C++

 avatar
s7s
plain_text
25 days ago
31 kB
0
Indexable
Never
#include <iostream>
#include <string>
using namespace std;

enum enWinnerS_P_SC { Player = 1, Computer = 2, Draw = 3 };
enum enGameChoice { Stone = 1, Paper = 2, Scissors = 3 };
enum enGameModeS_P_SC { SinglePlayer = 1, MultiPlayer = 2, Settings = 3, Exit = 4 };
enum enDifficulty { Easy = 1, Medium, Hard, Imposible };
enum enSettings { RoundLimit = 1, Difficulty, Sound };
enum enOpType { Add = 1, Sub = 2, Mul = 3, Div = 4, MixOT = 5 };
enum enLevel { EasyMathGame = 1, MidMathGame, HardMathGame, MixDifMathGame };

enum enGame { Stone_Paper_Scissors_Game = 1, X_O_Game, Math_Game };

enum enX_O { X = 1, O };
enum enWinnerX_O { Player_X_O = 1, Computer_X_O, NoWinner_XO };
enum enPlay { Modify_XO = 1, NoModify_XO };
enum enPlayer { Player_XO = 1, Computer_XO };
enum enGameModeX_O { SinglePlayer_XO = 1, MultiPlayer_XO, Settings_XO };

struct stRoundInfo
{
	short RoundNumber = 0;
	enGameChoice PlayerChoice = enGameChoice::Paper;
	enGameChoice ComputerChoice = enGameChoice::Paper;
	enWinnerS_P_SC RoundWinner = enWinnerS_P_SC::Player;
	string WinnerName;
};
struct stGameInfo_S_P_SC
{
	short Rounds = 0;
	short PlayerWinTimes = 0;
	short ComputerWinTimes = 0;
	short DrawTimes = 0;
	enWinnerS_P_SC GameWinner = enWinnerS_P_SC::Draw;
	string WinnerName;
};
struct stGameSettings
{
	int RoundLimit = 10;
	enDifficulty Difficulty = enDifficulty::Medium;
	bool GameOverSound = 0;
};

struct stGameInfo_XO
{
	char XorOorNum[9] = { 'X','X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'};
	short X = 'X';
	short O = 'O';
	enX_O XorO_Turn = enX_O::X;
	bool Win = 0;
	bool Draw = 0;
	short Round = 0;
};
struct stChoice_X_O
{
	char PlayerChoice = 'X', ComputerChoice = 'O';
	short Number1 = 0, Number2 = 0;
	enPlay Position[9] = { Modify_XO , Modify_XO  ,Modify_XO  ,Modify_XO ,Modify_XO ,Modify_XO ,Modify_XO ,Modify_XO ,Modify_XO };
};
struct stGameResult_X_O
{
	short NumberOfRounds = 0, PlayerWon = 0, ComputerWon = 0, NoWinner_XO = 0;
	enWinnerX_O Winner = enWinnerX_O::Player_X_O;
};

struct stQuestion
{
	short Number1 = 0;
	short Number2 = 0;
	enOpType OpType = enOpType::Add;
	enLevel QuestionLevel = enLevel::EasyMathGame;
	string QuestionString = "";
	bool RightAnswer = 1;
	short Result = 0;
};
struct stQuize
{
	stQuestion QuestionList[100];
	short QuestionNumber = 0;
	enLevel QuizeLevel = enLevel::EasyMathGame;
	enOpType OperationType = enOpType::Add;
	short RightQuestionCounter = 0;
	short WrongQuestionCounter = 0;
	bool isPass = 1;
};

short ReadNumber(string Message)
{
	short Number;
	cout << Message;
	cin >> Number;
	return Number;
}
short RandomNumber(short From, short To)
{
	return rand() % (To - From + 1) + From;
}
string Taps(short Length)
{
	string Tap = "";
	for (int i = 1; i <= Length; i++)
	{
		Tap = Tap + "\t";
	}
	return Tap;
}
void ResetScreen()
{
	system("cls");
	system("color 0F");
}
short ReadNumberInRange(string Message, short From, short To)
{
	short Num;

	do
	{
		cout << Message;
		cin >> Num;

	} while (Num < From || Num > To);

	return Num;
}


