0 / 0 / 0
Регистрация: 24.01.2017
Сообщений: 14
|
|
1
|
Напишите пожалуйста игровое меню по такому типу 1.Начало игры
26.05.2017, 20:51. Показов 471. Ответов 0
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
| #include <iostream>
#include <conio.h>
#include <random>
#include <time.h>
#include <Windows.h>
using namespace std;
char name1[30];
char name2[30];
char table[3][3];
bool step;
void instruction()
{
cout«"Крестики-Нолики\n";
int l = 0;
for(int i(0); i < 3; i++)
{
for(int j(0); j < 3; j++)
{
table[i][j] = char(49+l);
l++;
}
}
cout«"Для начала игры нажмите любую клавишу:";
_getch();
}
bool input()
{
for(int i(0); i < 3; i++)
{
for(int j(0); j < 3; j++)
{
cout « "|" « table[i][j] « ' ';
}
cout«"|";
cout« endl;
}
cout« endl;
if(step)
cout«"Ходит 1 игрок\n";
else cout«"Ходит 2 игрок\n";
int n;
cin » n;
if(n < 1 || n > 9)
return false;
int i,j;
if(n%3 == 0)
{
i = n/3-1;
j = 2;
}
else
{
j = n%3-1;
i = n/3;
}
if(table[i][j] == 'O' || table[i][j] == 'X')
return false;
if(step)
{
table[i][j] = 'X';
step = false;
}
else {table[i][j] = 'O'; step = true;}
return true;
}
bool win()
{
for(int i(0); i < 3; i++)
if((table[i][0] == table[i][1]) && (table[i][0] == table[i][2]))
return true;
else
if((table[0][i] == table[1][i]) && (table[0][i] == table[2][i]))
return true;
else
if((table[0][0] == table[1][1]) && (table[0][0] == table[2][2]) || (table[0][2] == table[1][1] && table[0][2] == table[2][0] == table[1][1] && table[0][0] == table[2][2]) || (table[0][2] == table[1][1] && table[0][2] == table[2][0]))
return true;
else
return false;
}
int main()
{
setlocale(LC_ALL , "Russian");
instruction();
system("cls");
cout«"Введите имя 1 игрока: \n";
cin.getline(name1,30);
cout«"Введите имя 2 игрока: \n";
cin.getline(name2,30);
srand(time(NULL));
if(rand() & 1)
step = true;
else step = false;
while(!win())
{
system("cls");
if( !input() )
{
cout«" Вы ввели неверные данные,пожалуйста повторите!\n";
_getch();
}
}
system ("cls");
if (step)
cout«"Победил 2 игрок\n";
else cout«"Победил 1 игрок\n";
_getch();
} |
|
0
|