public void Visit(Game game, IAmTheGameOver gameOver) { System.Console.ForegroundColor = ConsoleColor.Green; System.Console.WriteLine("*********** NEW GAME STARTS HERE *********************"); System.Console.WriteLine("########### HISTORY OF TABLE VIEWS #####################"); System.Console.ResetColor(); foreach (var view in game.TableViewsHistory) { System.Console.WriteLine(view); } System.Console.ForegroundColor = ConsoleColor.Green; switch (gameOver) { case Draw draw: System.Console.WriteLine($"GAME ENDED WITH A DRAW. Reason: {draw.Reason}"); PrintDroppedCards(game); System.Console.WriteLine("\r\nPlayers still have cards: "); foreach (var player in game.Players.Where(p => p.HasCards())) { System.Console.WriteLine($"Player {player.Id} having {player.CardStack.Size} cards"); System.Console.WriteLine($" ===> They are: {player.CardStack.Sort()}\r\n"); } break; case HasWinner hasWinner: var winner = hasWinner.Winner; System.Diagnostics.Debug.Assert(winner.CardStack.Size + game.DroppedCards.Count == game.DistributedCardsSize); System.Console.WriteLine($"GAME OVER."); System.Console.WriteLine($"\r\nTHE WINNER IS 'Player {winner.Id}'"); System.Console.WriteLine($" ===> He has {winner.CardStack.Size} cards: {winner.CardStack.Sort()}"); PrintDroppedCards(game); break; } }
public void Visit(Game game, IAmTheGameOver gameOver) { }
private bool ShouldContinue(ref int iterations, ref int iterationsAfterReShuffle, ref bool reShuffled, out IAmTheGameOver draw) { if (iterations == 1000 && !reShuffled) { foreach (var survivor1000Iterations in Players.Where(p => p.HasCards())) { survivor1000Iterations.CardStack.Shuffle(); } reShuffled = true; draw = new GameOngoing("ReShuffle"); return(true); } if (iterationsAfterReShuffle == 1000) { draw = new Draw($"After {iterations - iterationsAfterReShuffle} iterations and After ReShuffled {iterationsAfterReShuffle} iterations, still no winner. Declare this game as a DRAW"); return(false); } iterations++; if (reShuffled) { iterationsAfterReShuffle++; } draw = new GameOngoing("Continuation when iterations < 1000"); return(false); }