かめさん

かめさん。      ver 1.50


やっとそれらしくなってきましたー

--------------------------------------------------------------------------

現在実装済みの機能 (最終更新 08/1/9)

Fで前進 Rで右回転 Lで左回転
[特殊な字]で囲まれた部分を![特殊な字]で呼出可能
※ 現在 # $ % & が実装
[数字]+ForRorLor![特殊な字]で、[数字]分繰り返しで呼び出す
M[数字]で座標を保存、W[数字]でその座標にワープ
|(Shift+\)で入力途中でも中断して表示、その後入力可能 Xで入力終了(主に手動入力時)
英字の小文字入力を大文字に修正
Oでオプション呼出、Oで終了
<オプション>
D[数字] 一回あたりの進む量の変更
E 全部消す
C[数字] 色の変更 ※(黒=0 青=1 赤=4)
V[数字]  速度を追加 (0=通常 数字=速度)

※「1回あたりの進む量」/「速度」 が正の整数になるように指定してください

T[数字] マークのタイプを変更 ※0=× 1=>
S[数字] マークのサイズを変更
L[数字] 線の有無を変更 ※0=なし 1=直線


ステータスバーを表示

-------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

#define NMAX 100
#define XARE 600
#define YARE 600
#define BARX 100
#define BARY 100
#define WINS 20
#define YOHAKU 10
#define FH 3

void cord();
void ordscan();
void mode1();
void mode2();
void modeop();
int usech(char x);
void output(char x);
void put_mark(int x, int y);
void forward();
void l_turn();
void r_turn();
void allerase();
void coinput();
void armemo();
void warp();

void dinput();
void vinput();
void msinput();
void mtinput();
void ltinput();

void stbar();
void stout();

int cordgetch(int x);
void labelch(int sx, int sy, char st[]);

void makespace();
void makebox(int boxx1,int boxy1,int boxx2,int boxy2,int boxc);
void makelv();

char ord[NMAX], comm[NMAX], memory[NMAX][NMAX], armemory[NMAX][3];

int ordno, nread=0, savememo=0;
int memoryarea=0;

int dl=10, x, y, dx, dy, co=0, stco=0, marktype=0, marksize=2;
int linetype=1; /*線の有無*/
int v=0; /*速度の値*/

int closef=0; /*終了フラグ*/
int stbaron=1; /*statubarの有無*/
int checkon=1; /*チェック用表示*/

/*******************************************************************************************************/

int main(void){
openpl();
makespace();
x=0; y=0; dx=0; dx=1;
fcolor(co);
move(x,y);
while(closef==0){
cord();
if(checkon==1){printf("******************\n");}
ordscan();
labelch(-XARE/2+YOHAKU,-YARE/2-YOHAKU-WINS, comm);
}
return 0;
}

/*******************************************************************************************************/

void cord(){ /*例外文字(スペース、改行の排除)*/
int i=nread, q, f=0, k=nread;

while(f==0){
ord[i]=getchar();
if(ord[i]==EOF||ord[i]=='X'){ord[i]==EOF;f=1;closef=1;}
else if(ord[i]=='|'){ord[i]==EOF;f=1;}
else{i=i+1;}
}

ordno=i;
q=ordno;

for(i=nread;k<q;i++){
if(97<=ord[i]&&ord[i]<=122){ord[i]=ord[i]-32;}
if(usech(ord[i])==1){
if(checkon==1){printf("%c(%d)", ord[i], ord[i]);}
comm[k]=ord[i];
if(checkon==1){printf("comm[%d]=%c i=%d q=%d\n", k, comm[k], i, q);}
k=k+1;
}
else{
if(checkon==1){printf("ord[%d]=%d i=%d q=%d\n", i, ord[i], i, q);}
q=q-1;
}
}

ordno=k;
}

/*******************************************************************************************************/

