小游戏——————三子棋(保姆级教学)
int main()
{
int input = 0;
do
{
menu();
printf("请选择:>");
scanf("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("退出成功\n");
break;
default:
printf("选择错误,重新选择:>\n");
break;
}
} while (input);
return 0;
}
void menu()
{
printf("*************************\n");
printf("******** 1.play *******\n");
printf("******** 0.exit *******\n");
printf("*************************\n");
}
" width="16" class="ne-image-loading-icon">
void game()
{
char board[row][col] = { 0 };
initboard(board, row, col);
displayboard(board, row, col);
char ret = 0;
while (1)
{
playermove(board, row, col);
displayboard(board, row, col);
ret = iswin(board, row, col);
if (ret != 'c')
break;
//电脑下
computermove(board, row, col);
displayboard(board, row, col);
ret = iswin(board, row, col);
if (ret != 'c')
break;
}
if (ret == '*')
printf("玩家赢\n");
else if (ret == '#')
printf("电脑赢\n");
else
printf("和局\n");
}
" width="16" class="ne-image-loading-icon">
" width="16" class="ne-image-loading-icon">
" width="16" class="ne-image-loading-icon">
请后发表内容
1个评论