예제 #1
0
        public async Task GameTurn(CancellationTokenSource cancellationTokenSource)
        {
            if (PlayerOnTurn.IsAI)
            {
                await(PlayerOnTurn.TryToPlay(GameBoard, cancellationTokenSource));
            }
            if (!cancellationTokenSource.IsCancellationRequested)
            {
                if (!PlayerOnTurn.Finished)
                {
                    await PlayerOnTurn.Selection(ToIntToRow(SelectedPosition), ToIntToCol(SelectedPosition), GameBoard, cancellationTokenSource);

                    if (PlayerOnTurn.PlayerMove[(int)GameConstants.MoveParts.result] == (int)GameConstants.MoveResult.Fail && !PlayerOnTurn.StartPositionSelected)
                    {
                        SelectedPosition = "none - Failed Move, Play again.";
                    }
                }
                if (PlayerOnTurn.Finished)
                {
                    GameHistory.Push(new List <int>(PlayerOnTurn.PlayerMove));
                    PlayerOnTurn.PlayerMove.ForEach(Console.Write);
                    PlayerOnTurn.Finished = false;
                    CheckEndGame();
                    RedoStack.Clear();
                    BestMove = null;
                    EndTurn();
                }
            }
        }
예제 #2
0
        private static void Main(string[] args)
        {
            var game = new GameEnvironment()
            {
                CowsCount = 10, MoneysCount = 100
            };
            var gameHistory = new GameHistory();

            game.WriteToConsole();

            gameHistory.Push(game.SaveState());

            game.BuyCow();
            game.WriteToConsole();

            game.RestoreState(gameHistory.Pop());
            game.WriteToConsole();
        }
예제 #3
0
 public void RedoMove()
 {
     if (RedoStack.Count != 0)
     {
         List <int> move = RedoStack.Peek();
         GameBoard.Board[move[0], move[1]] = 0;
         if (move[6] == 1)
         {
             GameBoard.Board[move[3], move[4]] = 8;
         }
         else
         {
             GameBoard.Board[move[3], move[4]] = move[2];
         }
         GameHistory.Push(RedoStack.Pop());
         CheckEndGame();
         PlayerOnTurn = PlayerSwap();
     }
 }