示例#1
0
        public void Initialize(PlayerObjectContainer p1, PlayerObjectContainer p2)
        {

            if (p1 == null || p2 == null)
            {
                BuildPlayers();
            }
            else
            {

                Player1 = p1;
                Player2 = p2;
            }
            
            ++_gameId;

            Log.Info("Starting");
            GameMessages.Add("Starting match");

            _gameCounter = 0;
            

            return;
        }
示例#2
0
        private bool NextState(PlayerObjectContainer currentPlayer, PlayerObjectContainer otherPlayer)
        {

            #region Handle each cards actions
            for (int pos = 0; pos < PlayerHandClass.NUM_SLOTS; ++pos)
            {
                var slot = currentPlayer.PlayerHand.GetCardsInPlay()[pos];

                if (slot == null)
                    continue;

                Log.DebugFormat("slot #{0} to act {1}.  ", pos + 1, slot.ToString());

                if (slot.IsStunned)
                {
                    GameMessages.Add("Card {0} is stunned, skipping turn", slot.card.Name);
                    currentPlayer.PlayerHand.HandleStunnedCard(pos);
                    continue;
                }

                if (currentPlayer.PlayerName.Equals(PlayerObjectContainer.PLAYER2_USER))
                {
                    bool done = false;

                    while (!done)
                    {
#if SHOW_THREAD_MESSAGES
                        GameMessages.Add("Game Id {0} Waiting for start ActionType before user ActionType (player {1} card {2}) (Slot {3})",
                        _gameId, _selectedPlayer, _selectedCard, pos);
#endif
                        _waitForUserInput.WaitOne();

                        if (CancelToken.IsCancellationRequested)
                        {
                            return false;
                        }

                        bool userDidValidAction = false;

                        if (_selectedPlayer < 0 || _selectedPlayer > 1)
                        {
                            GameMessages.Add("Please select a player");

                            GameMessages.Add(new ActionContainer(ActionType.ILLEGAL_MOVE, 
                                "Please select a player", currentPlayer.PlayerHand[pos], null));
                        }
                        else if (_selectedCard < 0 || _selectedCard > 3)
                        {
                            GameMessages.Add("Please select a card");
                        }                        
                        else
                        {
                            userDidValidAction = slot.card.HandleUserEntryCardAction(slot, 
                            otherPlayer.PlayerHand, _selectedPlayer, _selectedCard);
                        }


                        if (userDidValidAction)
                        {                            
                            done = true;
                        }

#if SHOW_THREAD_MESSAGES
                            GameMessages.Add("Game Id {0} Done with user initiated action (player {1} card {2}) (Slot {3})",
                            _gameId, _selectedPlayer, _selectedCard, pos);
#endif
                        Update?.Invoke(this, new EventArgs());
                    }
                }
                else
                {
#if SHOW_THREAD_MESSAGES
                    GameMessages.Add("Game Id {0} Waiting to start computer ActionType (player {1} card {2}) (Slot {3})",
                            _gameId, _selectedPlayer, _selectedCard, pos);
#endif
                    

                    if (CancelToken.IsCancellationRequested)
                    {
                        GameMessages.Add("Cancel requested");
                        return false;
                    }

                    slot.card.HandleCardAction(slot, otherPlayer.PlayerHand);
#if SHOW_THREAD_MESSAGES
                    GameMessages.Add("Game Id {0} Done with computer ActionType (player {1} card {2}) (Slot {3})",
                            _gameId, _selectedPlayer, _selectedCard, pos);
#endif

                    Update?.Invoke(this, new EventArgs());
                }
                
            }

            #endregion

#if SHOW_THREAD_MESSAGES
            GameMessages.Add("Game Id {0} Waiting to draw card ActionType (player {1} card {2}) )",
                    _gameId, _selectedPlayer, _selectedCard);
#endif
            Update?.Invoke(this, new EventArgs());

            #region Draw a card
            if (currentPlayer.PlayerHand.canAddCard())
            {
                var nextCard = currentPlayer.Deck.GetNextCard();

                if (nextCard == null)
                {
                    if (currentPlayer.PlayerHand.anyCardsLeft() == false)
                    {
                        GameMessages.Add("Death!");
                        GameMessages.Add(new ActionContainer(ActionType.DEATH, "Death for " + currentPlayer.PlayerName, null, null));

                        Update?.Invoke(this, new EventArgs());

                        return false;
                    }
                }
                else
                {
#if SHOW_THREAD_MESSAGES
                    GameMessages.Add("Game Id {0} Waiting for start ActionType before drawing card (player {1} card {2})",
                        _gameId, _selectedPlayer, _selectedCard);
#endif
                    

                    nextCard.HandleCardEntry(currentPlayer.PlayerHand, otherPlayer.PlayerHand, GameMessages, _actionHandler);
                    GameMessages.Add("New card {0}", nextCard.Name);

                    GameMessages.Add(currentPlayer.PlayerName +  " (Current) has " + currentPlayer.Deck.Cards.Sum(x => x.Points) + " points remaining");
#if SHOW_THREAD_MESSAGES
                    GameMessages.Add("Game Id {0} Card drawn, trigger waitHandleAction (player {1} card {2})",
                        _gameId, _selectedPlayer, _selectedCard);
#endif

                    Update?.Invoke(this, new EventArgs());
                }
            }
            #endregion

            //Cull dead guys
            otherPlayer.PlayerHand.cull();

            GameMessages.Add("Culling...");
            GameMessages.Add(otherPlayer.PlayerName +  " (other) has " + otherPlayer.Deck.Cards.Sum(x => x.Points) + " points remaining");

            Update?.Invoke(this, new EventArgs());

            return true;

        }
