Окончательная неокончательная версия. Мэйн расшит на отдельные файлы для классов. Дальше расшивать лень.

This commit is contained in:
2024-11-07 11:43:09 +05:00
parent ae50933cbb
commit e282072e93
7 changed files with 254 additions and 148 deletions

71
BoardClass/Board.cpp Normal file
View File

@ -0,0 +1,71 @@
#include "Board.h"
//
//
//Функция графического вывода поля.
//Пустая клетка (со значением "е") выводится координатами, а занятая - своим знаком.
void Board::BoardShow() {
for (unint countlines = 0; countlines < LINES; ++countlines) {
for (unint countcolumns = 0; countcolumns < COLUMNS; ++countcolumns) {
if (board[countlines][countcolumns]=="e") {
cout << countlines << countcolumns << " ";
}
else {
cout << board[countlines][countcolumns] << " ";
}
}
cout << endl;
}
}
//Функция очистки поля. Вызывается в новой итерации игрового цикла.
void Board::BoardClr() {
for (unint countlines = 0; countlines < LINES; ++countlines) {
for (unint countcolumns = 0; countcolumns < COLUMNS; ++countcolumns) {
board[countlines][countcolumns] = "e";
}
}
}
//Функция проверки победы Х.
void Board::XWon() {
if (drawcounter>=4) {
if ((board[0][0])=="'X'") {
if ((board[0][1])=="'X'" and (board[0][2])=="'X'") {Xwonflag=true;}
else if ((board[1][1])=="'X'" and (board[2][2])=="'X'") {Xwonflag=true;}
else if ((board[1][0])=="'X'" and (board[2][0])=="'X'") {Xwonflag=true;}
}
if (((board[1][0])=="'X'") and ((board[1][1])=="'X'") and ((board[1][2]))=="'X'") {Xwonflag=true;}
if (((board[0][1])=="'X'") and ((board[1][1])=="'X'") and ((board[2][1]))=="'X'") {Xwonflag=true;}
if (((board[0][2])=="'X'") and ((board[1][2])=="'X'") and ((board[2][2]))=="'X'") {Xwonflag=true;}
if ((board[2][0])=="'X'") {
if ((board[2][1])=="'X'" and (board[2][2])=="'X'") {Xwonflag=true;}
else if ((board[1][1])=="'X'" and (board[0][2])=="'X'") {Xwonflag=true;}
}
}
}
//Функция проверки победы О.
void Board::OWon() {
if (drawcounter>=4) {
if ((board[0][0])=="'O'") {
if ((board[0][1])=="'O'" and (board[0][2])=="'O'") {Owonflag=true;}
else if ((board[1][1])=="'O'" and (board[2][2])=="'O'") {Owonflag=true;}
else if ((board[1][0])=="'O'" and (board[2][0])=="'O'") {Owonflag=true;}
}
if (((board[1][0])=="'O'") and ((board[1][1])=="'O'") and ((board[1][2]))=="'O'") {Owonflag=true;}
if (((board[0][1])=="'O'") and ((board[1][1])=="'O'") and ((board[2][1]))=="'O'") {Owonflag=true;}
if (((board[0][2])=="'O'") and ((board[1][2])=="'O'") and ((board[2][2]))=="'O'") {Owonflag=true;}
if ((board[2][0])=="'O'") {
if ((board[2][1])=="'O'" and (board[2][2])=="'O'") {Owonflag=true;}
else if ((board[1][1])=="'O'" and (board[0][2])=="'O'") {Owonflag=true;}
}
}
}
//Функция, считающая заполненные клетки.
void Board::Draw() {
drawcounter=0;
for (int countlines = 0; countlines < LINES; ++countlines) {
for (int countcolumns = 0; countcolumns < COLUMNS; ++countcolumns) {
if (board[countlines][countcolumns]!="e") {
drawcounter++;
}
}
}
}