-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
85 lines (77 loc) · 1.41 KB
/
main.c
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
74
75
76
77
78
79
80
81
82
83
84
85
#include "addition.h"
void game()
{
//创建一个数组,用来制作棋盘。
char board[ROW][COL] = { ' ' };
//初始化棋盘,让棋盘上的位置没有棋子出现。
InitBoard(board, ROW, COL);
//打印棋盘
BoardPrint(board, ROW, COL);
//生成随机数
//开始游戏
while (1)
{
//让玩家下棋,*代表玩家下的棋。
PlayerDo(board,ROW,COL);
//打印下棋后的棋盘
BoardPrint(board, ROW, COL);
//判断输赢,返回*,代表玩家赢
//返回#代表电脑赢
//返回E代表平局
//返回C代表继续
char indication = Win(board, ROW, COL);
//让电脑下棋,#代表电脑下的棋。
ComputerDo(board,ROW,COL);
//打印下棋后的棋盘
BoardPrint(board, ROW, COL);
//判断输赢
indication = Win(board, ROW, COL);
if (indication == '*')
{
printf("玩家赢!\n");
break;
}
else if (indication == '#')
{
printf("电脑赢\n!");
break;
}
else if (indication == 'C')
;
else if (indication == 'E')
{
printf("平局");
break;
}
}
}
void menu()
{
int input = 0;
srand((unsigned int)time(NULL));
do
{
printf("###################\n");
printf("## 1.play 0.exit ##\n");
printf("###################\n");
printf("请选择!");
scanf("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("退出游戏!");
break;
default:
printf("输入错误!请重新输入!\n");
break;
}
} while (input);
}
int main()
{
menu();
return 0;
}