Exemple #1
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                var swindledCard = victim.Deck.TopCard;
                if(swindledCard == null)
                {
                    context.Game.Log.LogMessage("{0} did not have any cards to be swindled.", victim.Name);
                    return;
                }
                
                context.Trash(victim, swindledCard);
                var candidates = context.Game.Bank.Piles.Where(p => p.IsEmpty == false && p.TopCard.Cost == swindledCard.Cost);                

                if(candidates.Count() == 0)
                {
                    context.Game.Log.LogMessage("There are no cards of cost {0}.", swindledCard.Cost);
                }
                else if (candidates.Count() == 1)
                {
                    var pile = candidates.Single();
                    var card = pile.TopCard;
                    card.MoveTo(victim.Discards);
                    context.Game.Log.LogGain(victim, card);
                }
                else
                {
                    var activity = Activities.SelectACardForOpponentToGain(context, context.ActivePlayer, victim, swindledCard.Cost, source);
                    _activities.Add(activity);    
                }
            }
Exemple #2
0
        public Player PlayerToLeftOf(Player player)
        {
            if (player == _players.Last())
                return _players.First();

            return _players.SkipWhile(p => p != player).Skip(1).First();
        }
Exemple #3
0
        public GameViewModel(Game game, Player player)
        {
            Log = game.Log.Contents;

            Version = game.Version;
            
            PopulateActivityRelated(game, player);

            Bank = game.Bank.Piles
                .Select(p => new CardPileViewModel(p, game.CurrentTurn, player)).ToArray();

            Hand = player.Hand
                .Select(c => new CardViewModel(c, game.CurrentTurn, player)).ToArray();

            if (game.IsComplete)
            {
                InPlay = player.PlayArea
                    .Select(c => new CardViewModel(c)).ToArray();
            }
            else
            {
                InPlay = game.ActivePlayer.PlayArea
                    .Select(c => new CardViewModel(c)).ToArray();
            }

            Status = new TurnContextViewModel(game.CurrentTurn, player);

            Deck = new DeckViewModel(player.Deck);

            Discards = new DiscardPileViewModel(player.Discards);
        }
Exemple #4
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                var victoryTypes = victim.Hand.OfType<IVictoryCard>()
                    .WithDistinctTypes()
                    .ToList();

                if(victoryTypes.Count() > 1)
                {
                    var activity = Activities.PutCardOfTypeFromHandOnTopOfDeck(context.Game.Log, victim,
                                                                               "Select a victory card to put on top",
                                                                               typeof (IVictoryCard),
                                                                               source);
                   _activities.Add(activity);
                }
                else if(victoryTypes.Any())
                {
                    var card = victoryTypes.Single();
                    victim.Deck.MoveToTop(card);
                    context.Game.Log.LogMessage("{0} put a {1} on top of the deck.", victim.Name, card.Name);
                }
                else
                {
                    context.Game.Log.LogRevealHand(victim);
                }
            }
Exemple #5
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                if (victim.Deck.CardCount + victim.Discards.CardCount > 0)
                    victim.Deck.MoveTop(1, victim.Discards);

                var gainUtil = new GainUtility(context, victim);
                gainUtil.Gain<Curse>(c => victim.Deck.MoveToTop(c));
            }
Exemple #6
0
 public IEnumerable<TurnContext> GameTurns()
 {
     foreach (var player in TurnLoop)
     {           
         _activePlayer = player;
         yield return player.BeginTurn(this);
     }                
 }
Exemple #7
0
 public override void Attack(Player victim, TurnContext context, ICard source)
 {
     if (victim.Hand.CardCount > 4)
     {
         context.DiscardCards(victim, victim.Hand);
         victim.DrawCards(4);
     }
 }
Exemple #8
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                int cardsToPutBack = victim.Hand.CardCount - 3;

                var activities = Activities.PutMultipleCardsFromHandOnTopOfDeck(context.Game.Log, victim, cardsToPutBack, source);
                foreach(var activity in activities)
                    _activities.Add(activity);
            }
Exemple #9
0
            public override void Attack(Player player, TurnContext context, ICard source)
            {
                if (player.Deck.CardCount + player.Discards.CardCount > 0)
                    player.Deck.MoveTop(1, player.Discards);

                var gainUtil = new GainUtility(context, player);
                gainUtil.Gain<Curse>(c => player.Deck.MoveToTop(c));
            }
