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)); }
/// <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); } }
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(); } }
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); }
public PassTurnCommand(ICardGame cardGame, TakeTurnCommand nextCommand) : base(cardGame) { _nextCommand = nextCommand; }
public TakeTurnCommand(ICardGame cardGame) : base(cardGame) { }
private static ConsoleKey Reset(ICardGame game) { game.ResetDeck(); Console.WriteLine("\n\nDeck Reset\n"); return(MenuReturn()); }
private static ConsoleKey Shuffle(ICardGame game) { game.ShuffleDeck(); Console.WriteLine("\n\nDeck Shuffled\n"); return(MenuReturn()); }
protected Command(ICardGame cardGame) { CardGame = cardGame; }