void ordscan(){
int f=0, n=0, m;
while(f==0){
if('9'>=comm[nread]&&comm[nread]>='0'){
n=(comm[nread]-48)+10*n;
if(checkon==1){printf("n=%d\n", n);}
}
else if(comm[nread]=='F'||comm[nread]=='L'||comm[nread]=='R'){
if(n==0){n=1;}
for(m=0;m<n;m++){output(comm[nread]);}
n=0;
}
else if('&'>=comm[nread]&&comm[nread]>='#'){ mode1();}
else if(comm[nread]=='!'){nread=nread+1;
if(n==0){n=1;}
for(m=0;m<n;m++){mode2();}n=0;}
else if(comm[nread]=='O'){modeop();}
else if(comm[nread]=='M'){armemo();}
else if(comm[nread]=='W'){warp();}
nread=nread+1;
if(nread>=ordno){f=1;}
}

}

/*******************************************************************************************************/

void mode1(){
int nmemo=0, l, i=0, f=0;

for(l=0;l<=savememo;l++){
if(memory[l][0]==comm[nread]){
nmemo=l;l=savememo+1;
if(checkon==1){printf("save nmemo=No %d\n", nmemo);}
}
else if(l==savememo){
nmemo=savememo;
if(checkon==1){printf("save nmemo=No %d\n", nmemo);}
}
}

while(f==0){
memory[nmemo][i]=comm[nread];
if(checkon==1){printf("memory[%d][%d]=%c(%d)\n", nmemo, i,  comm[nread], comm[nread]);}
i=i+1; nread=nread+1;
if(comm[nread]==memory[nmemo][0]){
memory[nmemo][i]=comm[nread];
if(checkon==1){printf("memory[%d][%d]=%c(%d)\n", nmemo, i,  comm[nread], comm[nread]);}
f=1; savememo=savememo+1;
}
}

}

/*******************************************************************************************************/

void mode2(){
int nload, l, i=1, f=0, n=0, m;

for(l=0;l<=savememo;l++){
if(memory[l][0]==comm[nread]){
nload=l;l=savememo+1;
if(checkon==1){printf("load nload=No %d\n", nload);}
}
else if(l==savememo){
if(checkon==1){printf("not save [%c]\n", comm[nread]);}
f=1;
}
}

while(f==0){
if(checkon==1){printf("memory[%d][%d]=%c(%d) ", nload, i, memory[nload][i], memory[nload][i]);}
if(57>=memory[nload][i]&&memory[nload][i]>=48){
n=(memory[nload][i]-48)+10*n;
if(checkon==1){printf("n=%d\n", n);}
}
else if(memory[nload][i]=='R'||memory[nload][i]=='F'||memory[nload][i]=='L'){
if(n==0){n=1;}
for(m=0;m<n;m++){output(memory[nload][i]);}
n=0;
}
else{}
i=i+1;
if(memory[nload][i]==memory[nload][0]){f=1;}
}

}

/*******************************************************************************************************/

int usech(char x){
if(x==EOF){return 1;}
if('0'<=x&&x<='9'){return 1;}
if(x=='F'||x=='L'||x=='R'){return 1;}
if('#'<=x&&x<='&'){return 1;} /*# $ % &*/
if(x=='!'){return 1;}
if(x=='O'){return 1;}
if(x=='D'){return 1;}
if(x=='E'){return 1;}
if(x=='M'){return 1;}
if(x=='C'){return 1;}
if(x=='W'){return 1;}
if(x=='V'){return 1;}
if(x=='T'){return 1;}        
if(x=='S'){return 1;}
if(x=='L'){return 1;}
if(x=='X'){return 1;}
return 0;    
}

/*******************************************************************************************************/

void modeop(){
int f=0;
if(checkon==1){printf("\nmode option\n");}  
nread=nread+1;
while(f==0){
if(comm[nread]=='D'){dinput();} /*一回あたりの進む量変更(dl)*/
if(comm[nread]=='E'){allerase();} /*全消し*/
if(comm[nread]=='C'){coinput();} /*カラー変更*/
if(comm[nread]=='V'){vinput();} /*速度変更*/
if(comm[nread]=='T'){mtinput();} /*マークタイプ変更*/
if(comm[nread]=='S'){msinput();} /*マークサイズ変更*/
if(comm[nread]=='V'){vinput();} /*速度変更*/
if(comm[nread]=='L'){ltinput();} /*線の種類を変更*/
nread=nread+1;
if(comm[nread]=='O'){f=1;}
}

}

