-
Notifications
You must be signed in to change notification settings - Fork 0
/
MBGame.c
85 lines (82 loc) · 2.79 KB
/
MBGame.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 <stdio.h>
int main()
{
int array[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
int i, j, a, b, end = 0, m, X, Y, r = 0, t = 0;
while (1)
{
printf("→行入力:");
scanf("%d", &a);
printf("↓列入力:");
scanf("%d", &b);
if (array[a-1][b-1] == 0 && t == 0)
{
array[a-1][b-1] = 1;
t = 1;
r++;
}
else if((array[a-1][b-1] == 1 && t == 1)){
printf("既に〇が入ってます\nXの方は、もう一度入力してください\n\n");
printf("→行入力1:");
scanf("%d", &a);
printf("↓列入力:");
scanf("%d", &b);
array[a-1][b-1] = 2;
t = 0;
}
if (array[a-1][b-1] == 0 && t == 1)
{
array[a-1][b-1] = 2;
t = 0;
r++;
}
else if((array[a-1][b-1] == 2 && t == 0)){
printf("既にXが入ってます\n〇の方は、もう一度入力してください\n\n");
printf("→行入力2:");
scanf("%d", &a);
printf("↓列入力:");
scanf("%d", &b);
array[a-1][b-1] = 1;
t = 1;
}
if (r < 10)
{
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
if (array[i][j] == 0)
printf(" ");
if (array[i][j] == 1){
printf("O");
if (array[0][j] == 1 && array[1][j] == 1 && array[2][j] == 1)
end = 1;
if (array[i][0] == 1 && array[i][1] == 1 && array[i][2] == 1)
end = 1;
if (array[0][0] == 1 && array[1][1] == 1 && array[2][2] == 1)
end = 1;
if (array[0][2] == 1 && array[1][1] == 1 && array[2][0] == 1)
end = 1;
}
if (array[i][j] == 2){
printf("×");
if (array[0][j] == 2 && array[1][j] == 2 && array[2][j] == 2)
end = 1;
if (array[i][0] == 2 && array[i][1] == 2 && array[i][2] == 2)
end = 1;
if (array[0][0] == 2 && array[1][1] == 2 && array[2][2] == 2)
end = 1;
if (array[0][2] == 2 && array[1][1] == 2 && array[2][0] == 2)
end = 1;
}
}
printf("\n");
}
}
if (r == 9 || end == 1){
printf("\nゲーム終了!!\n");
break;
}
}
return 0;
}