private void playRound() { this.m_RoundStatus = this.m_Game.NewRound(this.m_CurrentMove); this.handleRound(); if (this.m_Game.CurrentPlayer.IsComputer && this.m_GameWasCreated == true) { this.m_ComputerTimer.Start(); } }
private void handleRound(ref string io_PreviousMove, ref string io_UserMove, ref CheckersGame.eRoundOptions io_CurrentRound, Player i_CurrentPlayer, CheckersGame i_Game) { bool iswinnigPlayer = false; if (io_CurrentRound == CheckersGame.eRoundOptions.weakPlayerQuits) { this.endOfRoundScreen(i_Game, i_CurrentPlayer.PlayerType, iswinnigPlayer, ref io_CurrentRound, ref io_PreviousMove); } else if (io_CurrentRound == CheckersGame.eRoundOptions.strongPlayerWantsToQuit) { // another round - Quit Console.WriteLine("You are not the weak player! Enter a valid move. . ."); Thread.Sleep(800); } else if (io_CurrentRound == CheckersGame.eRoundOptions.playerDidntEnterObligatoryMove) { // another round - Wrong move Console.WriteLine("Invalid move, you must eliminate your opponnent!"); Thread.Sleep(800); } else if (io_CurrentRound == CheckersGame.eRoundOptions.currentPlayerHasAnotherRound) { // another round Console.WriteLine("{0} {1} has another turn", Environment.NewLine, i_CurrentPlayer.Name); Thread.Sleep(800); } else if (io_CurrentRound == CheckersGame.eRoundOptions.playerOneWon) { iswinnigPlayer = true; i_Game.endRoundScoreUpdate(Square.eSquareType.playerTwo); this.endOfRoundScreen(i_Game, Square.eSquareType.playerOne, iswinnigPlayer, ref io_CurrentRound, ref io_PreviousMove); } else if (io_CurrentRound == CheckersGame.eRoundOptions.playerTwoWon) { iswinnigPlayer = true; i_Game.endRoundScoreUpdate(Square.eSquareType.playerOne); this.endOfRoundScreen(i_Game, Square.eSquareType.playerTwo, iswinnigPlayer, ref io_CurrentRound, ref io_PreviousMove); } else if (io_CurrentRound == CheckersGame.eRoundOptions.gameIsATie) { this.endOfRoundScreen(i_Game, Square.eSquareType.none, iswinnigPlayer, ref io_CurrentRound, ref io_PreviousMove); } else if (io_CurrentRound == CheckersGame.eRoundOptions.playerEnteredInvalidMove) { Console.WriteLine("Invalid move, try again . . ."); Thread.Sleep(800); } else { string shape = i_Game.Board.SquareToString(i_Game.Board.GetSquareStatus(Move.Parse(io_UserMove).SquareTo)); io_PreviousMove = i_CurrentPlayer.Name + "'s move was (" + shape + "): " + io_UserMove; } }
private void ComputerTimer_Tick(object sender, EventArgs e) { Timer computerTimer = sender as Timer; this.m_RoundStatus = this.m_Game.NewRound(this.m_Game.CurrentPlayer.ComputerMove(this.m_Game.Board)); this.m_ComputerTimer.Stop(); this.handleRound(); if (this.m_Game.CurrentPlayer.IsComputer) { this.m_ComputerTimer.Start(); } }
private void runGame(CheckersGame i_Game, int i_BoardSize) { string playerChoice = string.Empty; Player currentPlayer = i_Game.PlayerOne; string previousMove = string.Empty; string userMove = string.Empty; CheckersGame.eRoundOptions gameStatus; CheckersGame.eRoundOptions currentRound = CheckersGame.eRoundOptions.passRound; while (currentRound != CheckersGame.eRoundOptions.gameOver) { this.clearScreen(); this.printBoard(i_Game.Board); this.printTurn(previousMove, currentPlayer); if (currentPlayer.PlayerType != Square.eSquareType.playerPC) { userMove = this.getUserMove(i_BoardSize); } else { userMove = currentPlayer.ComputerMove(i_Game.Board); Thread.Sleep(1200); } currentRound = i_Game.NewRound(userMove); gameStatus = i_Game.CheckGameStatus(); if (gameStatus != CheckersGame.eRoundOptions.passRound) { currentRound = gameStatus; } this.handleRound(ref previousMove, ref userMove, ref currentRound, currentPlayer, i_Game); currentPlayer = i_Game.GetCurrentPlayer(); } }
private void endOfRoundScreen(CheckersGame i_Game, Square.eSquareType i_PlayerType, bool i_WinningPlayer, ref CheckersGame.eRoundOptions io_CurrentRound, ref string io_PreviousMove) { this.clearScreen(); this.printEndGame(i_Game, i_PlayerType, i_WinningPlayer); if (!this.playerWantsAnotherRound(i_Game, i_PlayerType)) { Console.WriteLine("Goodbye! :)"); io_CurrentRound = CheckersGame.eRoundOptions.gameOver; } else { // player wants to play another game i_Game.CreateGameBoard(i_Game.Board.Size); io_PreviousMove = string.Empty; } }