/*******************************************************************************************************/

void output(char x){
if(checkon==1){printf(">%c\n", x);}
if(x=='F'){forward();}
if(x=='R'){r_turn();}
if(x=='L'){l_turn();}
}

/*******************************************************************************************************/

void forward(){
makelv();
put_mark(x,y);
}

/*******************************************************************************************************/

void r_turn(){int tmp; tmp=dx; dx=dy; dy=-tmp;}

/*******************************************************************************************************/

void l_turn(){int tmp; tmp=dx; dx=-dy; dy=tmp;}

/*******************************************************************************************************/

void put_mark(int x, int y){
int s=marksize;
fcolor(co);
if(marktype==0){
move(x-1*s,y-1*s); cont(x+1*s,y+1*s);
move(x+1*s,y-1*s); cont(x-1*s,y+1*s);
}
if(marktype==1){
if(dx==1){move(x-1*s,y-1*s); cont(x,y);move(x-1*s,y+1*s); cont(x,y);}
else if(dx==-1){move(x+1*s,y-1*s); cont(x,y);move(x+1*s,y+1*s); cont(x,y);}
else if(dy==1){move(x-1*s,y-1*s); cont(x,y);move(x+1*s,y-1*s); cont(x,y);}
else{move(x-1*s,y+1*s); cont(x,y);move(x+1*s,y+1*s); cont(x,y);}
}
move(x,y);
fcolor(co);
}

/*******************************************************************************************************/

void allerase(){
int i;
fcolor(7); /*white*/
for(i=0;i<600;i++){
move(-XARE/2+i, -YARE/2); cont(-XARE/2+i, YARE/2);
}
fcolor(co);
move(x,y);
put_mark(x,y);
}

/*******************************************************************************************************/

void coinput(){
nread=nread+1;
co=comm[nread];
fcolor(co);
}    

/*******************************************************************************************************/

void armemo(){
int  narmemo=0, l, m;
nread=nread+1;
if(checkon==1){printf("armemo\n");}

for(l=0;l<=memoryarea;l++){
if(armemory[l][0]==comm[nread]){
narmemo=l;l=memoryarea+1;
if(checkon==1){printf("save narmemo=No M%d\n", narmemo);}
}
else if(l==memoryarea){
narmemo=l;
armemory[narmemo][0]=comm[nread];
if(checkon==1){printf("save narmemo=No M%d\n", narmemo);}
}
}

armemory[narmemo][1]=x;    
if(checkon==1){printf("armemory[%d] X=%d\n", narmemo, armemory[narmemo][1]);}
armemory[narmemo][2]=y;    
if(checkon==1){printf("armemory[%d] Y=%d\n", narmemo, armemory[narmemo][2]);}
memoryarea=memoryarea+1;
}

/*******************************************************************************************************/

void warp(){
int narload, l, f=0;
if(checkon==1){printf("warp\n");}
nread=nread+1;

for(l=0;l<=memoryarea;l++){
if(armemory[l][0]==comm[nread]){narload=l;l=memoryarea+1;
if(checkon==1){printf("load narload=No M%d\n", narload);}
}
else if(l==memoryarea){
if(checkon==1){printf("not save M[%c]\n", comm[nread]);}
f=1;
}
}

if(f==0){
if(checkon==1){printf("armemory[%d] X=%d\n", narload, armemory[narload][1]);}
x=armemory[narload][1];
if(checkon==1){printf("armemory[%d] Y=%d\n", narload, armemory[narload][2]);}
y=armemory[narload][2];
}

}

/*******************************************************************************************************/

