public void GainCardByCost(int cost, bool exactCost, bool optional, Kingdom myKingdom, Deck.State state = Deck.State.discardPile, Card.Type type = 0) { ClearIndex(myKingdom); bool done = false; int index = 1; foreach (Deck deck in myKingdom.KingdomSupply) { if (deck.Cards.Count > 0) { if ((deck.Cards[0].cost <= cost && !exactCost) || (deck.Cards[0].cost == cost && exactCost)) { if (type == 0 || deck.Cards[0].types.Contains(type)) { deck.Cards[0].index = index++; } } } } myKingdom.PrintKingdom(); string optionalText = ""; if (optional) { optionalText = " Or, press [n] to gain no card."; } if (exactCost) { Console.WriteLine("\r\nChoose a card from the kingdom to gain costing exactly " + cost + "." + optionalText); } else { Console.WriteLine("\r\nChoose a card from the kingdom to gain costing up to " + cost + "." + optionalText); } do { string buyInput = Console.ReadLine().ToLower(); int intBuyInput = -1; if (Int32.TryParse(buyInput, out intBuyInput)) { if (intBuyInput > 0 && intBuyInput < index) { foreach (Deck deck in myKingdom.KingdomSupply) { if (deck.Cards[0].index == intBuyInput) { Card cardToGain = deck.Cards[deck.Cards.Count - 1]; GainCard(cardToGain, deck, state); done = true; } } } else { Console.WriteLine("Invalid Input."); } } else if (optional && buyInput == "n") { done = true; } else { Console.WriteLine("Invalid Input"); } } while (!done); }
static void Main(string[] args) { bool gameOver = false; Player Broc = new Player("Broc"); Kingdom.SetName chosenSet = Kingdom.SetName.Random; Console.Write("\r\nWelcome to Dominion Mimicing Software!\r\n\r\n Please choose a recommended Set of 10 from the list below, or anything else for Random.\r\n\r\n"); Console.Write("[1]: First Game\r\n[2]: Size Distortion\r\n[3]: Deck Top\r\n[4]: Sleight of Hand\r\n[5]: Improvements\r\n[6]: Silver & Gold\r\n\r\n"); string chosenSetInput = Console.ReadLine().ToLower(); int intChosenSet = -1; if (Int32.TryParse(chosenSetInput, out intChosenSet)) { if (intChosenSet >= 0 && intChosenSet <= 6) { chosenSet = (Kingdom.SetName)intChosenSet; } } Kingdom myKingdom = new Kingdom((Kingdom.SetName)intChosenSet, 1, false); do { Broc.StartTurn(); do { myKingdom.PrintKingdom(); if (Broc.HasActions()) { Broc.PrintHand(); Console.Write("\r\nA to play an action. B to go to buy phase. T to print Trash. H for help. Q to quit.\r\n"); Console.Write("Actions: " + Broc.Actions + ", Buys: " + Broc.Buys + ", Dollars: " + Broc.Dollars + ".\r\n"); switch (Console.ReadLine().ToLower()) { case "a": Broc.ActionPhase(myKingdom); break; case "b": Broc.BuyPhase(myKingdom); break; case "t": myKingdom.PrintTrash(); break; case "printplayer": Broc.PrintPlayer(); break; case "q": gameOver = true; break; } } else { Broc.BuyPhase(myKingdom); } } while (!Broc.TurnComplete && !gameOver); Broc.Cleanup(myKingdom); } while (!gameOver && !myKingdom.GameOver()); Console.WriteLine("Game Over! " + Broc.PlayerName + " won with " + Broc.CalculatePoints() + " points, taking " + Broc.Turns + " turns.\r\nPress enter to continue..."); Console.ReadLine(); }
public void BuyPhase(Kingdom myKingdom) { bool readyToBuy = false; int index = 1; ClearIndex(myKingdom); foreach (Card card in inHand.Cards) { if (card.types.Contains(Card.Type.Treasure)) { card.index = index++; } } do { inHand.PrintDeck(); Console.WriteLine("\r\nSelect Treasures to play from your hand. [A] = All. [#] = Play specific treasure. [D] = Done playing treasures. [T] = Print trash."); Console.WriteLine("Buys: " + Buys + ", Dollars: " + Dollars + "."); string playTreasureInput = Console.ReadLine().ToLower(); if (playTreasureInput == "a") { for (int i = inHand.Cards.Count - 1; i >= 0; i--) { if (inHand.Cards[i].types.Contains(Card.Type.Treasure)) { PlayTreasure(inHand.Cards[i]); } } readyToBuy = true; } else if (playTreasureInput == "d") { readyToBuy = true; } else if (playTreasureInput == "t") { myKingdom.PrintTrash(); } else { int intPlayTreasureInput = -1; if (Int32.TryParse(playTreasureInput, out intPlayTreasureInput)) { if (intPlayTreasureInput > 0 && intPlayTreasureInput < index) { for (int i = 0; i < inHand.Cards.Count; i++) { if (inHand.Cards[i].index == intPlayTreasureInput) { PlayTreasure(inHand.Cards[i]); } } } else { Console.WriteLine("Invalid Input."); } } else { Console.WriteLine("Invalid Input."); } } } while (!readyToBuy); //Ready to buy, reset index index = 1; bool doneBuying = false; foreach (Deck deck in myKingdom.KingdomSupply) { if (deck.Cards.Count > 0) { if (deck.Cards[0].cost <= Dollars) { deck.Cards[0].index = index++; } } } myKingdom.PrintKingdom(); while (!doneBuying) { Console.WriteLine("\r\nChoose a card from the kingdom to buy. [N] for none. Buys: " + Buys + ", Dollars: " + Dollars + "."); string buyInput = Console.ReadLine().ToLower(); int intBuyInput = -1; if (Int32.TryParse(buyInput, out intBuyInput)) { if (intBuyInput > 0 && intBuyInput < index) { foreach (Deck deck in myKingdom.KingdomSupply) { if (deck.Cards[0].index == intBuyInput) { Card cardToGain = deck.Cards[deck.Cards.Count - 1]; GainCard(cardToGain, deck); Dollars = Dollars - cardToGain.cost; Buys = Buys - 1; if (Buys == 0) { doneBuying = true; } } } } else { Console.WriteLine("Invalid Input."); } } else if (buyInput == "n") { doneBuying = true; } else { Console.WriteLine("Invalid Input."); } } TurnComplete = true; }