public Card[] Attack(State state) { if (_hand.Cards.Count < 3) { return new Card[0]; } return _hand.Cards.GetRange(0, 3).ToArray<Card>(); }
public Card[] Attack(State state) { DisplayGameState(state); // Allow selecting attack cards var attackers = SelectAttackers(); // Return attack cards return attackers; }
public Defence Defend(State state, Card[] attackingCards) { var d = new Defence(); if (_hand.Cards.Count < 3) { return d; } if (attackingCards.Count<Card>() > 1) { d.Response[attackingCards[0]] = new Card[] { _hand.Cards[0] }; d.Response[attackingCards[1]] = new Card[] { _hand.Cards[1] }; } return d; }
static void Main(string[] args) { var humanHand = new Hand(true); var compHand1 = new Hand(true); //var compHand2 = new Hand(); var human = new HumanPlayer("Gary", humanHand); var comp1 = new ComputerPlayer("Bob", compHand1); //var comp2 = new ComputerPlayer("Jane", compHand2); //var state = new State(comp1, comp2, compHand1, compHand2); var state = new State(human, comp1, humanHand, compHand1); GameManager.Play(state); }
void DisplayGameState(State state) { var header = string.Format("{0} | {1}", state.ActivePlayer.Name, state.OtherPlayer.Name); var life = string.Format("{0} | {1}", state.ActivePlayer.Life, state.OtherPlayer.Life); var padding = state.ActivePlayer.Name.Length - state.ActivePlayer.Life.ToString().Length; var separator = new String('-', header.Length); Console.WriteLine(header); Console.WriteLine(separator); Console.Write(new String(' ', padding)); Console.WriteLine(life); Console.WriteLine(separator); Console.WriteLine(); DisplayCards(_hand.Cards.ToArray(), "Hand:"); }
public static void Play(State state) { // Alternate turns until game over while (!state.GameOver) { // Active player draws a card state.ActiveHand.Cards.Add(RandomCardGenerator.generateCard(1, 4)); // Allow active player to attack var attackCards = state.ActivePlayer.Attack(state); // Allow other player to defend var defence = state.OtherPlayer.Defend(state, attackCards.ToArray<Card>()); // If an attacking card was not blocked, it deals it's damage to the opponent foreach (Card c in attackCards) { if (!defence.Response.Keys.Contains<Card>(c)) { state.OtherPlayer.Life -= c.Attack; } } // Compute battle damage to cards (Taking into account only the first defender) foreach (KeyValuePair<Card, Card[]> entry in defence.Response) { var attackCard = entry.Key; var defenceCard = entry.Value[0]; // If attacking card's Attack >= defending card's Defence, then defending card is destroyed if (attackCard.Attack >= defenceCard.Defence) { state.OtherHand.Cards.Remove(defenceCard); } // If attacking card's Defence <= defending card's Attack, the attacking card is destroyed if (defenceCard.Attack >= attackCard.Defence) { state.ActiveHand.Cards.Remove(attackCard); } } state.EndTurn(); } }
public Defence Defend(State state, Card[] attackingCards) { // Show attackers Console.WriteLine("### YOU'RE UNDER ATTACK!!! ###"); Console.WriteLine(); DisplayCards(attackingCards, "Attackers:"); // Show hand DisplayCards(_hand.Cards.ToArray(), "Hand:"); // Loop over attackers and request defenders for each attacker var defence = new Defence(); foreach (Card c in attackingCards) { Console.WriteLine("Input the Numbers of Defending Cards for [{0}] separated by spaces", c); var defenders = SelectCards(_hand.Cards.ToArray()); defence.Response[c] = defenders; } // Return defenders return defence; }