Exemple #10
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                var copper = victim.Hand.FirstOrDefault(c => c is Copper);

                if (copper != null)
                    context.DiscardCard(victim, copper);
                else
                    context.Game.Log.LogRevealHand(victim);
            }
Exemple #11
0
            public override void Attack(Player player, TurnContext context)
            {
                var revealZone = new RevealZone(player);
                player.Deck.MoveTop(3, revealZone);

                revealZone.LogReveal(context.Game.Log);
                revealZone.MoveWhere(c => c is IActionCard || c is ITreasureCard, player.Discards);

                foreach (var activity in Activities.SelectMultipleRevealedCardsToPutOnTopOfDeck(context.Game.Log, player, revealZone))
                    _activities.Add(activity);
            }
Exemple #12
0
        public TurnContext(Player player, Game game)
        {
            ActivePlayer = player;
            Game = game;
            AvailableSpend = 0;
            RemainingActions = 1;
            Buys = 1;

            foreach (var longLivedEffect in player.LongLivedEffects)
                longLivedEffect.OnTurnStarting(this);
        }
Exemple #13
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                var numberToDiscard = victim.Hand.CardCount - 3;

                if (numberToDiscard > 0)
                    _activities.Add(Activities.DiscardCards(context, victim, numberToDiscard, source));
                else
                {
                    context.Game.Log.LogMessage("{0} did not have to discard any cards.", victim.Name);
                }
            }            
Exemple #14
0
            public override void Attack(Player player, TurnContext context)
            {
                var numberToDiscard = player.Hand.CardCount - 3;

                if (numberToDiscard > 0)
                    _activities.Add(Activities.DiscardCards(context, player, numberToDiscard));
                else
                {
                    context.Game.Log.LogMessage("{0} did not have to discard any cards.", player.Name);
                }
            }            
Exemple #15
0
        public virtual IActivity GetActivity(Player player)
        {
            var activity = _activities.FirstOrDefault(a => a.Player == player && !a.IsSatisfied);
            if (activity != null)
                return activity;

            if (_activities.Any())
                return new WaitingForPlayersActivity(player);

            return null;
        }
Exemple #16
0
        private void PopulateActivityRelated(Game game, Player player)
        {
            var activity = game.GetPendingActivity(player);
            if(activity != null)
                PendingActivity = new ActivityModel(activity);

            if (activity is IRevealedCardsActivity)
            {
                this.Revealed = ((IRevealedCardsActivity)activity).RevealedCards
                    .Select(c => new CardViewModel(c)).ToArray();
            }
        }
Exemple #17
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                var revealZone = new RevealZone(victim);
                victim.Deck.MoveTop(3, revealZone);

                revealZone.LogReveal(context.Game.Log);
                revealZone.MoveWhere(c => c is IActionCard || c is ITreasureCard, victim.Discards);

                if(revealZone.CardCount == 1)
                    victim.Deck.MoveToTop(revealZone.Single());

                foreach (var activity in Activities.SelectMultipleRevealedCardsToPutOnTopOfDeck(context.Game.Log, victim, revealZone, source))
                    _activities.Add(activity);
            }
Exemple #18
0
            private IActivity CreateChooseCardActivity(TurnContext context, RevealZone revealZone, Player player, ICard source)
            {
                var selectTreasure = new SelectFromRevealedCardsActivity(context.Game.Log, player, revealZone,
                    string.Format("Select the card you do NOT want {0} to draw.", revealZone.Owner.Name), SelectionSpecifications.SelectExactlyXCards(1), source);

                selectTreasure.AfterCardsSelected = cards =>
                {
                    var discardingCard = cards.Single();
                    discardingCard.MoveTo(context.ActivePlayer.Discards);
                    revealZone.MoveAll(context.ActivePlayer.Hand);
                };

                return selectTreasure;
            }           
