开门见山:
#include
#include
int main()
{
char a[9][9];
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (i < 3 || i>5)
{
if (j < 3 || j>5)
a[i][j] = ' ';
else
a[i][j] = 'O';
}
else
a[i][j] = 'O';
}
}
for (int i = 3; i < 6; i++)
{
for (int j = 3; j < 6; j++)
{
a[i][j] = '.';
}
}
printf("\n\n\n\n\n\n\n\n 规则是:X是你的坐标.选择一颗棋,AWSD控制它的走向,让他跳过其他棋,被跳过的棋会消失,最后场上只剩一颗棋就算赢\n 十秒后开始游戏");
Sleep(10000);
system("cls");
int t = 4, x = 4;
char b, c, e, f = '.';
int d = 0, j = 0;
a[t][x] = 'X';
while (1)
{
printf("\n\n");
for (int i = 0; i < 9; i++)
{
printf("\n\n ");
for (int j = 0; j < 9; j++)
printf("%c ", a[i][j]);
}
printf("\n\n\n\n");
if (j % 2 == 0)
{
printf(" 选择你要走的棋,摁下回车键继续.....(摁 x 取消)");
scanf_s(" %c", &b);
switch (b)
{
case 'a':if (a[t][x - 1] != ' ' && x > 0) { x--; e = a[t][x]; a[t][x + 1] = f; f = e; a[t][x] = 'X'; }
else { printf("\n 此 *** 作违规"); d = 1; } break;
case 's':if (a[t + 1][x] != ' ') { t++; e = a[t][x]; a[t - 1][x] = f; f = e; a[t][x] = 'X'; }
else { printf("\n 此 *** 作违规"); d = 1; } break;
case 'w':if (a[t - 1][x] != ' ') { t--; e = a[t][x]; a[t + 1][x] = f; f = e; a[t][x] = 'X'; }
else { printf("\n 此 *** 作违规"); d = 1; } break;
case 'd':if (a[t][x + 1] != ' ' && x < 9) { x++; e = a[t][x]; a[t][x - 1] = f; f = e; a[t][x] = 'X'; }
else { printf("\n 此 *** 作违规"); d = 1; } break;
default:x = x, t = t; break;
}
system("cls");
printf("\n\n");
for (int i = 0; i < 9; i++)
{
printf("\n\n ");
for (int j = 0; j < 9; j++)
printf("%c ", a[i][j]);
}
}
if (j % 2 == 1)
{
if (d == 0)
{
printf("\n 现在想让它跳向哪里:(摁 x 取消)");
scanf_s(" %c", &c);
switch (c)
{
case 'a':if (a[t][x - 2] == '.' && a[t][x - 1] == 'O')
{
if (e == 'O')
{
if (x >= 2)
{
a[t][x - 1] = '.'; a[t][x] = '.'; x -= 2; a[t][x] = 'O'; e = a[t][x]; f = a[t][x]; a[t][x] = 'X';
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
case 's':if (a[t + 2][x] == '.' && a[t + 1][x] == 'O')
{
if (e == 'O')
{
if (t <= 6)
{
a[t + 1][x] = '.'; a[t][x] = '.'; t += 2; a[t][x] = 'O'; e = a[t][x]; f = a[t][x]; a[t][x] = 'X';
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
case 'w':if (a[t - 2][x] == '.' && a[t - 1][x] == 'O')
{
if (e == 'O')
{
if (t >= 2)
{
a[t - 1][x] = '.'; a[t][x] = '.'; t -= 2; a[t][x] = 'O'; e = a[t][x]; f = a[t][x]; a[t][x] = 'X';
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
case 'd':if (a[t][x + 2] == '.' && a[t][x + 1] == 'O')
{
if (e == 'O')
{
if (x <= 6)
{
a[t][x + 1] = '.'; a[t][x] = '.'; x += 2; a[t][x] = 'O'; e = a[t][x]; f = a[t][x]; a[t][x] = 'X';
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
}
else printf("\n 此 *** 作违规"); break;
case 'x': break;
}
}
}
else
{
d = 0;
}
j++;
Sleep(500);
system("cls");
}
return 0;
}
好了,希望这段代码能对你有帮助~(都是我自己写的)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)