1713 lines
69 KiB
C++
1713 lines
69 KiB
C++
#include <iostream>
|
|
#include <conio.h>
|
|
#include <windows.h>
|
|
#include <random>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
|
|
using namespace std;
|
|
|
|
string board[20][20], playerName1, playerName2;
|
|
char turn = 'b';
|
|
int n = 8;
|
|
string temp = "";
|
|
|
|
struct player
|
|
{
|
|
int score;
|
|
string name;
|
|
};
|
|
struct gameStats
|
|
{
|
|
int score1;
|
|
string name1;
|
|
int score2;
|
|
string name2;
|
|
string time;
|
|
};
|
|
|
|
int menu(); // opens the menu and outputs the selected number.
|
|
int gameModeSelector(); // opens the single or multiplayer selection menu and ouputs the selected number.
|
|
void game(); // starts the game but it has the game mode selector inside.
|
|
void boardClear(); // clears the board and sets to defualt for a new game.
|
|
void gameScreenUpdate(); // updates the game board based on the new board array and uses the global turn variable.
|
|
void historyScreen(); // opens the resualt of the saved games.
|
|
void saveGame(); // saves the game in the history.txt file.
|
|
void movePass(); // shows that the player had no moves and it uses the global turn variable.
|
|
void playerNameSelector(int); // shows the screen that gets the users name from the user and gets needs the gam emode number.
|
|
void markMoves(); // mark the possible moves that the player can do with # based on the global turn variable.
|
|
bool moveCheck(int, int); // checks if the move in the inputed point is possible and outputs true or false based on the global turn variable.
|
|
void clearMoves(); // clears all the # in the board.
|
|
void moveUpdate(int, int); // fillips the pices that got flipped by the placed pice in the given point.
|
|
void helpScreen(); // opens the help menu.
|
|
void leaderBoard(); // shows the points and the winner of the game.
|
|
|
|
int main()
|
|
{
|
|
SetConsoleOutputCP(CP_UTF8);
|
|
SetConsoleCP(CP_UTF8);
|
|
while (true)
|
|
{
|
|
int answer = menu();
|
|
switch (answer)
|
|
{
|
|
case 1:
|
|
game();
|
|
saveGame();
|
|
leaderBoard();
|
|
break;
|
|
case 2:
|
|
helpScreen();
|
|
break;
|
|
case 3:
|
|
historyScreen();
|
|
break;
|
|
case 4:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
int menu()
|
|
{
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m 1. New Game \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m 2. Help \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m 3. Game History \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m 4. Exit \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n"
|
|
<< "\x1b[0m";
|
|
return getch() - '0';
|
|
}
|
|
|
|
void game()
|
|
{
|
|
char move;
|
|
int answer = gameModeSelector();
|
|
playerNameSelector(answer);
|
|
boardClear();
|
|
int playerX = 0, playerY = 0;
|
|
if (answer == 2) // enter the game mode.
|
|
{
|
|
// multiplayer mode.
|
|
while (true)
|
|
{
|
|
// check what player has moves.
|
|
bool movePossibleBlack = false;
|
|
bool movePossibleWhite = false;
|
|
char temp1 = turn;
|
|
turn = 'b';
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (moveCheck(i, j))
|
|
{
|
|
movePossibleBlack = true;
|
|
}
|
|
}
|
|
}
|
|
turn = 'w';
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (moveCheck(i, j))
|
|
{
|
|
movePossibleWhite = true;
|
|
}
|
|
}
|
|
}
|
|
turn = temp1;
|
|
// ends the game if no moves can be made.
|
|
if (movePossibleWhite == false && movePossibleBlack == false)
|
|
{
|
|
break;
|
|
}
|
|
// passes the turn if the player doesn't have any moves.
|
|
if (turn == 'w' && movePossibleWhite == false)
|
|
{
|
|
movePass();
|
|
turn = 'b';
|
|
}
|
|
if (turn == 'b' && movePossibleBlack == false)
|
|
{
|
|
movePass();
|
|
turn = 'w';
|
|
}
|
|
markMoves();
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
gameScreenUpdate();
|
|
move = getch();
|
|
// for uppercase handling
|
|
switch (move)
|
|
{
|
|
case 'A':
|
|
move = 'a';
|
|
break;
|
|
case 'S':
|
|
move = 's';
|
|
break;
|
|
case 'W':
|
|
move = 'w';
|
|
break;
|
|
case 'D':
|
|
move = 'd';
|
|
break;
|
|
case 13:
|
|
move = 13;
|
|
break;
|
|
}
|
|
// move player until possible move got selected.
|
|
while (true)
|
|
{
|
|
switch (move)
|
|
{
|
|
case 'w':
|
|
if (playerX > 0)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerX--;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
case 'a':
|
|
if (playerY > 0)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerY--;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
case 'd':
|
|
if (playerY < n - 1)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerY++;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
case 's':
|
|
if (playerX < n - 1)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerX++;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
}
|
|
board[playerX][playerY] = temp;
|
|
clearMoves();
|
|
// save the move if it was possible.
|
|
if (moveCheck(playerX, playerY) && move == 13)
|
|
{
|
|
if (turn == 'w')
|
|
{
|
|
board[playerX][playerY] = "●";
|
|
}
|
|
else
|
|
{
|
|
board[playerX][playerY] = "○";
|
|
}
|
|
moveUpdate(playerX, playerY);
|
|
if (turn == 'w')
|
|
{
|
|
board[playerX][playerY] = "\x1b[0m \x1b[0m";
|
|
}
|
|
else
|
|
{
|
|
board[playerX][playerY] = "\x1b[40m \x1b[0m";
|
|
}
|
|
// flashes the black turn move and confirms.
|
|
if (turn == 'b')
|
|
{
|
|
for (int h = 0; h < 2; h++)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[40m \x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[40m○\x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(370));
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[40m○\x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[40m \x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(370));
|
|
}
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[40m \x1b[0m")
|
|
{
|
|
board[i][j] = "○";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (turn == 'w')
|
|
{
|
|
for (int h = 0; h < 2; h++)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[0m \x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[0m●\x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(370));
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[0m●\x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[0m \x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(370));
|
|
}
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[0m \x1b[0m")
|
|
{
|
|
board[i][j] = "●";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
gameScreenUpdate();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
markMoves();
|
|
}
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
gameScreenUpdate();
|
|
move = getch();
|
|
// for uppercase handling
|
|
switch (move)
|
|
{
|
|
case 'A':
|
|
move = 'a';
|
|
break;
|
|
case 'S':
|
|
move = 's';
|
|
break;
|
|
case 'W':
|
|
move = 'w';
|
|
break;
|
|
case 'D':
|
|
move = 'd';
|
|
break;
|
|
case 13:
|
|
move = 13;
|
|
break;
|
|
}
|
|
}
|
|
board[playerX][playerY] = temp;
|
|
// changes the turn.
|
|
if (turn == 'b')
|
|
{
|
|
turn = 'w';
|
|
}
|
|
else
|
|
{
|
|
turn = 'b';
|
|
}
|
|
clearMoves();
|
|
move = ' ';
|
|
}
|
|
}
|
|
// single player mode.
|
|
else
|
|
{
|
|
while (true)
|
|
{
|
|
// check what player has moves.
|
|
bool movePossibleBlack = false;
|
|
bool movePossibleWhite = false;
|
|
char temp1 = turn;
|
|
turn = 'b';
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (moveCheck(i, j))
|
|
{
|
|
movePossibleBlack = true;
|
|
}
|
|
}
|
|
}
|
|
turn = 'w';
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (moveCheck(i, j))
|
|
{
|
|
movePossibleWhite = true;
|
|
}
|
|
}
|
|
}
|
|
turn = temp1;
|
|
// end the game if no moves where possible
|
|
if (movePossibleWhite == false && movePossibleBlack == false)
|
|
{
|
|
break;
|
|
}
|
|
// check if player has a move if not it will pass the turn
|
|
if (turn == 'w' && movePossibleWhite == false)
|
|
{
|
|
movePass();
|
|
turn = 'b';
|
|
}
|
|
if (turn == 'b' && movePossibleBlack == false)
|
|
{
|
|
movePass();
|
|
turn = 'w';
|
|
}
|
|
|
|
if (turn == 'b')
|
|
{
|
|
markMoves();
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
gameScreenUpdate();
|
|
move = getch();
|
|
// for uppercase handling
|
|
switch (move)
|
|
{
|
|
case 'A':
|
|
move = 'a';
|
|
break;
|
|
case 'S':
|
|
move = 's';
|
|
break;
|
|
case 'W':
|
|
move = 'w';
|
|
break;
|
|
case 'D':
|
|
move = 'd';
|
|
break;
|
|
case 13:
|
|
move = 13;
|
|
break;
|
|
}
|
|
// move player until possible move got selected.
|
|
while (true)
|
|
{
|
|
switch (move)
|
|
{
|
|
case 'w':
|
|
if (playerX > 0)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerX--;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
case 'a':
|
|
if (playerY > 0)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerY--;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
case 'd':
|
|
if (playerY < n - 1)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerY++;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
case 's':
|
|
if (playerX < n - 1)
|
|
{
|
|
board[playerX][playerY] = temp;
|
|
playerX++;
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
}
|
|
break;
|
|
}
|
|
// save the move if it was possible.
|
|
board[playerX][playerY] = temp;
|
|
clearMoves();
|
|
if (moveCheck(playerX, playerY) && move == 13)
|
|
{
|
|
board[playerX][playerY] = "○";
|
|
moveUpdate(playerX, playerY);
|
|
board[playerX][playerY] = "\x1b[40m \x1b[0m";
|
|
for (int h = 0; h < 1; h++)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[40m \x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[40m○\x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(300));
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[40m○\x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[40m \x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(300));
|
|
}
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[40m \x1b[0m")
|
|
{
|
|
board[i][j] = "○";
|
|
}
|
|
}
|
|
}
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
gameScreenUpdate();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
markMoves();
|
|
}
|
|
temp = board[playerX][playerY];
|
|
board[playerX][playerY] = "\x1b[31mX\x1b[0m";
|
|
gameScreenUpdate();
|
|
move = getch();
|
|
// for uppercase handling
|
|
switch (move)
|
|
{
|
|
case 'A':
|
|
move = 'a';
|
|
break;
|
|
case 'S':
|
|
move = 's';
|
|
break;
|
|
case 'W':
|
|
move = 'w';
|
|
break;
|
|
case 'D':
|
|
move = 'd';
|
|
break;
|
|
}
|
|
}
|
|
board[playerX][playerY] = temp;
|
|
}
|
|
// bot move selector.
|
|
else
|
|
{
|
|
int count = 0;
|
|
clearMoves();
|
|
// count possible moves.
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (moveCheck(i, j) == true)
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
// select a randome move from detected possible moves.
|
|
static thread_local mt19937 rng(random_device{}());
|
|
uniform_int_distribution<int> dist(1, count);
|
|
int random = dist(rng);
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (moveCheck(i, j) == true)
|
|
{
|
|
random--;
|
|
}
|
|
if (random == 0)
|
|
{
|
|
// blinks so the move can be seen.
|
|
board[i][j] = "●";
|
|
moveUpdate(i, j);
|
|
board[i][j] = "\x1b[0m \x1b[0m";
|
|
for (int h = 0; h < 2; h++)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[0m \x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[0m●\x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(450));
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[0m●\x1b[0m")
|
|
{
|
|
board[i][j] = "\x1b[0m \x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
this_thread::sleep_for(chrono::milliseconds(450));
|
|
}
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[0m \x1b[0m")
|
|
{
|
|
board[i][j] = "●";
|
|
}
|
|
}
|
|
}
|
|
gameScreenUpdate();
|
|
i = n; // break the for loop.
|
|
j = n; // break the for loop.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// change the turn.
|
|
if (turn == 'b')
|
|
{
|
|
turn = 'w';
|
|
}
|
|
else
|
|
{
|
|
turn = 'b';
|
|
}
|
|
clearMoves();
|
|
move = ' ';
|
|
}
|
|
}
|
|
}
|
|
|
|
void boardClear()
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
board[i][j] = " ";
|
|
}
|
|
}
|
|
board[n / 2 - 1][n / 2 - 1] = "○";
|
|
board[n / 2][n / 2] = "○";
|
|
board[n / 2 - 1][n / 2] = "●";
|
|
board[n / 2][n / 2 - 1] = "●";
|
|
}
|
|
|
|
void gameScreenUpdate()
|
|
{
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━";
|
|
for (int i = 0; i < (n - 4) * 4; i++)
|
|
{
|
|
cout << "━";
|
|
}
|
|
cout << "━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
// count the scores.
|
|
int scoreB = 0, scoreW = 0;
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "●" || board[i][j] == "\x1b[0m \x1b[0m")
|
|
{
|
|
scoreW++;
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "○" || board[i][j] == "\x1b[40m \x1b[0m")
|
|
{
|
|
scoreB++;
|
|
}
|
|
}
|
|
}
|
|
if (temp == "○")
|
|
{
|
|
scoreB++;
|
|
}
|
|
if (temp == "●")
|
|
{
|
|
scoreW++;
|
|
}
|
|
// number of spaces for border.
|
|
int tempScoreW = scoreW, tempScoreB = scoreB;
|
|
int spaces = (n - 4) * 4;
|
|
while (tempScoreW > 9)
|
|
{
|
|
tempScoreW /= 10;
|
|
spaces--;
|
|
}
|
|
while (scoreB > 9)
|
|
{
|
|
tempScoreB /= 10;
|
|
spaces--;
|
|
}
|
|
// updates the screen based on the turn.
|
|
if (turn == 'w')
|
|
{
|
|
cout << "\x1b[36m┃\x1b[0m White player's turn ";
|
|
for (int i = 0; i < (n - 4) * 4; i++)
|
|
{
|
|
cout << " ";
|
|
}
|
|
cout << "\x1b[36m┃\x1b[0m\n";
|
|
}
|
|
else
|
|
{
|
|
cout << "\x1b[36m┃\x1b[0m black player's turn ";
|
|
for (int i = 0; i < (n - 4) * 4; i++)
|
|
{
|
|
cout << " ";
|
|
}
|
|
cout << "\x1b[36m┃\x1b[0m\n";
|
|
}
|
|
cout << "\x1b[36m┃\x1b[0m ";
|
|
for (int i = 0; i < (n - 4) * 4; i++)
|
|
{
|
|
cout << " ";
|
|
}
|
|
cout << " \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m ●: " << scoreW << " ○:" << scoreB << " ";
|
|
for (int i = 0; i < spaces; i++)
|
|
{
|
|
cout << " ";
|
|
}
|
|
cout << "\x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m ";
|
|
for (int i = 0; i < (n - 4) * 4; i++)
|
|
{
|
|
cout << " ";
|
|
}
|
|
cout << " \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m ┌";
|
|
for (int i = 0; i < n - 1; i++)
|
|
{
|
|
cout << "───┬";
|
|
}
|
|
cout << "───┐ \x1b[36m┃\x1b[0m\n";
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
cout << "\x1b[36m┃\x1b[0m ";
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
cout << "│ " << board[i][j] << " ";
|
|
}
|
|
cout << "│";
|
|
cout << " \x1b[36m┃\x1b[0m\n";
|
|
if (i != n - 1)
|
|
{
|
|
cout << "\x1b[36m┃\x1b[0m ├";
|
|
for (int k = 0; k < n - 1; k++)
|
|
{
|
|
cout << "───┼";
|
|
}
|
|
cout << "───┤ \x1b[36m┃\x1b[0m\n";
|
|
}
|
|
}
|
|
cout << "\x1b[36m┃\x1b[0m └";
|
|
for (int i = 0; i < n - 1; i++)
|
|
{
|
|
cout << "───┴";
|
|
}
|
|
cout << "───┘ \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m ";
|
|
for (int i = 0; i < (n - 4) * 4; i++)
|
|
{
|
|
cout << " ";
|
|
}
|
|
cout << " \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━";
|
|
for (int i = 0; i < (n - 4) * 4; i++)
|
|
{
|
|
cout << "━";
|
|
}
|
|
cout << "━━━━━━━━━┛\x1b[0m\n";
|
|
}
|
|
|
|
void markMoves()
|
|
{
|
|
// marks the possible moves
|
|
int x, y;
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (moveCheck(i, j) == true)
|
|
{
|
|
board[i][j] = "\x1b[33m#\x1b[0m";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool moveCheck(int x, int y)
|
|
{
|
|
if (board[x][y] != " ")
|
|
{
|
|
return false;
|
|
}
|
|
bool seen = false;
|
|
string primary, secondary;
|
|
// sets that what player made the move based on the global turn variable.
|
|
if (turn == 'w')
|
|
{
|
|
primary = "●";
|
|
secondary = "○";
|
|
}
|
|
else
|
|
{
|
|
primary = "○";
|
|
secondary = "●";
|
|
}
|
|
// check all n dirrections for one pice that gets fliped.
|
|
for (int j = y - 1; j >= 0; j--)
|
|
{
|
|
if (board[x][j] == " " || board[x][j] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[x][j] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[x][j] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[x][j] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
seen = false;
|
|
for (int j = y + 1; j < n; j++)
|
|
{
|
|
if (board[x][j] == " " || board[x][j] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[x][j] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[x][j] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[x][j] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
seen = false;
|
|
for (int i = x - 1; i >= 0; i--)
|
|
{
|
|
if (board[i][y] == " " || board[i][y] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][y] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[i][y] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][y] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
seen = false;
|
|
for (int i = x + 1; i < n; i++)
|
|
{
|
|
if (board[i][y] == " " || board[i][y] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][y] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[i][y] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][y] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
seen = false;
|
|
for (int i = x - 1, j = y + 1; i >= 0 && j < n; i--, j++)
|
|
{
|
|
if (board[i][j] == " " || board[i][j] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[i][j] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
seen = false;
|
|
for (int i = x + 1, j = y - 1; i < n && j >= 0; i++, j--)
|
|
{
|
|
if (board[i][j] == " " || board[i][j] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[i][j] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
seen = false;
|
|
for (int i = x + 1, j = y + 1; i < n && j < n; i++, j++)
|
|
{
|
|
if (board[i][j] == " " || board[i][j] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[i][j] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
seen = false;
|
|
for (int i = x - 1, j = y - 1; i >= 0 && j >= 0; i--, j--)
|
|
{
|
|
if (board[i][j] == " " || board[i][j] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == primary && seen)
|
|
{
|
|
return true;
|
|
}
|
|
if (board[i][j] == primary)
|
|
{
|
|
break;
|
|
}
|
|
if (board[i][j] == secondary)
|
|
{
|
|
seen = true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void moveUpdate(int x, int y)
|
|
{
|
|
string primary, secondary;
|
|
string primary1;
|
|
bool change = true, seen = false;
|
|
// sets the player that made the move.
|
|
if (turn == 'w')
|
|
{
|
|
primary = "●";
|
|
primary1 = "\x1b[0m \x1b[0m";
|
|
secondary = "○";
|
|
}
|
|
else
|
|
{
|
|
primary = "○";
|
|
primary1 = "\x1b[40m \x1b[0m";
|
|
secondary = "●";
|
|
}
|
|
// check the n directions to flip pices.
|
|
for (int j = y - 1; j >= 0; j--)
|
|
{
|
|
if (board[x][j] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[x][j] == " " && !seen)
|
|
{
|
|
change = false;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int j = y - 1; j >= 0; j--)
|
|
{
|
|
if (board[x][j] == secondary)
|
|
{
|
|
board[x][j] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
change = true, seen = false;
|
|
for (int j = y + 1; j < n; j++)
|
|
{
|
|
if (board[x][j] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[x][j] == " " && !seen)
|
|
{
|
|
change = false;
|
|
break;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int j = y + 1; j < n; j++)
|
|
{
|
|
if (board[x][j] == secondary)
|
|
{
|
|
board[x][j] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
change = true, seen = false;
|
|
for (int i = x - 1; i >= 0; i--)
|
|
{
|
|
if (board[i][y] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[i][y] == " " && !seen)
|
|
{
|
|
change = false;
|
|
break;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int i = x - 1; i >= 0; i--)
|
|
{
|
|
if (board[i][y] == secondary)
|
|
{
|
|
board[i][y] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
change = true, seen = false;
|
|
for (int i = x + 1; i < n; i++)
|
|
{
|
|
if (board[i][y] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[i][y] == " " && !seen)
|
|
{
|
|
change = false;
|
|
break;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int i = x + 1; i < n; i++)
|
|
{
|
|
if (board[i][y] == secondary)
|
|
{
|
|
board[i][y] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
change = true, seen = false;
|
|
for (int i = x - 1, j = y + 1; i >= 0 && j < n; i--, j++)
|
|
{
|
|
if (board[i][j] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[i][j] == " " && !seen)
|
|
{
|
|
change = false;
|
|
break;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int i = x - 1, j = y + 1; i >= 0 && j < n; i--, j++)
|
|
{
|
|
if (board[i][j] == secondary)
|
|
{
|
|
board[i][j] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
change = true, seen = false;
|
|
for (int i = x + 1, j = y - 1; i < n && j >= 0; i++, j--)
|
|
{
|
|
if (board[i][j] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[i][j] == " " && !seen)
|
|
{
|
|
change = false;
|
|
break;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int i = x + 1, j = y - 1; i < n && j >= 0; i++, j--)
|
|
{
|
|
if (board[i][j] == secondary)
|
|
{
|
|
board[i][j] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
change = true, seen = false;
|
|
for (int i = x + 1, j = y + 1; i < n && j < n; i++, j++)
|
|
{
|
|
if (board[i][j] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[i][j] == " " && !seen)
|
|
{
|
|
change = false;
|
|
break;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int i = x + 1, j = y + 1; i < n && j < n; i++, j++)
|
|
{
|
|
if (board[i][j] == secondary)
|
|
{
|
|
board[i][j] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
change = true, seen = false;
|
|
for (int i = x - 1, j = y - 1; i >= 0 && j >= 0; i--, j--)
|
|
{
|
|
if (board[i][j] == primary)
|
|
{
|
|
seen = true;
|
|
}
|
|
if (board[i][j] == " " && !seen)
|
|
{
|
|
change = false;
|
|
break;
|
|
}
|
|
}
|
|
if (change && seen)
|
|
{
|
|
for (int i = x - 1, j = y - 1; i >= 0 && j >= 0; i--, j--)
|
|
{
|
|
if (board[i][j] == secondary)
|
|
{
|
|
board[i][j] = primary1;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void leaderBoard()
|
|
{
|
|
system("cls");
|
|
int black = 0, white = 0;
|
|
string gameStat;
|
|
// count each players pices.
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "○")
|
|
{
|
|
black++;
|
|
}
|
|
if (board[i][j] == "●")
|
|
{
|
|
white++;
|
|
}
|
|
}
|
|
}
|
|
// detect the winner.
|
|
if (black > white)
|
|
{
|
|
gameStat = playerName1;
|
|
}
|
|
if (black < white)
|
|
{
|
|
gameStat = playerName2;
|
|
}
|
|
if (black == white)
|
|
{
|
|
gameStat = "Draw ";
|
|
}
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << "\x1b[38;2;255;0;0mG" << "\x1b[38;2;255;127;0ma" << "\x1b[38;2;255;255;0mm" << "\x1b[38;2;0;255;0me" << " " << "\x1b[38;2;0;255;255mw" << "\x1b[38;2;0;127;255mi" << "\x1b[38;2;0;0;255mn" << "\x1b[38;2;127;0;255mn" << "\x1b[38;2;255;0;255me" << "\x1b[38;2;255;0;127mr" << "\x1b[38;2;255;0;0m:" << "\x1b[0m"
|
|
" \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << gameStat << "\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m Black points: " << black << " ○ \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m White points: " << white << " ● \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m press any key to go back to the menu \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
getch();
|
|
}
|
|
|
|
void helpScreen()
|
|
{
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m You can move by w,a,s and d in the game. \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m You have to press enter to confirm your move.\x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m The possible moves are marked with #. \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m press any key to go back to the menu \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
getch();
|
|
}
|
|
|
|
int gameModeSelector()
|
|
{
|
|
n = 1;
|
|
while (n % 2 == 1)
|
|
{
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m select your board size: \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m it shoud be even and bigger than two. \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
cin >> n;
|
|
}
|
|
int answer = 0;
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m select your game mode: \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m 1. Single player \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m 2. Multiplayer \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
while (answer != 1 && answer != 2)
|
|
{
|
|
answer = getch() - '0';
|
|
}
|
|
return answer;
|
|
}
|
|
|
|
void playerNameSelector(int answer)
|
|
{
|
|
if (answer == 2)
|
|
{
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m Enter the first player's name: \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
cin >> playerName1;
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m Enter the second player's name: \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
cin >> playerName2;
|
|
}
|
|
else
|
|
{
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m Enter your name: \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
cin >> playerName1;
|
|
playerName2 = "bot";
|
|
}
|
|
}
|
|
|
|
void movePass()
|
|
{
|
|
system("cls");
|
|
string nameTemp;
|
|
if (turn == 'b')
|
|
{
|
|
nameTemp = playerName1;
|
|
}
|
|
else
|
|
{
|
|
nameTemp = playerName2;
|
|
}
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << nameTemp << "'s move has passed. \n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m press any key to continue \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
getch();
|
|
}
|
|
|
|
void saveGame()
|
|
{
|
|
// adds the game at the end of the file.
|
|
ofstream file("history.txt", ios::app);
|
|
player playerB, playerW;
|
|
playerB.score = 0;
|
|
playerW.score = 0;
|
|
playerB.name = playerName1;
|
|
playerW.name = playerName2;
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "○")
|
|
{
|
|
playerB.score++;
|
|
}
|
|
if (board[i][j] == "●")
|
|
{
|
|
playerW.score++;
|
|
}
|
|
}
|
|
}
|
|
file << playerB.name << endl;
|
|
file << playerB.score << endl;
|
|
file << playerW.name << endl;
|
|
file << playerW.score << endl;
|
|
// save the date and the time.
|
|
time_t t = time(nullptr);
|
|
tm tm_buf;
|
|
localtime_s(&tm_buf, &t);
|
|
char buf[64] = {0};
|
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm_buf);
|
|
file << buf << endl;
|
|
}
|
|
|
|
void historyScreen()
|
|
{
|
|
// check if there is a history.
|
|
filesystem::path p = "history.txt";
|
|
if (!filesystem::exists(p))
|
|
{
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m There is nothing in the history. \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m press any key to continue \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
getch();
|
|
return;
|
|
}
|
|
ifstream file("history.txt");
|
|
string line;
|
|
int i = 0, count = 0;
|
|
gameStats *game = new gameStats[2000];
|
|
// reads the saved games from the oldest to the newest and saves in an array.
|
|
while (getline(file, line))
|
|
{
|
|
i++;
|
|
if (i == 6)
|
|
{
|
|
i = 1;
|
|
count++;
|
|
}
|
|
switch (i)
|
|
{
|
|
case 1:
|
|
game[count].name1 = line;
|
|
break;
|
|
case 2:
|
|
game[count].score1 = stoi(line);
|
|
break;
|
|
case 3:
|
|
game[count].name2 = line;
|
|
break;
|
|
case 4:
|
|
game[count].score2 = stoi(line);
|
|
break;
|
|
case 5:
|
|
game[count].time = line;
|
|
break;
|
|
}
|
|
}
|
|
char answer = ' ';
|
|
int page = count;
|
|
// shows the newest game and moves between them.
|
|
while (answer != 'q')
|
|
{
|
|
string winner = "";
|
|
// detects the winner
|
|
if (game[page].score1 > game[page].score2)
|
|
{
|
|
winner = "Black";
|
|
}
|
|
if (game[page].score1 < game[page].score2)
|
|
{
|
|
winner = "White";
|
|
}
|
|
if (game[page].score1 == game[page].score2)
|
|
{
|
|
winner = "Draw ";
|
|
}
|
|
system("cls");
|
|
cout << "\x1b[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << "\x1b[38;2;255;0;0mG" << "\x1b[38;2;255;127;0ma" << "\x1b[38;2;255;255;0mm" << "\x1b[38;2;0;255;0me" << " " << "\x1b[38;2;0;255;255mw" << "\x1b[38;2;0;127;255mi" << "\x1b[38;2;0;0;255mn" << "\x1b[38;2;127;0;255mn" << "\x1b[38;2;255;0;255me" << "\x1b[38;2;255;0;127mr" << "\x1b[38;2;255;0;0m:" << "\x1b[0m"
|
|
" \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << winner << " \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << game[page].name1 << " points:\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << game[page].score1 << " ○ \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << game[page].name2 << " points:\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << game[page].score2 << " ● \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m " << game[page].time << " \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m use a and d to see all the games. \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m press q to go back to the menu. \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┃\x1b[0m \x1b[36m┃\x1b[0m\n";
|
|
cout << "\x1b[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\x1b[0m\n";
|
|
answer = getch();
|
|
switch (answer)
|
|
{
|
|
// uppercase handeling
|
|
case 'A':
|
|
answer = 'a';
|
|
break;
|
|
case 'D':
|
|
answer = 'd';
|
|
break;
|
|
case 'Q':
|
|
answer = 'q';
|
|
break;
|
|
}
|
|
if (answer == 'd' && page > 0)
|
|
{
|
|
page--;
|
|
}
|
|
if (answer == 'a' && page < count)
|
|
{
|
|
page++;
|
|
}
|
|
}
|
|
delete[] game;
|
|
}
|
|
|
|
void clearMoves()
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
if (board[i][j] == "\x1b[33m#\x1b[0m")
|
|
{
|
|
board[i][j] = " ";
|
|
}
|
|
}
|
|
}
|
|
} |