-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c.txt
73 lines (68 loc) · 1.33 KB
/
test.c.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h"
void menu()
{
printf("**************************\n");
printf("****** 1. play *****\n");
printf("****** 0. exit *****\n");
printf("**************************\n");
}
void game()
{
char ret = 0;
//数据的存储是二位数组
char board[ROW][COL];
//初始化棋盘-初始化为空格
InitBoard(board, ROW, COL);
DisplayBoard(board, ROW, COL);
while (1)
{
//玩家下棋
PlayerMove(board, ROW, COL);
ret = CheckWin(board, ROW, COL);
if (ret != 'C')
{
break;
}
DisplayBoard(board, ROW, COL);
//电脑下棋
ComputerMove(board, ROW, COL);//随机下棋的
ret = CheckWin(board, ROW, COL);
if (ret != 'C')
{
break;
}
DisplayBoard(board, ROW, COL);
}
if (ret == '*')
printf("玩家赢了\n");
else if (ret == '#')
printf("电脑赢了\n");
else if (ret == 'Q')
printf("平局\n");
DisplayBoard(board, ROW, COL);
}
int main()
{
srand((unsigned int)time(NULL));
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;
}