void makespace(){
if(stbaron==0){space(-XARE/2,-YARE/2,XARE/2,YARE/2);}
else if(stbaron==1){space(-XARE/2,-YARE/2-BARY,XARE/2+BARX,YARE/2);
makebox(XARE/2,-YARE/2,XARE/2+BARX,YARE/2,3);
makebox(-XARE/2,-YARE-BARY,XARE/2+BARX,-YARE/2,3);
}

}

/*******************************************************************************************************/

void makebox(int boxx1,int boxy1,int boxx2,int boxy2,int boxc){
int i;
fcolor(boxc);
for(i=0;i<=boxx2-boxx1;i++){
move(boxx1+i, boxy1);cont(boxx1+i, boxy2);
}
fcolor(co);
move(x,y);

}

/*******************************************************************************************************/

void makelv(){
int sec, di;
stbar();
stout();
if(v==0){
x=x+dx*dl;
y=y+dy*dl;
if(linetype==1){cont(x,y);}
else if(linetype==0){move(x,y);}
}
else if(v>0){
sec=dl/v;

for(di=1;di<=sec;di++){
sleep(1);
stbar();stout();
x=x+dx*v;y=y+dy*v;
if(linetype==1){cont(x,y);}
else if(linetype==0){move(x,y);}
stout();
}

}
fcolor(co);

}

/*******************************************************************************************************/

void stbar(){
makebox(-XARE/2+YOHAKU,-YARE/2-YOHAKU-WINS,XARE/2,-YARE/2-YOHAKU,7); /*下部表示用*/

makebox(XARE/2+YOHAKU,YARE/2-YOHAKU-WINS,XARE/2+BARX-YOHAKU,YARE/2-YOHAKU,7); /*x用のbox*/
move(XARE/2+YOHAKU, YARE/2-YOHAKU-WINS+FH);
fcolor(stco);label("x:");

makebox(XARE/2+YOHAKU,YARE/2-YOHAKU*2-WINS*2,XARE/2+BARX-YOHAKU,YARE/2-YOHAKU*2-WINS,7); /*y用のbox*/
move(XARE/2+YOHAKU, YARE/2-YOHAKU*2-WINS*2+FH);
fcolor(stco);label("y:");

makebox(XARE/2+YOHAKU,YARE/2-YOHAKU*3-WINS*3,XARE/2+BARX-YOHAKU,YARE/2-YOHAKU*3-WINS*2,7); /*v用のbox*/
move(XARE/2+YOHAKU, YARE/2-YOHAKU*3-WINS*3+FH);
fcolor(stco);label("v:");

makebox(XARE/2+YOHAKU,YARE/2-YOHAKU*4-WINS*4,XARE/2+BARX-YOHAKU,YARE/2-YOHAKU*4-WINS*3,7); /*dl用のbox*/
move(XARE/2+YOHAKU, YARE/2-YOHAKU*4-WINS*4+FH);
fcolor(stco);label("d:");

move(XARE/2+YOHAKU, YARE/2-YOHAKU*5-WINS*5+FH);
fcolor(stco);label("Mark");
move(XARE/2+YOHAKU, YARE/2-YOHAKU*6-WINS*6+FH);
fcolor(stco);label("Type");
move(XARE/2+(BARX-YOHAKU)/2+YOHAKU, YARE/2-YOHAKU*6-WINS*6+FH);
fcolor(stco);label("Size");

makebox(XARE/2+YOHAKU,YARE/2-YOHAKU*7-WINS*7,XARE/2+(BARX-YOHAKU)/2,YARE/2-YOHAKU*7-WINS*6,7);
/*mt用のbox*/

makebox(XARE/2+(BARX-YOHAKU)/2+YOHAKU,YARE/2-YOHAKU*7-WINS*7,XARE/2+BARX-YOHAKU,YARE/2-YOHAKU*7-WINS*6,7);
/*ms用のbox*/

move(x,y);

}

/*******************************************************************************************************/

