public void GainCard(Card card, Deck deck, Deck.State state = 0) { if (state == 0 || state == Deck.State.discardPile) { discardPile.Cards.Add(card); } else if (state == Deck.State.inHand) { inHand.Cards.Add(card); } else if (state == Deck.State.drawPile) { drawPile.Cards.Insert(0, card); } deck.Cards.Remove(card); }
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); }
public void GainCardByName(string cardName, bool optional, Kingdom myKingdom, Deck.State state = Deck.State.discardPile) { foreach (Deck deck in myKingdom.KingdomSupply) { if (deck.Cards.Count > 0) { if (deck.Cards[0].name == cardName) { Card cardToGain = deck.Cards[deck.Cards.Count - 1]; GainCard(cardToGain, deck, state); return; } } } Console.WriteLine("\r\nNo " + cardName + " available.\r\n"); }