public bool DoOneTurn() { int drawCount = CurrentTurn == 0 ? 3 : 5; // Set up the turn GameState state = new GameState(); var hand = CurrentPlayer.Draw(drawCount); // Play the turn while(hand.Count > 0) { var card = hand[0]; hand.RemoveAt(0); state.Tableau.Add(card); // Handle the card. InterpretCard(card, state); } // Resolve the turn CurrentPlayer.DiscardPile.AddRange(state.Tableau); Opponent.Authority -= state.Attack; if(Opponent.Authority <= 0) { Winner = CurrentPlayer; return true; } ++CurrentTurn; return false; }
void InterpretCard(Card card, GameState state) { InterpretAction(card.MainAction, state); if(state.Tableau.Concat(CurrentPlayer.Bases).Where(x => (x.Faction & card.Faction) != 0).Count() > 0) { InterpretAction(card.AllyAction, state); } }
void InterpretAction(GameAction action, GameState state) { if (action is MoneyAction) { state.Money += (action as MoneyAction).Money; } else if (action is AttackAction) { state.Attack += (action as AttackAction).Attack; } else { throw new NotImplementedException(action.FriendlyName); } }