char s[1000]
FILE *fin = fopen ("palsquare.txt","r")
FILE *fout = fopen ("palsquarew.txt","w")
while(fgets(s,maxn,fin))
{ fprintf(fout,"%s",s)
}
/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo…………)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运*//*贪吃蛇*/#include#include#include#includeinthead=3,tail=0intmain(){inti,j,k=0intzuobiao[2][80]longstartintdirection=77intgamespeedinttimeoverintchange(charqipan[20][80],intzuobiao[2][80],chardirection)zuobiao[0][tail]=1zuobiao[1][tail]=1zuobiao[0][1]=1zuobiao[1][1]=2zuobiao[0][2]=1zuobiao[1][2]=3zuobiao[0][head]=1zuobiao[1][head]=4/*处理棋盘*/charqipan[20][80]//定义棋盘for(i=0i<20i++)for(j=0j<80j++)qipan[i][j]=''//初始化棋盘for(i=0i<80i++)qipan[0][i]='_'for(i=0i<20i++)qipan[i][0]='|'for(i=0i<20i++)qipan[i][79]='|'for(i=0i<80i++)qipan[19][i]='_'qipan[1][1]=qipan[1][2]=qipan[1][3]='*'//初始化蛇的位置qipan[1][4]='#'printf("ThisisagameofaSNAKE.\nGOODLUCKTOYOU!\n")printf("Inputyourgamespeed,please.(e.g.300)\n")scanf("%d",&gamespeed)while(direction!='q'){system("cls")for(i=0i<20i++)//打印出棋盘for(j=0j<80j++)printf("%c",qipan[i][j])timeover=1start=clock()while(!kbhit()&&(timeover=clock()-start<=gamespeed))if(timeover){getch()direction=getch()}elsedirection=directionif(!(direction==72||direction==80||direction==75||direction==77)){return0system("cls")printf("GAMEOVER!\n")}if(!change(qipan,zuobiao,direction)){direction='q'system("cls")printf("GAMEOVER!\n")}}return0}intchange(charqipan[20][80],intzuobiao[2][80],chardirection){intx,yif(direction==72)x=zuobiao[0][head]-1y=zuobiao[1][head]if(direction==80)x=zuobiao[0][head]+1y=zuobiao[1][head]if(direction==75)x=zuobiao[0][head]y=zuobiao[0][head]-1if(direction==77)x=zuobiao[0][head]y=zuobiao[1][head]+1if(x==0||x==18||y==78||y==0)return0if(qipan[x][y]!='')return0qipan[zuobiao[0][tail]][zuobiao[1][tail]]=''tail=(tail+1)%80qipan[zuobiao[0][head]][zuobiao[1][head]]='*'head=(head+1)%80zuobiao[0][head]=xzuobiao[1][head]=yqipan[zuobiao[0][head]][zuobiao[1][head]]='#'return1}欢迎分享,转载请注明来源:内存溢出
评论列表(0条)