short HowManyRounds(short RoundLimit)
{
	short Round;
	do
	{
		cout << "How Many Rounds ? 1 to " << RoundLimit << " ?\n";
		cin >> Round;

	} while (Round < 1 || Round > RoundLimit);

	return Round;
}
string Player1Name(string OutherPlayer)
{
	string Player1;
	if (OutherPlayer == "Player 2")
		return "Player 1";
	else
		return "Player";
}
enGameChoice ReadPlayerChoice(short Player)
{
	short Choice;
	do
	{

		cout << "\nPlayer ";
		cout << Player;
		cout << " Choice ? [1]:Stone , [2]:Paper , [3]:Scissors ?  ";
		cin >> Choice;

	} while (Choice > 3 || Choice < 1);

	return (enGameChoice)Choice;
}
enGameChoice GetComputerChoice(enDifficulty Difficulty, enGameChoice PlayerChoice)
{

	int Choice;

	switch (Difficulty)
	{
	case Easy:
		switch (PlayerChoice)
		{
		case Stone:
			Choice = RandomNumber(1, 10);
			if (Choice < 8)
				return enGameChoice::Scissors;
			else
				return (enGameChoice)RandomNumber(1, 3);
			break;
		case Paper:
			Choice = RandomNumber(1, 10);
			if (Choice < 8)
				return enGameChoice::Stone;
			break;
		case Scissors:
			Choice = RandomNumber(1, 10);
			if (Choice < 8)
				return enGameChoice::Paper;
			break;
		}
		break;
	case Medium:
		return (enGameChoice)RandomNumber(1, 3);
		break;
	case Hard:
		switch (PlayerChoice)
		{
		case Stone:
			Choice = RandomNumber(1, 10);
			if (Choice < 8)
				return enGameChoice::Paper;
			else
				return (enGameChoice)RandomNumber(1, 3);
			break;
		case Paper:
			Choice = RandomNumber(1, 10);
			if (Choice < 8)
				return enGameChoice::Scissors;
			else
				return (enGameChoice)RandomNumber(1, 3);
			break;
		case Scissors:
			Choice = RandomNumber(1, 10);
			if (Choice < 8)
				return enGameChoice::Stone;
			else
				return (enGameChoice)RandomNumber(1, 3);
			break;
		}
		break;
	case Imposible:
		switch (PlayerChoice)
		{
		case Stone:
			return enGameChoice::Paper;
			break;
		case Paper:
			return enGameChoice::Scissors;
			break;
		case Scissors:
			return enGameChoice::Stone;
		}
		break;
	}
	return enGameChoice::Stone;
}
enWinnerS_P_SC GetRoundWinner(stRoundInfo RoundInfo)
{

	if (RoundInfo.PlayerChoice == RoundInfo.ComputerChoice)
		return enWinnerS_P_SC::Draw;

	switch (RoundInfo.PlayerChoice)
	{
	case enGameChoice::Stone:
		if (RoundInfo.ComputerChoice == enGameChoice::Paper)
		{
			return enWinnerS_P_SC::Computer;
		}
		break;

	case enGameChoice::Paper:
		if (RoundInfo.ComputerChoice == enGameChoice::Scissors)
		{
			return enWinnerS_P_SC::Computer;
		}
		break;

	case enGameChoice::Scissors:
		if (RoundInfo.ComputerChoice == enGameChoice::Stone)
		{
			return enWinnerS_P_SC::Computer;
		}
		break;
	}

	return enWinnerS_P_SC::Player;

}
string WinnerName(enWinnerS_P_SC RoundWinner, string OutherPlayer)
{
	string Winner[3] = { Player1Name(OutherPlayer) , OutherPlayer , "No Winner" };
	return Winner[(short)RoundWinner - 1];
}
string GetChoiceName(enGameChoice Choice)
{
	string RoundChoice[3] = { "Stone" , "Paper" , "Scissors" };
	return RoundChoice[(short)Choice - 1];
}
void ChangeScreenColor(enWinnerS_P_SC Winner)
{
	switch (Winner)
	{
	case Player:
		system("color 2f");
		break;
	case Computer:
		system("color 4f");
		break;
	case Draw:
		system("color 6f");
		break;

	}
}
void PrintRoundResult(stRoundInfo RoundInfo, string OutherPlayer)
{

	cout << "\n\n__________________Round [" << RoundInfo.RoundNumber << "] __________________\n";
	cout << "\n" << Player1Name(OutherPlayer) << " Choice    :  " << GetChoiceName(RoundInfo.PlayerChoice);
	cout << "\n" << OutherPlayer << " Choice  :  " << GetChoiceName(RoundInfo.ComputerChoice);
	cout << "\nRound Winner     :  [" << RoundInfo.WinnerName << "]";
	cout << "\n______________________________________________\n";

	ChangeScreenColor(RoundInfo.RoundWinner);

}
enWinnerS_P_SC FinalGameWinner(short PlayerWinTimes, short ComputerWinTimes)
{
	if (PlayerWinTimes > ComputerWinTimes)
		return enWinnerS_P_SC::Player;
	else if (PlayerWinTimes < ComputerWinTimes)
		return enWinnerS_P_SC::Computer;
	else
		return enWinnerS_P_SC::Draw;
}
stGameInfo_S_P_SC FillGameInfo(short HowManyRounds, short PlayerWinTimes, short ComputerWinTimes, short DrawTimes, string OutherPlayer)
{

	stGameInfo_S_P_SC GameResult;

	GameResult.Rounds = HowManyRounds;
	GameResult.PlayerWinTimes = PlayerWinTimes;
	GameResult.ComputerWinTimes = ComputerWinTimes;
	GameResult.DrawTimes = DrawTimes;
	GameResult.GameWinner = FinalGameWinner(PlayerWinTimes, ComputerWinTimes);

	GameResult.WinnerName = WinnerName(GameResult.GameWinner, OutherPlayer);

	return GameResult;

}
stGameInfo_S_P_SC GamePlay(short HowManyRounds, string OutherPlayer, enDifficulty Difficulty)
{
	stRoundInfo RoundInfo;
	short PlayerWinTimes = 0, ComputerWinTimes = 0, DrawTimes = 0;

	for (short Round = 1; Round <= HowManyRounds; Round++)
	{

		cout << "\n\nRound [" << Round << "] begins : \n\n";
		RoundInfo.RoundNumber = Round;
		RoundInfo.PlayerChoice = ReadPlayerChoice(1);

		if (OutherPlayer == "Player 2")
			RoundInfo.ComputerChoice = ReadPlayerChoice(2);
		else
			RoundInfo.ComputerChoice = GetComputerChoice(Difficulty, RoundInfo.PlayerChoice);

		RoundInfo.RoundWinner = GetRoundWinner(RoundInfo);
		RoundInfo.WinnerName = WinnerName(RoundInfo.RoundWinner, OutherPlayer);

		if (RoundInfo.RoundWinner == enWinnerS_P_SC::Player)
			PlayerWinTimes++;
		else if (RoundInfo.RoundWinner == enWinnerS_P_SC::Computer)
			ComputerWinTimes++;
		else
			DrawTimes++;

		PrintRoundResult(RoundInfo, OutherPlayer);

	}


	return FillGameInfo(HowManyRounds, PlayerWinTimes, ComputerWinTimes, DrawTimes, OutherPlayer);

}
void PrintGameOverScreen(bool GameOverSound)
{
	cout << "\n" << Taps(2) << "_____________________________________________________\n\n";
	cout << Taps(4) << "+++G a m e  O v e r+++";
	cout << "\n" << Taps(2) << "_____________________________________________________\n\n";

	if (GameOverSound)
		cout << "\a";
}
void PrintGameResult(stGameInfo_S_P_SC GameResult, string OutherPlayer)
{
	cout << "\n" << Taps(2) << "_______________[Game Resluts]_______________\n";
	cout << "\n" << Taps(2) << "Game Rounds         :  " << GameResult.Rounds;
	cout << "\n" << Taps(2) << Player1Name(OutherPlayer) << " Win Times    :  " << GameResult.PlayerWinTimes;
	cout << "\n" << Taps(2) << OutherPlayer << " Win Times  :  " << GameResult.ComputerWinTimes;
	cout << "\n" << Taps(2) << "Draw Times          :  " << GameResult.DrawTimes;
	cout << "\n" << Taps(2) << "Final Winner        :  " << WinnerName(GameResult.GameWinner, OutherPlayer);
	cout << "\n" << Taps(2) << "____________________________________________\n";

	ChangeScreenColor(GameResult.GameWinner);
}
char AskUserToPlayAgain()
{
	char Replay;
	cout << Taps(2) << "Do you want to play again ?  Y / N :  ";
	cin >> Replay;
	return Replay;
}
void PlayGame_S_P_SC(string OutherPlayer, stGameSettings Settings)
{
	char Replay = 'Y';

	do
	{

		ResetScreen();
		stGameInfo_S_P_SC GameResult = GamePlay(HowManyRounds(Settings.RoundLimit), OutherPlayer, Settings.Difficulty);
		PrintGameOverScreen(Settings.GameOverSound);
		PrintGameResult(GameResult, OutherPlayer);
		Replay = AskUserToPlayAgain();


	} while (Replay == 'Y' || Replay == 'y');

}
void ShowStartGameScreen()
{
	cout << "\n" << Taps(2) << "____________________________________________________\n";
	cout << Taps(2) << "|" << Taps(6) << "   |\n";
	cout << Taps(2) << "|" << Taps(6) << "   |\n";
	cout << Taps(2) << "|" << Taps(1) << "  W e l c o m   T o   M y   G a m e    " << Taps(1) << "   |\n";
	cout << Taps(2) << "|" << Taps(6) << "   |\n";
	cout << Taps(2) << "|__________________________________________________|\n\n";
}
void ShowGameModeScreen()
{
	cout << "\n" << Taps(2) << "__________________[Chouse Game Mode]_________________\n";
	cout << Taps(2) << "|" << Taps(6) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[1]:Single Player ( vs Computer )   " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[2]:Multi Players  ( vs Friend )    " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[3]:Settings                        " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[4]:Exit                            " << Taps(1) << "    |\n";
	cout << Taps(2) << "|___________________________________________________|\n\n";
}
enGameModeS_P_SC GameMode()
{
	short Mode;
	ShowStartGameScreen();
	ShowGameModeScreen();
	cout << "\n" << Taps(2) << "    >> ";
	cin >> Mode;

	return (enGameModeS_P_SC)Mode;
}
void ShowSettingsScreen()
{
	cout << "\n" << Taps(2) << "____________________________________________________\n";
	cout << Taps(2) << "|" << Taps(6) << "   |\n";
	cout << Taps(2) << "|" << Taps(2) << "   S e t t i n g s" << Taps(2) << "   |\n";
	cout << Taps(2) << "|__________________________________________________|\n\n";
}
string TrueFalse(bool TrueOrFalse)
{
	if (TrueOrFalse == true)
		return "True";
	else
		return "False";
}
void ShowSettingsMenu(stGameSettings Settings)
{

	cout << "\n" << Taps(2) << "Game Rounds Limit   :  " << Settings.RoundLimit << Taps(1) << "Modify:[1]";
	cout << "\n" << Taps(2) << "Difficulty          :  " << Settings.Difficulty << Taps(1) << "Modify:[2]";
	cout << "\n" << Taps(2) << "Game Over Sound     :  " << TrueFalse(Settings.GameOverSound) << Taps(1) << "Modify:[3]";;
	cout << "\n" << Taps(2) << "___________________________________________________\n";
	cout << "\n" << Taps(2) << "What do you need to modify ?  >>  ";

}
short ChangeRoundLimit(short Round)
{

	char ConfirmModify;
	cout << "\n" << Taps(2) << "Game Rounds Limit   :  " << Round;
	cout << "\n" << Taps(2) << "Do You Need To Modify Round Limit ?  Y / N  >>  ";
	cin >> ConfirmModify;

	if (ConfirmModify == 'Y' || ConfirmModify == 'y')
	{
		cout << "\n" << Taps(2) << "How Many Rounds Do You Need ?  >>  ";
		cin >> Round;
	}
	else if (!(ConfirmModify == 'N' || ConfirmModify == 'n'))
	{
		cout << "\nError >> Command Not Found >> Retry Please";
	}
	else
	{
		ConfirmModify = 'N';
	}

	return Round;
}
string GetDiffecultyName(enDifficulty Difficulty)
{
	string arr[4] = { "Easy" , "Medium" , "Hard" , "Imposible" };
	return arr[(short)Difficulty - 1];
}
void DifficultyMenu()
{
	cout << "\n" << Taps(2) << "_________________[Chouse Difficulty]_________________\n";
	cout << Taps(2) << "|" << Taps(6) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[1]:Easy                            " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[2]:Medium                          " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[3]:Hard                            " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[4]:Imposible                       " << Taps(1) << "    |\n";
	cout << Taps(2) << "|___________________________________________________|\n\n";
	cout << "\n" << Taps(2) << "What Difficulty Do you Need ?  >>  ";
}
enDifficulty ChangeDifficulty(enDifficulty Difficulty)
{
	char ConfirmModify;
	short Choise;
	cout << "\n" << Taps(2) << "Game Difficulty   :  " << GetDiffecultyName(Difficulty);
	cout << "\n" << Taps(2) << "Do You Need To Modify Difficulty ?  Y / N  >>  ";
	cin >> ConfirmModify;

	if (ConfirmModify == 'Y' || ConfirmModify == 'y')
	{
		DifficultyMenu();
		cin >> Choise;
		Difficulty = (enDifficulty)Choise;
	}
	else if (!(ConfirmModify == 'N' || ConfirmModify == 'n'))
	{
		cout << "\nError >> Command Not Found >> Retry Please";
	}
	else
	{
		ConfirmModify = 'N';
	}

	return Difficulty;
}
bool ChangeSound(bool GameOverSound)
{
	char Confirm;
	cout << "\n" << Taps(2) << "Game Over Sound   :  " << TrueFalse(GameOverSound);
	cout << "\n" << Taps(2) << "Do You Need To Modify Game Over Sound ?  Y / N  >>  ";
	cin >> Confirm;

	if ((Confirm == 'y') || (Confirm == 'Y'))
	{
		if (GameOverSound == false)
		{
			cout << "\n" << Taps(2) << "[1]:Turn Sound 'On'";
			return true;
		}
		else
		{
			cout << "\n" << Taps(2) << "[2]:Turn Sound 'Off'";
			return false;
		}
	}

	return true;
}
stGameSettings Modify(enSettings Setting, stGameSettings SettingsInfo)
{

	ResetScreen();

	switch (Setting)
	{
	case RoundLimit:
		SettingsInfo.RoundLimit = ChangeRoundLimit(SettingsInfo.RoundLimit);
		break;
	case Difficulty:
		SettingsInfo.Difficulty = ChangeDifficulty(SettingsInfo.Difficulty);
		break;
	case Sound:
		SettingsInfo.GameOverSound = ChangeSound(SettingsInfo.RoundLimit);
		break;
	}

	return SettingsInfo;

}
stGameSettings ModifySettings(stGameSettings Settings)
{

	ResetScreen();



	ShowSettingsScreen();
	ShowSettingsMenu(Settings);

	return Modify((enSettings)ReadNumber(""), Settings);


}
void Play_Stone_Paper_Scissors()
{
	stGameSettings Settings;
	bool Exit = false;

	while (Exit == false)
	{

		ResetScreen();
		enGameModeS_P_SC Mode = GameMode();

		if (Mode == enGameModeS_P_SC::SinglePlayer)
			PlayGame_S_P_SC("Computer", Settings);
		else if (Mode == enGameModeS_P_SC::MultiPlayer)
			PlayGame_S_P_SC("Player 2", Settings);
		else if (Mode == enGameModeS_P_SC::Settings)
			Settings = ModifySettings(Settings);
		else
			Exit = true;

	}

}
void ShowGamesMenu()
{
	cout << "\n" << Taps(2) << "____________________[Chouse Game]____________________\n";
	cout << Taps(2) << "|" << Taps(6) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[1]: Stone - Paper - Scissors Game  " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[2]: X - O Game                     " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[3]: Math Game                      " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[4]: Exit                           " << Taps(1) << "    |\n";
	cout << Taps(2) << "|___________________________________________________|\n\n";
}


