SEsource/三子棋/test.c

75 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//test.c 测试游戏的逻辑
//game.h关于游戏相关的函数声明符号声明头文件的包含
//game.c 游戏相关函数的实现
#include "game.h"
void menu(){
printf("*************************\n");
printf("**** 1.play **********\n");
printf("**** 0.exit **********\n");
printf("*************************\n");
}
void game(){
//存储数据---二维数组
char board[ROW][COL];
//初始化棋盘 -- 初始化空格
initBoard(board,ROW,COL);
//打印棋盘 本质是打印数组内容
displayBoard(board,ROW,COL);
char ret = 0;//接收游戏状态
while(1){
//玩家走
playMove(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");
}
displayBoard(board,ROW,COL);
}
int main(){
int input = 0;
srand((unsigned int)time(NULL));
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;
}