private void DoGame() { ScopaGame game = new ScopaGame(); AddPlayers(game); game.BeginGame(); do { game.DealStartingHand(); if (!PlayRound(game)) { Console.Out.WriteLine(game.Current.Name + " ha concesso."); return; } foreach (IScopaPlayer player in game.Players) { Console.Out.Write(player.Name + " ha presa(" + player.CardCount + ")"); #if DEBUG List <Card> cardsTaken = player.CardsTaken; cardsTaken.Sort(); Console.Out.Write(": " + Card.ToString(cardsTaken)); #endif Console.Out.WriteLine(); Console.Out.WriteLine("Primiera: " + player.PrimieraValue); Console.Out.WriteLine("Denari: " + player.DenariCount); Console.Out.WriteLine("Settebello: " + player.SetteBello); Console.Out.WriteLine("Scopa: " + player.ScopaCount); Console.Out.WriteLine(); } PrintRanking(game.ScoreRound()); game.NewRound(); } while (!game.IsGameOver); }
private List <Card> SelectCardsFromTable(ScopaGame game, GameAction action, Card fromHand) { List <Card> fromTable = new List <Card>(); if (game.Table.Count > 0) { CardActions actions = game.PossibleActions[fromHand]; Console.Out.WriteLine(actions.PossibleTricks.Count + " trick(s) are possible with " + fromHand); foreach (List <Card> possibleTrick in actions.PossibleTricks) { Console.Out.WriteLine("Possible Trick: " + Card.ToString(possibleTrick)); } if (actions.PossibleTricks.Count == 1) { fromTable.AddRange(actions.PossibleTricks[0]); } else { int index; Console.Out.WriteLine("Dal tavolo"); while (SelectWhichWithEscape(game.Table.Count, out index)) { fromTable.Add(game.Table[index]); // If the trick is valid do not wait for input from the user if (game.ValidateTrick(fromHand, fromTable)) { break; } } } } return(fromTable); }
private static void PrintTable(ScopaGame game) { Console.Out.WriteLine("Sul Tavolo"); int index = 0; foreach (Card card in game.Table) { Console.Out.WriteLine(" " + (++index) + ") " + card); } Console.Out.WriteLine(); }
private static void PrintHand(ScopaGame game) { Console.Out.WriteLine("La mano di " + game.Current.Name + (game.Current.Equals(game.Dealer) ? "*" : "")); int index = 0; Console.Out.Write(" "); foreach (Card card in game.Current.Hand) { if (index++ > 0) { Console.Out.Write(", "); } Console.Out.Write(index + ") " + (game.ValidateThrow(card) ? "-" : "+") + card); } Console.Out.WriteLine(); }
private void NewGame() { game = new ScopaGame(); selection = new PlaySelection(); computer = new AIScopaPlayer(PLAYER_A_NAME, game); humanPlayer = new UIScopaPlayer(PLAYER_B_NAME, game, selection); game.AddPlayers(new List <IScopaPlayer> { computer, humanPlayer, }); game.BeginGame(); playerAName.Text = computer.Name; playerBName.Text = humanPlayer.Name; BeginNextRound(COMPUTER_INITIAL_INTERVAL); }
private static void AddPlayers(ScopaGame game) { string name = null; int count = 0; do { do { Console.Out.Write("Add A Player: "); name = Console.In.ReadLine(); if (name != null && !"".Equals(name)) { if (count == 0) { game.AddPlayer(new ConsoleScopaPlayer(name, game)); } else { game.AddPlayer(new AIScopaPlayer(name, game)); } ++count; } } while (name != null && !"".Equals(name)); } while (count < 2); /* * Console.Out.Write("Giocatore A: "); * string a = Console.In.ReadLine(); * a = a != null && !"".Equals(a) ? a : "[Giocatore A]"; * Console.Out.Write("Giocatore B: "); * string b = Console.In.ReadLine(); * b = b != null && !"".Equals(b) ? b : "[Giocatore B]"; * Console.Out.Write("Giocatore C: "); * string c = Console.In.ReadLine(); * c = c != null && !"".Equals(c) ? c : "[Giocatore C]"; * game.AddPlayers(new List<IScopaPlayer> { * new AIScopaPlayer (a, game), * new AIScopaPlayer (b, game), * new AIScopaPlayer (c, game), * }); */ }
private bool PlayRound(ScopaGame game) { do { // If everyone has played out their hand deal a new one if (game.IsHandOver) { game.DealHand(); } PrintTable(game); PrintHand(game); game.TakeAction(game.Current, eventHandler); } while (!game.IsRoundOver); if (game.Table.Count > 0) { Console.Out.WriteLine(game.LastTrick.Name + " prende il resto: " + Card.ToString(game.Table)); } game.TakeLastTrick(); return(true); }
public ConsoleScopaPlayer(string name, ScopaGame game) : base(name, game) { }