void ShowGameTable(stGameInfo_XO Game)
{

	short L = 0;
	cout << "\t _______________\n";
	cout << "\t|               |\n";

	for (short j = 1; j <= 3; j++)
	{
		cout << "\t|   ";
		for (short i = 0 + L; i < 3 + L; i++)
		{
			cout << Game.XorOorNum[i] << "   ";
		}

		cout << "|";

		if (L < 6)
			cout << endl << "\t|               |";

		cout << endl;

		L = L + 3;
	}

	cout << "\t|_______________|";
}
void FillGame(stGameInfo_XO& Game)
{

	Game.XorOorNum[0] = '1';

	for (int i = 1; i < 9; i++)
		Game.XorOorNum[i] = char(int(Game.XorOorNum[0]) + i);
}
void Play(stGameInfo_XO& Game)
{

	if (Game.XorO_Turn == enX_O::X)
	{
		do
		{
			Game.X = ReadNumber("\n\n\tChouse Your Position - Player < X >  >>  ");
		} while (Game.X > 9 || Game.X < 1);
	}
	else
	{
		do
		{
			Game.O = ReadNumber("\n\n\tChouse Your Position - Player < O >  >>  ");
		} while (Game.O > 9 || Game.O < 1);
	}
}
void Turn(enX_O& Turn)
{
	if (Turn == enX_O::X)
		Turn = enX_O::O;
	else
		Turn = enX_O::X;
}
void ChangeTablePositions(stGameInfo_XO& Game)
{
	if (Game.XorO_Turn == enX_O::X)
		Game.XorOorNum[Game.X - 1] = 'X';
	else
		Game.XorOorNum[Game.O - 1] = 'O';
}
void CheckWin(stGameInfo_XO& Game)
{

	for (int i = 0; i < 9; i = i + 3)
	{
		if (Game.XorOorNum[i] == Game.XorOorNum[i + 1] && Game.XorOorNum[i] == Game.XorOorNum[i + 2])
			Game.Win = true;
	}

	for (int j = 0; j < 3; j++)
	{
		if (Game.XorOorNum[j] == Game.XorOorNum[j + 3] && Game.XorOorNum[j] == Game.XorOorNum[j + 6])
			Game.Win = true;
	}

	if (Game.XorOorNum[0] == Game.XorOorNum[4] && Game.XorOorNum[0] == Game.XorOorNum[8])
		Game.Win = true;

	if (Game.XorOorNum[2] == Game.XorOorNum[4] && Game.XorOorNum[2] == Game.XorOorNum[6])
		Game.Win = true;

}
char GetWinner(enX_O Winner)
{
	//reversed 
	char arr[2] = { 'O' , 'X' };

	return arr[(short)Winner - 1];
}
void PrintWinScreen(stGameInfo_XO& Game)
{
	if (Game.Win)
		cout << "\n\n\tThe Winner is Player < " << GetWinner(Game.XorO_Turn) << " >";
}
void PrintDrawScreen()
{
	cout << "\n\nNo Winner !!!";
}
void EndGame(stGameInfo_XO& Game)
{

	ResetScreen();
	ShowGameTable(Game);

	if (Game.Win)
	{
		PrintWinScreen(Game);
	}

	if (Game.Round == 9)
	{
		PrintDrawScreen();
		Game.Draw = true;
	}


}
char PlayerChoice()
{
	char Player_X_O = 'X';

	cout << "Choice: [X] or [O]: ";
	cin >> Player_X_O;
	return Player_X_O;
}
short ReadNumberFromPlayer()
{
	short Number = 0;
	cout << "Choice Number Form 1 To 9 : ";
	cin >> Number;
	return Number;
}
short ReadNumberFromComputer(stChoice_X_O Choice)
{
	short Number = 0;
	do
	{
		Number = RandomNumber(0, 8);

	} while (Choice.Position[Number - 1] == enPlay::NoModify_XO);
	return Number;
}
void DrawTablePlay(char Arrchar[9])
{
	cout << "           ----------------------\n";
	cout << "           |    (X - O) Game     |\n";
	cout << "           ----------------------\n\n";
	cout << "----------------------------------------------\n";
	for (short i = 0; i < 3; i++)
	{
		for (short j = 0; j < 3; j++)
		{
			cout << '|' << "\t" << Arrchar[3 * i + j] << "\t";
		}
		cout << "\n";
		cout << "----------------------------------------------\n";
	}
}
void CheckValiablePosistion(stChoice_X_O& Choice, enPlayer PorC)
{
	if (PorC == enPlayer::Player_XO)
		Choice.Position[Choice.Number1 - 1] = enPlay::NoModify_XO;
	else
		Choice.Position[Choice.Number2 - 1] = enPlay::NoModify_XO;
}
char GetResult(char Arrchar[9], stChoice_X_O& Choice)
{
	ResetScreen();
	DrawTablePlay(Arrchar);

	char Result = 'N';
	for (short i = 0; i < 5; i++)
	{

		Choice.Number1 = ReadNumberFromPlayer();
		CheckValiablePosistion(Choice, enPlayer::Player_XO);
		Choice.Number2 = ReadNumberFromComputer(Choice);
		CheckValiablePosistion(Choice, enPlayer::Computer_XO);
		Arrchar[Choice.Number2 - 1] = Choice.ComputerChoice;

		if (Arrchar[Choice.Number1 - 1] != Choice.PlayerChoice && Arrchar[Choice.Number1 - 1] != Choice.ComputerChoice)
		{
			Arrchar[Choice.Number1 - 1] = Choice.PlayerChoice;
			cout << endl;
		}

		ResetScreen();
		DrawTablePlay(Arrchar);

		for (int i = 0; i < 9; i = i + 3)
		{
			if (Arrchar[i] == Arrchar[i + 1] && Arrchar[i] == Arrchar[i + 2])
				return Arrchar[i];
		}
		for (int j = 0; j < 3; j++)
		{
			if (Arrchar[j] == Arrchar[j + 3] && Arrchar[j] == Arrchar[j + 6])
				return Arrchar[j];
		}

		if (Arrchar[0] == Arrchar[4] && Arrchar[0] == Arrchar[8])
			return Arrchar[0];

		if (Arrchar[2] == Arrchar[4] && Arrchar[2] == Arrchar[6])
			return Arrchar[2];

		Arrchar[Choice.Number2 - 1] = Choice.ComputerChoice;

	}

	return Arrchar[0];

}
stGameResult_X_O FillResult(char Arr[9], stChoice_X_O Choice, stGameResult_X_O& GameResult)
{
	char Result = GetResult(Arr, Choice);
	if (Result == Choice.PlayerChoice)
	{
		GameResult.Winner = enWinnerX_O::Player_X_O;
		GameResult.PlayerWon++;
	}
	else if (Result == Choice.ComputerChoice)
	{
		GameResult.Winner = enWinnerX_O::Computer_X_O;
		GameResult.ComputerWon++;
	}
	else if (Result == 'N')
	{
		GameResult.Winner = enWinnerX_O::NoWinner_XO;
		GameResult.NoWinner_XO++;
	}
	GameResult.NumberOfRounds = GameResult.ComputerWon + GameResult.NoWinner_XO + GameResult.PlayerWon;
	return GameResult;
}
string FinalWinner(stGameResult_X_O GameResult)
{
	if (GameResult.PlayerWon > GameResult.ComputerWon)
	{
		system("color 2F");
		return "Player is Winner \n";
	}

	else if (GameResult.ComputerWon > GameResult.PlayerWon)
	{
		system("color 4F");
		cout << "\a";
		return "Computer is Winner \n";
	}

	else
	{
		system("color 6F");
		return "No Winner \n";
	}

}
void PrintFinalResult(stGameResult_X_O GameResult)
{
	cout << "Number Of Rounds : " << GameResult.NumberOfRounds << endl;
	cout << "Player Won       : " << GameResult.PlayerWon << endl;
	cout << "Computer Won     : " << GameResult.ComputerWon << endl;
	cout << "No Winner        : " << GameResult.NoWinner_XO << endl;
	cout << "Final Winner     : " << FinalWinner(GameResult) << endl;
}
stChoice_X_O Choice_X_Or_O()
{
	stChoice_X_O Choice;
	Choice.PlayerChoice = PlayerChoice();
	if (Choice.PlayerChoice == 'X')
		Choice.ComputerChoice = 'O';
	else
		Choice.ComputerChoice = 'X';
	return Choice;
}
void ResetScreenGame(char Arr[9])
{
	system("cls");
	char Arr1[9] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
	for (short i = 0; i < 9; i++)
	{
		Arr[i] = Arr1[i];
	}
}
short HowManyGames()
{
	short Games = 0;
	do
	{
		cout << "How many games you want to Play ? from 3 To 10 ? >> ";
		cin >> Games;
	} while (Games < 3 || Games > 10);
	return Games;
}
string RoundWinner(enWinnerX_O Winner)
{
	string arr[3] = { ">> Y o u   W o n   T h e   G a m e <<" , ">> C o m p u t e r    W o n    T h e   G a m e <<" ,
		">> T h e r e    I s   N o   W i n n e r <<" };

	return arr[(short)Winner - 1];
}
void PlayGame_X_O(char Arr[9])
{
	string Round;
	stGameResult_X_O GameResult;
	short Rounds = HowManyGames();
	for (short i = 0; i < Rounds; i++)
	{
		FillResult(Arr, Choice_X_Or_O(), GameResult);
		cout << "\n\n\t\t" << RoundWinner(GameResult.Winner);
		cout << "\n\n\t\tTap \"Enter\" To Start The Next Round >> ";
		getline(cin, Round);
		getline(cin, Round);
		ResetScreenGame(Arr);
	}
	PrintFinalResult(GameResult);
}
void PlaySinglePlayerX_O()
{
	char PlayAgain = 'Y';
	do
	{
		ResetScreen();
		char Arr[9] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
		ResetScreenGame(Arr);
		PlayGame_X_O(Arr);
		cout << "Do you want to play again ? Y/N \n";
		cin >> PlayAgain;

	} while (PlayAgain == 'Y' || PlayAgain == 'y');

}
void WinOrDrawScreen(stGameInfo_XO Game)
{
	if (Game.Win)
		PrintWinScreen(Game);
	else
		PrintDrawScreen();
}
void PlayMultiPlayerX_O()
{
	string Next;
	ResetScreen();
	short Rounds = ReadNumber("\nHow many Rounds You need To Play ? >> ");

	for (int i = 0; i <= Rounds; i++)
	{


		stGameInfo_XO Game;

		FillGame(Game);
		Game.XorO_Turn = (enX_O)RandomNumber(1, 2);

		do
		{
			Game.Round++;

			ResetScreen();
			ShowGameTable(Game);
			Play(Game);
			ChangeTablePositions(Game);
			CheckWin(Game);
			//EndGame(Game);
			Turn(Game.XorO_Turn);

		} while (!Game.Win && !Game.Draw);

		ResetScreen();
		ShowGameTable(Game);
		WinOrDrawScreen(Game);

		cout << "\n\n\n\t\tPress \"Enter\" to continue >> ";
		getline(cin, Next);
		getline(cin, Next);
	}


}
void ShowXO_GameModeScreen()
{

	cout << "\n" << Taps(2) << "__________________[Chouse Game Mode]_________________\n";
	cout << Taps(2) << "|" << Taps(6) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[1]:Single Player ( vs Computer )   " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[2]:Multi Players  ( vs Friend )    " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[3]:Settings                        " << Taps(1) << "    |\n";
	cout << Taps(2) << "|" << Taps(1) << "[4]:Exit                            " << Taps(1) << "    |\n";
	cout << Taps(2) << "|___________________________________________________|\n\n";

}
void StartGameXO()
{
	char Replay = 'Y';
	bool Exit = false;
	do
	{
		ResetScreen();
		ShowXO_GameModeScreen();
		enGameModeX_O X_O_GameMode;
		X_O_GameMode = (enGameModeX_O)ReadNumber("\n\n\t\tChouse Game Mode >> ");

		switch (X_O_GameMode)
		{
		case SinglePlayer_XO:
			PlaySinglePlayerX_O();
			break;
		case MultiPlayer_XO:
			PlayMultiPlayerX_O();
			break;
		case Settings_XO:
			break;
		default:
			Exit = true;
			break;
		}

	} while (!Exit);

}
void Play_XO_Game()
{

	char Replay = 'y';

	do
	{
		ResetScreen();
		StartGameXO();

		cout << "\n\n\t\tDo You Need To Play Again ???  >>  ";
		cin >> Replay;

	} while (Replay == 'Y' || Replay == 'y');

}
//

