#include <string.h> #include <stdio.h> #include <stdlib.h> #include <windows.h> int main() { char a[50][50]={" ###", " #*#", "#####o######", "#* os o *#", "#######o####", " # #", " #*#", " ###", } int o,i,i1,x1,x2,x3,x4,x5,x6,x7; x1=1;x2=5;x3=3;x4=1;x5=10;x6=6;x7=7;i=1;i1=1; char m; for(i=0;i<=7;i++) pust(a[i]); while(a[x1][x5]!='o'||a[x3][x4]!='o'||a[x3][x5]!='o'||a[x6][x7]!='o') { m=getch(); if(m=='s') { if(a[i+1][i1]!='#') { a[i][i1]=' '; i++; a[i][i1]='s'; if(a[i][i1]=='o'||a[i+1][i1]!='#') { a[i+1][i1]='o'; } if(a[i][i1]=='o'||a[i+1][i1]=='#') { a[i-1][i1]='s'; a[i][i1]='o'; } pust(a[i]); } } } system("pause"); return 0; } |
本帖最后由 Living Things. 于 2018-3-20 16:46 编辑 a580230a 发表于 2018-1-30 12:55 #include <stdio.h> #include <stdlib.h> #include <windows.h> int x=3,y=5; const int fx[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; char a[50][50]={" ### ", " #*# ", "#####o######", "#* os o *#", "#######o####", " # # ", " #*# ", " ### "}; void move(int v) { switch(a[x+fx[v][0]][y+fx[v][1]]) { case 'o': if(a[x+fx[v][0]*2][y+fx[v][1]*2]!='#') { a[x][y]=' '; a[x+=fx[v][0]][y+=fx[v][1]]='s'; a[x+fx[v][0]][y+fx[v][1]]='o'; } break; case '#': break; case ' ': a[x][y]=' '; a[x+=fx[v][0]][y+=fx[v][1]]='s'; break; default: puts("Error"); getch(); exit(0); } } int main() { int i; while(a[1][5]=='*' || a[3][1]=='*' || a[3][9]=='*' || a[6][7]=='*') { for(i=0;i<8;i++) puts(a); switch(getch()) { case 'W':case 'w':case '\110': move(0); break; case 'S':case 's':case '\120': move(1); break; case 'A':case 'a':case '\113': move(2); break; case 'D':case 'd':case '\115': move(3); break; } system("cls"); } for(i=0;i<8;i++) puts(a); puts("你赢了!"); system("pause > nul"); return 0; } |