void labelch(int sx, int sy, char st[]){
int i, k, nfx=11, nfy=0;
char getch[NMAX];
for(i=0;i<NMAX;i++){getch[i]=8;}
fcolor(stco);

for(i=0;i<NMAX;i++){
getch[i]=st[i];
if(usech(st[i])==0){i=NMAX+1;}
}
move(sx, sy=sy+FH);

for(k=0;k<NMAX;k++){
if(getch[k]=='0'){label("0");}
else if(getch[k]=='1'){label("1");}
else if(getch[k]=='2'){label("2");}
else if(getch[k]=='3'){label("3");}
else if(getch[k]=='4'){label("4");}
else if(getch[k]=='5'){label("5");}
else if(getch[k]=='6'){label("6");}
else if(getch[k]=='7'){label("7");}
else if(getch[k]=='8'){label("8");}
else if(getch[k]=='9'){label("9");}
else if(getch[k]=='F'){label("F");}
else if(getch[k]=='R'){label("R");}
else if(getch[k]=='L'){label("L");}
else if(getch[k]=='#'){label("#");}
else if(getch[k]=='$'){label("$");}
else if(getch[k]=='%'){label("%");}
else if(getch[k]=='&'){label("&");}
else if(getch[k]=='!'){label("!");}
else if(getch[k]=='O'){label("O");}
else if(getch[k]=='D'){label("D");}
else if(getch[k]=='E'){label("E");}
else if(getch[k]=='M'){label("M");}
else if(getch[k]=='C'){label("C");}
else if(getch[k]=='W'){label("W");}
else if(getch[k]=='V'){label("V");}
else if(getch[k]=='T'){label("T");}
else if(getch[k]=='S'){label("S");}
else if(getch[k]=='L'){label("L");}
else {k=NMAX;}
sx=sx+nfx; sy=sy+nfy;
move(sx, sy);
}

fcolor(co);

}

/*******************************************************************************************************/

void stout(){

int i, pm, px, py, pv, pdl, pmt, pms;
char pri[3];
px=x; py=y; pv=v; pdl=dl; pmt=marktype; pms=marksize;

for(i=0;i<3;i++){pri[i]=EOF;}

if(px>=0){pm=0;}else{pm=1;px=-px;}
pri[0]=px/100;
pri[1]=(px-pri[0]*100)/10;
pri[2]=(px-pri[0]*100-pri[1]*10);
for(i=0;i<3;i++){pri[i]=cordgetch(pri[i]);
}
fcolor(stco);
if(pm==1){move(XARE/2+YOHAKU+16,YARE/2-YOHAKU-WINS+FH);label("-");}
labelch(XARE/2+YOHAKU+25,YARE/2-YOHAKU-WINS,pri);

for(i=0;i<3;i++){pri[i]=8;} /*初期化*/

if(py>=0){pm=0;}else{pm=1;py=-py;}
pri[0]=py/100;
pri[1]=(py-pri[0]*100)/10;
pri[2]=(py-pri[0]*100-pri[1]*10);
for(i=0;i<3;i++){pri[i]=cordgetch(pri[i]);
}
fcolor(stco);
if(pm==1){move(XARE/2+YOHAKU+16,YARE/2-YOHAKU*2-WINS*2+FH);label("-");}
labelch(XARE/2+YOHAKU+25,YARE/2-YOHAKU*2-WINS*2,pri);

for(i=0;i<3;i++){pri[i]=8;} /*初期化*/

if(pv>=0){pm=0;}else{pm=1;pv=-pv;}
pri[0]=pv/100;
pri[1]=(pv-pri[0]*100)/10;
pri[2]=(pv-pri[0]*100-pri[1]*10);
for(i=0;i<3;i++){pri[i]=cordgetch(pri[i]);
}
fcolor(stco);
if(pm==1){move(XARE/2+YOHAKU+16,YARE/2-YOHAKU*3-WINS*3+FH);label("-");}
labelch(XARE/2+YOHAKU+25,YARE/2-YOHAKU*3-WINS*3,pri);

for(i=0;i<3;i++){pri[i]=8;} /*初期化*/

if(pdl>=0){pm=0;}else{pm=1;pdl=-pdl;}
pri[0]=pdl/100;
pri[1]=(pdl-pri[0]*100)/10;
pri[2]=(pdl-pri[0]*100-pri[1]*10);
for(i=0;i<3;i++){pri[i]=cordgetch(pri[i]);
}
fcolor(stco);
if(pm==1){move(XARE/2+YOHAKU+16,YARE/2-YOHAKU*4-WINS*4+FH);label("-");}
labelch(XARE/2+YOHAKU+25,YARE/2-YOHAKU*4-WINS*4,pri);

for(i=0;i<3;i++){pri[i]=8;} /*初期化*/

if(pmt>=0){pm=0;}else{pm=1;pmt=-pmt;}
pri[0]=pmt/10;
pri[1]=(pmt-pri[0]*10);
for(i=0;i<2;i++){pri[i]=cordgetch(pri[i]);
}
fcolor(stco);
if(pm==1){move(XARE/2+YOHAKU+16,YARE/2-YOHAKU*7-WINS*7+FH);label("-");}
labelch(XARE/2+YOHAKU+13,YARE/2-YOHAKU*7-WINS*7,pri);

for(i=0;i<3;i++){pri[i]=8;} /*初期化*/

if(pms>=0){pm=0;}else{pm=1;pms=-pms;}
pri[0]=pms/100;
pri[1]=(pms-pri[0]*100)/10;
pri[2]=(pms-pri[0]*100-pri[1]*10);
for(i=0;i<3;i++){pri[i]=cordgetch(pri[i]);
}
fcolor(stco);
if(pm==1){move(XARE/2+YOHAKU+16,YARE/2-YOHAKU*7-WINS*7+FH);label("-");}
labelch(XARE/2+(BARX-YOHAKU)/2+YOHAKU+3,YARE/2-YOHAKU*7-WINS*7,pri);

for(i=0;i<3;i++){pri[i]=8;} /*初期化*/

move(x,y);
}