Exemple #19
0
 private ISelectCardsActivity CreatePassCardsActivity(TurnContext context, Player player, ICard source, Player tempPlayer)
 {
     return new SelectCardsActivity
         (context.Game.Log, player, "Select a card to pass.", SelectionSpecifications.SelectExactlyXCards(1), source)
     {
         AfterCardsSelected = cards =>
         {
             _cardMovements[cards.Single()] = context.Game.PlayerToLeftOf(tempPlayer).Hand;
             if (_cardMovements.Keys.Count == _expectedMovementCount)
             {
                 DoMovements();
                 DoTrash(context, source);
             }
         },
         Hint = ActivityHint.PassCards
     };
 }
Exemple #20
0
            public override void Attack(Player player, TurnContext context)
            {
                var curseInHand = player.Hand.OfType<Curse>().FirstOrDefault();

                if(curseInHand == null)
                {
                    GainCopperAndCurse(player, context);
                }
                else
                {
                    var activity = Activities.ChooseYesOrNo(context.Game.Log, player, "Discard a curse?",
                        () => context.DiscardCard(player, curseInHand),
                        () => GainCopperAndCurse(player, context));                  

                    _activities.Add(activity);
                    
                }
            }
Exemple #21
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {
                Action discardCards;

                if (victim.Hand.CardCount > 2)
                    discardCards = () => _activities.Add(Activities.DiscardCards(context, victim, 2, source));
                else if(victim.Hand.CardCount > 0)
                    discardCards = () => context.DiscardCards(victim, victim.Hand);
                else
                    discardCards = () => context.Game.Log.LogMessage("{0} had no cards to discard.", victim.Name);
   
                Action gainCurse = () => new GainUtility(context, victim).Gain<Curse>(victim.Hand);

                var decideActivity = Activities.ChooseYesOrNo(context.Game.Log, victim, "Discard two cards to Torturer?",
                                                              source, discardCards, gainCurse);

                _activities.Add(decideActivity);
            }
Exemple #22
0
            public override void Attack(Player victim, TurnContext context, ICard source)
            {                
                var revealZone = new RevealZone(victim);
                victim.Deck.MoveTop(2, revealZone);
                revealZone.LogReveal(context.Game.Log);                

                var revealedTreasures = revealZone.OfType<ITreasureCard>().WithDistinctTypes();

                switch(revealedTreasures.Count())
                {
                    case 0:
                        revealZone.MoveAll(victim.Discards);
                        return;
                    case 1:
                        var trashedCard = TrashAndDiscard(context, revealZone, revealedTreasures);
                        var gainChoiceActivity = Activities.GainOpponentsCardChoice(context, trashedCard, revealZone.Owner, source);
                        _activities.Add(gainChoiceActivity);
                        break;
                    default:
                        var chooseTreasureActivity = CreateChooseTreasureActivity(context, revealZone, source);
                        _activities.Add(chooseTreasureActivity);
                        break;
                }
            }
Exemple #23
0
 public void LogRevealHand(Player player)
 {
     _builder.AppendFormat("{0} has the following cards in hand: {1}", player.Name, player.Hand);
     _builder.AppendLine();
 }
Exemple #24
0
 public void LogTrash(Player player, ICard card)
 {
     _builder.AppendFormat("{0} trashed a {1}.", player.Name, card.Name);
     _builder.AppendLine();
 }
Exemple #25
0
        public void LogGain(Player player, ICard card)
        {
            _builder.AppendFormat("{0} gained a {1}", player.Name, card.Name);
            _builder.AppendLine();

        }
Exemple #26
0
 public void LogDiscard(Player player, ICard card)
 {
     _builder.AppendFormat("{0} discarded a {1}.", player.Name, card.Name);
     _builder.AppendLine();
 }
Exemple #27
0
 public void LogBuy(Player player, CardPile pile)
 {
     _builder.AppendFormat("{0} bought a {1}.", player.Name, pile.Name);
     _builder.AppendLine();
 }
Exemple #28
0
 public void LogPlay(Player player, IActionCard card)
 {
     _builder.AppendFormat("{0} played a {1}.", player.Name, card.Name);
     _builder.AppendLine();
 }
Exemple #29
0
 public void LogTurn(Player player)
 {
     _builder.AppendFormat("{0}'s turn has begun.", player.Name);
     _builder.AppendLine();
 }
Exemple #30
0
 public override void Attack(Player player, TurnContext context, ICard source)
 {
     var gainUtil = new GainUtility(context, player);                
     gainUtil.Gain<Curse>();       
 }