- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
class MainClass
{
public static char[,] titato = new char[3, 3] { { ' ', ' ', ' ' }, { ' ', ' ', ' ' }, { ' ', ' ', ' ' } };
static bool CheckWin(char s)
{
if ((titato[0, 0] == titato[1, 1] & titato[1, 1] == titato[2, 2] & titato[0, 0] != ' ') ||
(titato[0, 1] == titato[0, 2] & titato[0, 2] == titato[0, 0] & titato[0, 1] != ' ') ||
(titato[1, 1] == titato[1, 2] & titato[1, 2] == titato[1, 0] & titato[1, 1] != ' ') ||
(titato[2, 1] == titato[2, 2] & titato[2, 2] == titato[2, 0] & titato[2, 1] != ' ') ||
(titato[1, 0] == titato[2, 0] & titato[2, 0] == titato[0, 0] & titato[1, 0] != ' ') ||
(titato[1, 1] == titato[2, 1] & titato[2, 1] == titato[0, 1] & titato[1, 1] != ' ') ||
(titato[1, 2] == titato[2, 2] & titato[2, 2] == titato[0, 2] & titato[1, 2] != ' ') ||
(titato[2, 0] == titato[1, 1] & titato[1, 1] == titato[0, 2] & titato[2, 0] != ' '))
{
return true;
}
return false;
}
public static void PrintTicTacToe(char s)
{
Console.Clear();
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.White;
for (int i = 0; i < titato.GetLength(0); i++) {
Console.Write(" {0} ", i);
}
Console.WriteLine();
for (int i = 0; i < titato.GetLength(0); i++) {
Console.BackgroundColor = ConsoleColor.White;
Console.Write("{0}", i);
for (int j = 0; j < titato.GetLength(1); j++) {
Console.BackgroundColor = ConsoleColor.Black;
if (titato[i, j] == 'x') {
Console.ForegroundColor = ConsoleColor.Red;
}
else if (titato[i, j] == 'o') {
Console.ForegroundColor = ConsoleColor.Green;
}
else {
Console.ForegroundColor = ConsoleColor.Black;
}
Console.Write(" {0} ", titato[i, j]);
}
Console.WriteLine();
}
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
if (CheckWin(s)) {
Console.WriteLine(s + " win!!!");
}
}
public static void PushXO(int i, int j, char s)
{
titato[i, j] = s;
}
public static void Main(string[] args)
{
bool symbolX = true;
char s = 'x';
int i = 0, j = 0;
do {
Console.WriteLine("TIC TAC TOE!");
PrintTicTacToe(s);
if (symbolX == true) {
Console.WriteLine("Ходит Х");
Console.WriteLine("Введите номер столбца а затем введите номер строки:");
s = 'x';
symbolX = false;
}
else {
Console.WriteLine("Ходит О");
Console.WriteLine("Введите номер столбца а затем введите номер строки:");
s = 'o';
symbolX = true;
}
i = int.Parse(Console.ReadLine());
j = int.Parse(Console.ReadLine());
PushXO(j, i, s);
// Console.ReadLine();
PrintTicTacToe(s);
} while (true);
}