void GreenOrRed(bool Green)
{
	if (Green)
		system("color 2f");
	else
	{
		system("color 4f");
		cout << "\a";
	}
}
short CalculateResult(stQuestion& Question)
{

	if (Question.OpType == enOpType::MixOT)
		Question.OpType = (enOpType)RandomNumber(1, 4);

	switch (Question.OpType)
	{
	case Add:
		return Question.Number1 + Question.Number2;
	case Sub:
		return Question.Number1 - Question.Number2;
	case Mul:
		return Question.Number1 * Question.Number2;
	case Div:
		return Question.Number1 / Question.Number2;
	}

	return Question.Number1 + Question.Number2;
}
string ReturnOpTypeChar(enOpType OpType)
{
	string OT[5] = { "+","-","*","/","Mix" };
	return OT[(short)OpType - 1];
}
string ReturnQuestionString(stQuestion Question)
{
	string OT = ReturnOpTypeChar(Question.OpType);
	Question.QuestionString = to_string(Question.Number1) + "\n" + to_string(Question.Number2) + " " + OT + "\n_______________\n =";
	return Question.QuestionString;
}
stQuestion GenerateQuestion(stQuize Quize)
{

	stQuestion Question;

	if (Quize.QuizeLevel == enLevel::MixDifMathGame)
		Question.QuestionLevel = (enLevel)RandomNumber(1, 3);
	else
		Question.QuestionLevel = Quize.QuizeLevel;

	switch (Question.QuestionLevel)
	{
	case enLevel::EasyMathGame:
		Question.Number1 = RandomNumber(1, 10);
		Question.Number2 = RandomNumber(1, 10);
		break;
	case enLevel::MidMathGame:
		Question.Number1 = RandomNumber(10, 50);
		Question.Number2 = RandomNumber(10, 50);
		break;
	case enLevel::HardMathGame:
		Question.Number1 = RandomNumber(50, 100);
		Question.Number2 = RandomNumber(50, 100);
		break;
	}

	Question.OpType = Quize.OperationType;
	Question.Result = CalculateResult(Question);
	Question.QuestionString = ReturnQuestionString(Question);

	return Question;
}
void GenerateQuize(stQuize& Quize)
{
	for (short i = 0; i <= Quize.QuestionNumber; i++)
		Quize.QuestionList[i] = GenerateQuestion(Quize);
}
void AskForAnswerAndSheckAnswer(stQuize& Quize)
{

	for (short i = 0; i < Quize.QuestionNumber; i++)
	{

		cout << "\n\nQuestion [" << i << "/" << Quize.QuestionNumber << "]\n\n";

		if (ReadNumber(Quize.QuestionList[i].QuestionString + " ") == Quize.QuestionList[i].Result)
		{
			cout << "\n\nRight Answer :-)\n\n";
			GreenOrRed(1);
			Quize.RightQuestionCounter++;
		}
		else
		{
			cout << "\n\nWrong Answer :-(\nRight Answer is : " << Quize.QuestionList[i].Result << endl;
			GreenOrRed(0);
			Quize.WrongQuestionCounter++;
		}

	}

}
bool IsPass(stQuize Quize)
{
	return Quize.RightQuestionCounter > Quize.WrongQuestionCounter;
}
void FinalResultScreen(bool isPass)
{
	cout << "\n\n_______________________________________________\n\n";

	if (isPass)
		cout << "  Final Result is PASS :-)";
	else
		cout << "  Final Result is FAIL :-(";

	cout << "\n_______________________________________________\n\n";
}
string ResturnQuizeLevelText(enLevel QuizeLevel)
{
	string arr[4] = { "Easy" , "Mideum" , "Hard" , "Mix" };
	return arr[(short)QuizeLevel - 1];
}
void FinalResultInfo(stQuize Quize)
{
	cout << "\nNumber of question     : " << Quize.QuestionNumber;
	cout << "\nQuestion Level         : " << ResturnQuizeLevelText(Quize.QuizeLevel);
	cout << "\nOperation Type         : " << ReturnOpTypeChar(Quize.OperationType);
	cout << "\nNumber of right answer : " << Quize.RightQuestionCounter;
	cout << "\nNumber of wrong answer : " << Quize.WrongQuestionCounter;

	cout << "\n_______________________________________________\n\n";
}
void PrintQuizeResult(stQuize& Quize)
{
	Quize.isPass = IsPass(Quize);
	FinalResultScreen(Quize.isPass);
	FinalResultInfo(Quize);
}
void PlayMathGame()
{
	stQuize Quize;

	Quize.QuestionNumber = ReadNumber("How Many Question do you need to answer ? >> ");
	Quize.QuizeLevel = (enLevel)ReadNumber("Enter Question Level [1]:Easy, [2]:Mid, [3]:Hard, [4]:Mix >> ");
	Quize.OperationType = (enOpType)ReadNumber("Enter Operation Type [1]:Add, [2]:Sub, [3]:Mul, [4]:Div, [5]:Mix >> ");

	GenerateQuize(Quize);
	AskForAnswerAndSheckAnswer(Quize);
	PrintQuizeResult(Quize);
}
void Play_Math_Game()
{

	stQuize Quize;

	char RePlay = 'Y';

	do
	{

		ResetScreen();
		PlayMathGame();

		cout << "\n\n\tDo You Need To Play Again ? Y / N >> ";
		cin >> RePlay;

	} while (RePlay == 'y' || RePlay == 'Y');

}

bool StartSellectedGame(enGame Game)
{

	switch (Game)
	{
	case Stone_Paper_Scissors_Game:
		Play_Stone_Paper_Scissors();
		break;
	case X_O_Game:
		Play_XO_Game();
		break;
	case Math_Game:
		Play_Math_Game();
		break;
	default:
		return true;
		break;
	}

	return false;

}
void SelectGame()
{
	bool ExitGameMenu = false;

	do
	{

		ResetScreen();
		ShowGamesMenu();
		ExitGameMenu = StartSellectedGame((enGame)ReadNumber("\n\nWhich Game Do You need To Play ? (Enter Game Number) >> "));

	} while (!ExitGameMenu);

}

int main()
{

	srand((unsigned)time(NULL));

	SelectGame();

	return 0;
}