示例#3
0
        private void BuildPlayers()
        {
            var cards = Container.GetInstance<ICardData>();

            var deck1 = Container.GetInstance<IDeck>();
            var deck2 = Container.GetInstance<IDeck>();

            deck1.Should().NotBeSameAs(deck2);

            bool testing = false;

            if (testing == true)
            {
                deck1.AddCard(CardData.CRAZY_JOE);
                deck1.AddCard(CardData.JANUS_OUTRIGGER);

                deck2.AddCard(CardData.CRAZY_JOE);
                deck1.AddCard(CardData.JANUS_OUTRIGGER);
            }

            if (testing == false)
            {
                BuildDeckOfXPoints(cards, deck1, 500);

                deck2.AddCard(cards.Cards[27]); //Shrouded Minigun (25)
                deck2.AddCard(cards.Cards[30]); //Large Mutant (50)
                deck2.AddCard(cards.Cards[36]); //Giant Mutant (100)
                deck2.AddCard(cards.Cards[38]); //Dropship (130)
                deck2.AddCard(cards.Cards[41]); //Elizabeth (145)
                deck2.AddCard(cards.Cards[43]); //Authority Mutant (160)
                deck2.AddCard(cards.Cards[48]); //Gearhead Jet (180)
                deck2.AddCard(cards.Cards[50]); //Gearhead Boss (205)
                deck2.AddCard(cards.Cards[51]); //Jackal Crossbow (220)
                deck2.AddCard(cards.Cards[53]); //Elite Guard (250)
            }

            deck1.Reset();
            deck2.Reset();



            PlayerObjectContainer p1 = Container.With<IDeck>(deck1).With<string>("Hat dude").GetInstance<PlayerObjectContainer>();

            PlayerObjectContainer p2 = Container.With<IDeck>(deck2).With<string>(PlayerObjectContainer.PLAYER2_USER).GetInstance<PlayerObjectContainer>();

            p1.PlayerHand.PlayerIndex = 0;
            p2.PlayerHand.PlayerIndex = 1;

            Player1 = p1;
            Player2 = p2;
        }