/*******************************************************************************************************/

int cordgetch(int x){
if(x==0){return '0';}
if(x==1){return '1';}
if(x==2){return '2';}
if(x==3){return '3';}
if(x==4){return '4';}
if(x==5){return '5';}
if(x==6){return '6';}
if(x==7){return '7';}
if(x==8){return '8';}
if(x==9){return '9';}
return 0;    
}

/*******************************************************************************************************/

void dinput(){
int n=0, f2=0;
nread=nread+1; /*Dで一回あたりの進む量変更(dl)*/
while(f2==0){
if(57>=comm[nread]&&comm[nread]>=48){
n=(comm[nread]-48)+10*n;
nread=nread+1;
}
else{f2=1;}
}
nread=nread-1;
dl=n;

}

/*******************************************************************************************************/

void vinput(){
int n=0, f2=0;
nread=nread+1; /*vの変更(v)*/
while(f2==0){    
if(57>=comm[nread]&&comm[nread]>=48){
n=(comm[nread]-48)+10*n;
nread=nread+1;
}
else{f2=1;}
}
nread=nread-1;
v=n;
}

/*******************************************************************************************************/

void mtinput(){
int n=0, f2=0;
nread=nread+1; /*marktypeの変更(marktype)*/
while(f2==0){
if(57>=comm[nread]&&comm[nread]>=48){
n=(comm[nread]-48)+10*n;
nread=nread+1;
}
else{f2=1;}
}
nread=nread-1;
marktype=n;

}

/*******************************************************************************************************/

void msinput(){
int n=0, f2=0;
nread=nread+1; /*marksizeの変更(marksize)*/
while(f2==0){    
if(57>=comm[nread]&&comm[nread]>=48){
n=(comm[nread]-48)+10*n;
nread=nread+1;
}
else{f2=1;}
}
nread=nread-1;
marksize=n;

}

/*******************************************************************************************************/

void ltinput(){
int n=0, f2=0;
nread=nread+1; /*marksizeの変更(marksize)*/
while(f2==0){    
if(57>=comm[nread]&&comm[nread]>=48){
n=(comm[nread]-48)+10*n;
nread=nread+1;
}
else{f2=1;}
}
nread=nread-1;
linetype=n;

}

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2008年01月09日 16:29