Exemplo n.º 1
0
        private static void GameMenu(ICardGame game)
        {
            ConsoleKey input;

            do
            {
                Console.Clear();
                input = DisplayGameMenu(game.GetDeckName()).Key;
                switch (input)
                {
                case ConsoleKey.D:
                    DisplayHand(game.Deal());
                    break;

                case ConsoleKey.X:
                    DisplayCard(game.Draw());
                    break;

                case ConsoleKey.S:
                    Shuffle(game);
                    break;

                case ConsoleKey.R:
                    Reset(game);
                    break;
                }
            }while (!input.Equals(ConsoleKey.Q));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Used to stop the old card game, and start the new one.
        /// </summary>
        /// <param name="game"></param>
        public void StartNewCardGame(ICardGame game)
        {
            try
            {
                if (VariableStorage.IsCardGameAlreadyGoing)
                {
                    this.Current.Stop();
                }

                VariableStorage.IsCardGameAlreadyGoing = true;

                this.Current = game;
                game.New();
            }
            catch (Exception TheException)
            {
                ErrorReporter.Report(TheException);
            }
        }
Exemplo n.º 3
0
        private void HandleGameOver(ICardGame game)
        {
            this.textInterface.WriteLine();
            if (this.textInterface.GetYesOrNoResponse("Play again?"))
            {
                game.RestartGame();

                this.textInterface.WriteLine();
                if (!this.textInterface.GetYesOrNoResponse("Keep the same players again?"))
                {
                    this.textInterface.Clear();
                    var newPlayers = this.playerCollectionFactory.Create();
                    game.SetPlayers(newPlayers);
                }

                this.ExecuteGame(game);
            }
            else
            {
                this.Exit();
            }
        }
Exemplo n.º 4
0
        private void ExecuteGame(ICardGame game)
        {
            int roundCounter = 1;

            do
            {
                this.textInterface.Clear();
                this.textInterface.WriteLine($"Round {roundCounter}");
                this.textInterface.WriteLine();

                game.ExecuteRound();

                roundCounter++;
                if (!game.IsGameOver())
                {
                    this.textInterface.WriteLine();
                    this.textInterface.Write($"Press {this.continueRoundKey} to continue. ");
                    this.textInterface.ReadSingleCharFromList(new[] { this.continueRoundKey });
                    this.textInterface.Backspace();
                }
            }while (!game.IsGameOver());

            this.HandleGameOver(game);
        }
Exemplo n.º 5
0
 public PassTurnCommand(ICardGame cardGame, TakeTurnCommand nextCommand) : base(cardGame)
 {
     _nextCommand = nextCommand;
 }
Exemplo n.º 6
0
 public TakeTurnCommand(ICardGame cardGame) : base(cardGame) { }
Exemplo n.º 7
0
 private static ConsoleKey Reset(ICardGame game)
 {
     game.ResetDeck();
     Console.WriteLine("\n\nDeck Reset\n");
     return(MenuReturn());
 }
Exemplo n.º 8
0
 private static ConsoleKey Shuffle(ICardGame game)
 {
     game.ShuffleDeck();
     Console.WriteLine("\n\nDeck Shuffled\n");
     return(MenuReturn());
 }
Exemplo n.º 9
0
 protected Command(ICardGame cardGame)
 {
     CardGame = cardGame;
 }