private IMoveResult SaveGame(IMoveResult moveResult, int currentPlayer) { Console.WriteLine("Under what name save the game?"); string file = UserInteraction.ReadNotEmptyStringFromUser(); var saveRepository = SaveRepository.GetDefaultRepository(); bool isEnded = moveResult.IsCheckMate(TeamColor.Black) || moveResult.IsCheckMate(TeamColor.White); var state = new ChessGameState(moveResult, isEnded, _players, _players[currentPlayer].TeamColor, PlayerMode.TwoPlayers, 0); saveRepository.Save(file + ".bin", state); Console.WriteLine("Game saved."); return(new StoppedMoveResult()); }
private IMoveResult SaveGame(IMoveResult moveResult) { Console.WriteLine("Under what name save the game?"); string file = UserInteraction.ReadNotEmptyStringFromUser(); var saveRepository = SaveRepository.GetDefaultRepository(); bool isEnded = moveResult.IsCheckMate(TeamColor.Black) || moveResult.IsCheckMate(TeamColor.White); var state = new ChessGameState(moveResult, isEnded, new [] { _player }, _computer.MyTeamColor, PlayerMode.SinglePlayer, _difficulty); saveRepository.Save(file + ".bin", state); Console.WriteLine("Game saved."); return(new StoppedMoveResult()); }
private void UserMove(IMoveResult moveResult, int userIdx) { while (!moveResult.IsCheckMate(_players[userIdx].TeamColor)) { moveResult = NextTurn(moveResult, userIdx); if (moveResult.IsValidMove().Status == MoveResultStatus.Stopped) { return; } userIdx = userIdx == 1 ? 0 : 1; } EndGame(userIdx); }
private void PlayerMove(IMoveResult moveResult) { BoardDisplay.ShowFullInfoBoard(moveResult); if (moveResult.IsCheckMate(_player.TeamColor)) { Console.WriteLine("\n \n \n \n"); Console.WriteLine($"Computer wins!"); return; } moveResult = PlayerMoveHelper(); if (moveResult.IsValidMove().Status != MoveResultStatus.Stopped) { ComputerMove(moveResult); } }
private void ComputerMove(IMoveResult moveResult) { if (moveResult.IsCheckMate(_computer.MyTeamColor)) { Console.WriteLine("\n \n \n \n"); Console.WriteLine($"Player {_player.Name} wins!"); return; } Console.WriteLine($"==================== Computer - {_computer.MyTeamColor} ====================="); var nextMove = _computer.NextMove(moveResult.GetBoard()); moveResult = _gameConductor.DoMove(nextMove.From, nextMove.Destination); Console.WriteLine($"Computer has moved the figure from the {nextMove.From} position to the {nextMove.Destination} position"); PlayerMove(moveResult); }