Inheritance: MonoBehaviour
Esempio n. 1
0
        public void GetThrownCards_FireworkPileWithBlueOneAndDiscardPileWithBlueOne_ReturnsListWith2Elements()
        {
            //// arrange

            // create fake deck that contains blue one cards only
            FakeGameProvider provider = GameProviderFabric.Create(Color.Blue);

            // play blue one card
            var fireworkPile = new FireworkPile(provider);

            fireworkPile.AddCard(new Card(Color.Blue, Rank.One));

            // discard blue one card
            var discardPile = new DiscardPile(provider);

            discardPile.AddCard(new Card(Color.Blue, Rank.One));

            GameProvider gameProvider = new GameProvider();
            var          pileAnalyzer = new PilesAnalyzer(gameProvider);

            //// act
            IReadOnlyList <Card> actual = pileAnalyzer.GetThrownCards(fireworkPile, discardPile);

            Assert.AreEqual(2, actual.Count);
        }
        public void PopulateShownCards()
        {
            if (Deck.Count < 10)
            {
                //Shuffle the discard pile into the deck
                var allCards = DiscardPile;
                allCards.AddRange(Deck.Pop(Deck.Count));

                allCards.Shuffle();

                Deck        = allCards;
                DiscardPile = new List <TrainCard>();
            }

            FlipShownCards();

            var locomotiveCount = ShownCards.Where(x => x.Color == TrainColor.Locomotive).Count();

            while (locomotiveCount >= 3)
            {
                Console.WriteLine("Shown cards has 3 or more locomotives! Burning the shown cards.");

                //Discard the shown cards
                DiscardPile.AddRange(ShownCards);
                ShownCards = new List <TrainCard>();

                //Add a new set of shown cards
                FlipShownCards();
                locomotiveCount = ShownCards.Where(x => x.Color == TrainColor.Locomotive).Count();
            }
        }
Esempio n. 3
0
        public void GetCardsWhateverToPlay_EmptyPiles_ReturnsAllUniqueCards()
        {
            IGameProvider gameProvider =
                GameProviderFabric.Create(new List <Color> {
                Color.White, Color.Red
            });

            var fireworkPile = new FireworkPile(gameProvider);
            var discardPile  = new DiscardPile(gameProvider);

            var pileAnalyzer = new PilesAnalyzer(gameProvider);

            // act
            IReadOnlyList <Card> actual = pileAnalyzer.GetCardsWhateverToPlay(fireworkPile, discardPile);

            // assert
            var actualMatrix = new CardsToMatrixConverter(gameProvider).Encode(actual);

            var expectedMatrix = gameProvider.CreateEmptyMatrix();

            expectedMatrix[Rank.One, Color.White]   = 1;
            expectedMatrix[Rank.One, Color.Red]     = 1;
            expectedMatrix[Rank.Two, Color.White]   = 1;
            expectedMatrix[Rank.Two, Color.Red]     = 1;
            expectedMatrix[Rank.Three, Color.White] = 1;
            expectedMatrix[Rank.Three, Color.Red]   = 1;
            expectedMatrix[Rank.Four, Color.White]  = 1;
            expectedMatrix[Rank.Four, Color.Red]    = 1;
            expectedMatrix[Rank.Five, Color.White]  = 1;
            expectedMatrix[Rank.Five, Color.Red]    = 1;

            TestHelper.AreMatrixEqual(expectedMatrix, actualMatrix, gameProvider);
        }
Esempio n. 4
0
 private void Start()
 {
     attackDiscardPile   = new DiscardPile();
     locationDiscardPile = new DiscardPile();
     attackDeck          = new Deck(Defines.attackDeckSize);
     locationDeck        = new Deck(Defines.locationDeckSize);
 }
Esempio n. 5
0
        public void WhenThereAreTwoPlayersInAGameAndBothPlayersDrawACard_TheFirstPlayerHasTheirTurnAgain()
        {
            var game         = Game.New();
            var firstPlayer  = game.Join("Player1");
            var secondPlayer = game.Join("Player2");

            game.Start();

            var drawPile = new Deck();

            drawPile.Push(new Number(1, CardColour.Red));
            drawPile.Push(new Number(2, CardColour.Red));
            drawPile.Push(new Number(3, CardColour.Red));
            drawPile.Push(new Number(4, CardColour.Red));
            ((Game)game).DrawPile = drawPile;

            var discardPile = new DiscardPile();

            discardPile.Push(new Number(5, CardColour.Red));
            ((Game)game).DiscardPile = discardPile;

            ((Game)game).SetupDeckEvents();

            game.PlayCard(firstPlayer, game.DrawCard(firstPlayer));
            game.PlayCard(secondPlayer, game.DrawCard(secondPlayer));

            var currentPlayer = game.GetPlayerTurn();

            Assert.AreEqual(firstPlayer.ID, currentPlayer.ID);
        }
    /// <summary>
    /// If in hand, allows discarding instead of forgetting.
    /// </summary>
    public override void Forget(PowerCard card)
    {
        // (Source-1) Purchased / Active
        if (InPlay.Contains(card))
        {
            foreach (var el in card.Elements)
            {
                Elements[el.Key] -= el.Value;                                       // lose elements from forgotten card
            }
            InPlay.Remove(card);
            DiscardPile.Add(card);
            return;
        }

        if (Hand.Contains(card))
        {
            Hand.Remove(card);
            DiscardPile.Add(card);
            return;
        }

        if (DiscardPile.Contains(card))
        {
            base.Forget(card);
            return;
        }

        throw new System.Exception("Can't find card to forget:" + card.Name);
    }
Esempio n. 7
0
        public virtual void OnPlay()
        {
            string      discardPileName = this.ToRow.name.Contains("Enemy") ? "EnemyDiscardPile" : "PlayerDiscardPile";
            DiscardPile dp = GameObject.Find(discardPileName).GetComponent <DiscardPile>();

            dp.AddToDiscardPile(this);
        }
Esempio n. 8
0
        public void GetThrownCards_FireworkPileWithBlueOneAndDiscardPileWithBlueOne_ReturnsListWithBlueOnesOnly()
        {
            //// arrange

            FakeGameProvider gameProvider =
                GameProviderFabric.Create(new List <Color> {
                Color.Blue, Color.Red
            }.AsReadOnly());

            // play blue one card
            var fireworkPile = new FireworkPile(gameProvider);

            fireworkPile.AddCard(new Card(Color.Blue, Rank.One));

            // discard blue one card
            var discardPile = new DiscardPile(gameProvider);

            discardPile.AddCard(new Card(Color.Blue, Rank.One));

            var pileAnalyzer = new PilesAnalyzer(gameProvider);

            //// act
            IReadOnlyList <Card> actual = pileAnalyzer.GetThrownCards(fireworkPile, discardPile);

            Assert.IsTrue(actual.Count > 0 &&
                          actual.All(card => Equals(card, new Card(Color.Blue, Rank.One))));
        }
Esempio n. 9
0
 public void Clear()
 {
     Hand.Clear();
     DrawPile.Clear();
     DiscardPile.Clear();
     RemovePile.Clear();
 }
Esempio n. 10
0
    void drawHand()
    {
        hand = new List <Card>();

        for (int i = 0; i < HandSize; i++)
        {
            if (DrawPile.Count == 0)
            {
                DrawPile.List.AddRange(DiscardPile);
                DrawPile.List.ShuffleInPlace();
                DiscardPile.Clear();

                if (DrawPile.Count != Deck.Count)
                {
                    // we should be able to continue playing if this happens, but I absolutely want to know about it
                    Debug.LogError($"you lost {Deck.Count - DrawPile.Count} cards somewhere");
                }
            }

            var drawIndex = DrawPile.Count - 1;

            hand.Add(DrawPile[drawIndex]);
            DrawPile.RemoveAt(drawIndex);
        }
    }
Esempio n. 11
0
    public CardPosition PurgeCardFromDeck(string id)
    {
        if (!TotalDeckList.Where(i => i.Id == id).Any())
        {
            throw new Exception("Could not find card with ID of " + id);
        }
        var card = TotalDeckList.Where(i => i.Id == id).Single();

        if (DrawPile.Contains(card))
        {
            DrawPile.Remove(card);
            return(CardPosition.DRAW);
        }
        if (DiscardPile.Contains(card))
        {
            DiscardPile.Remove(card);
            return(CardPosition.DISCARD);
        }
        if (Hand.Contains(card))
        {
            Hand.Remove(card);
            return(CardPosition.HAND);
        }
        throw new Exception("This should be impossible");
    }
Esempio n. 12
0
        public void ProcessCardPlays()
        {
            foreach (Player player in players)
            {
                switch (player.play_mode)
                {
                case "Play":
                {
                    player.board.Add(player.picked_card);
                    player.current_booster.Remove(player.picked_card);
                    // etb
                    var etb = player.picked_card.ETB;
                    player.Gold += Calculate(player, etb);
                    // !!!

                    GameCommand command = new GameCommand("Board", String.Join(",", player.board.Select(x => x.Id)));
                    IssueCommand(command, player);

                    GameCommand game_command = new GameCommand("CurrentGold", player.Gold.ToString());
                    gameinterface.Send(player, game_command);

                    // !!!
                    // Если строкового боди нет, его надо скрыть в наследниках
                    game_command = new GameCommand("GameState", "");
                    // индексатор по объекту сразу?
                    game_command.Data["Gold"] = player.Gold;
                    gameinterface.Send(player, game_command);
                    //

                    break;
                }

                case "Wonder":
                {
                    player.current_booster.Remove(player.picked_card);
                    player.wonder.CurrentTier++;
                    var etb = player.wonder.Tiers[player.wonder.CurrentTier - 1].ETB;
                    player.Gold += Calculate(player, etb);
                    GameCommand game_command = new GameCommand("CurrentGold", player.Gold.ToString());
                    gameinterface.Send(player, game_command);
                    game_command = new GameCommand("NewTier", "");
                    gameinterface.Send(player, game_command);
                    break;
                }

                case "Sell":
                {
                    DiscardPile.Add(player.picked_card);
                    player.current_booster.Remove(player.picked_card);
                    // а здесь уже можно обнулить picked_card, но ресет пока отдельно
                    player.Gold += 3;
                    // Стейт надо научиться передавать более подробно
                    GameCommand game_command = new GameCommand("CurrentGold", player.Gold.ToString());
                    gameinterface.Send(player, game_command);
                    break;
                }
                }
            }
            // заглушка
        }
Esempio n. 13
0
 protected virtual void Start()
 {
     this.discardPile = ((DiscardPile[])FindObjectsOfType(typeof(DiscardPile))).Where(d =>
                                                                                      d.player == this.player
                                                                                      ).First();
     gwn = (GwentNetworkManager)FindObjectOfType(typeof(GwentNetworkManager));
 }
Esempio n. 14
0
        public void TestDiscard_Success()
        {
            DiscardPile discardPile = new DiscardPile();
            Card        card        = new Card(new CardIdType(0), new CardIndexType(0), CardColorType.Blue, CardValueType.Value1);

            Debug.Assert(discardPile.Discard(card));
        }
Esempio n. 15
0
        public static void MoveEntireDeckToDiscardPile(ref Game game)
        {
            Deck        theDeck     = game.Deck;
            List <Card> cardsInDeck = typeof(Deck).GetField("Cards",
                                                            BindingFlags.NonPublic | BindingFlags.Instance)
                                      .GetValue(theDeck) as List <Card>;

            DiscardPile discardPile             = game.DiscardPile;
            FieldInfo   cardsinDiscardFieldInfo = typeof(DiscardPile).GetField("Cards",
                                                                               BindingFlags.NonPublic | BindingFlags.Instance);
            List <Card> cardsInDiscard = cardsinDiscardFieldInfo.GetValue(discardPile) as List <Card>;

            cardsInDiscard.AddRange(cardsInDeck);
            cardsinDiscardFieldInfo.SetValue(discardPile, cardsInDiscard);
            PropertyInfo discardInfo = typeof(Game).GetProperty("DiscardPile");

            discardInfo.SetValue(game, discardPile);

            FieldInfo cardsinDeckFieldInfo = typeof(Deck).GetField("Cards",
                                                                   BindingFlags.NonPublic | BindingFlags.Instance);

            cardsinDeckFieldInfo.SetValue(theDeck, new List <Card>());
            PropertyInfo deckPropInfo = typeof(Game).GetProperty("Deck");

            deckPropInfo.SetValue(game, theDeck);
        }
Esempio n. 16
0
    void Awake()
    {
        _currentDeck        = Root.GetComponentFromRoot <Deck>();
        _currentDiscardPile = Root.GetComponentFromRoot <DiscardPile>();

        _testslot = GameObject.FindGameObjectsWithTag("CardSlot").ToList();
    }
Esempio n. 17
0
 public void AddNewCardToDiscardPile(AbstractCard card)
 {
     if (TotalDeckList.Any(item => item.Id == card.Id))
     {
         throw new Exception("Attempted to add duplicate card to deck: " + card.Name);
     }
     DiscardPile.Add(card);
 }
Esempio n. 18
0
 internal void CardPlayCleanup()
 {
     if (PutIntoDiscardAfterApplyingEffectSet != null)
     {
         DiscardPile.Add(PutIntoDiscardAfterApplyingEffectSet);
         PutIntoDiscardAfterApplyingEffectSet = null;
     }
 }
Esempio n. 19
0
        public void SetUp()
        {
            var discardPile = new DiscardPile();
            var deck        = new Deck(7.Coppers(), 3.Estates());

            _eventAggregator = new MockEventAggregator();
            player           = new Player(deck, discardPile, new NaivePlayerController());
        }
Esempio n. 20
0
 public void DiscardInto(DiscardPile discardPile, IActionScope turnScope)
 {
     this.ToList().ForEach(card =>
     {
         Remove(card);
         discardPile.Discard(card, turnScope);
     });
 }
Esempio n. 21
0
    public void DiscardCard(int index)
    {
        Card        playedOne = cards[index];
        DiscardPile dp        = MainManager.instance.GetDiscardPile();

        dp.AddCard(playedOne);
        cards.RemoveAt(index);
    }
Esempio n. 22
0
        public void When_discarded_card_set_should_be_empty()
        {
            var cards   = new CardSet(Treasure.Copper, Treasure.Gold, Treasure.Silver, Victory.Estate);
            var discard = new DiscardPile();

            cards.DiscardInto(discard, new MockTurnScope());
            cards.ShouldBeEmpty();
        }
Esempio n. 23
0
    private void SetupDiscardPile(GameObject discardPilePrefab)
    {
        Vector3 discardPlacement = MegaManager.Table.DiscardPlacement.position;

        DiscardPile = (MonoBehaviour.Instantiate(discardPilePrefab, discardPlacement, Quaternion.identity) as GameObject).GetComponent <DiscardPile>();
        DiscardPile.SetOwner(this);
        DiscardPileTranform = DiscardPile.transform;
    }
Esempio n. 24
0
        // Move a card from Hand to Discard
        public void Discard(int idxOfCardToDiscard)
        {
            //remove selected card from hand & append to discard
            Card cardToDiscard = Hand[idxOfCardToDiscard];

            Hand.RemoveAt(idxOfCardToDiscard);
            DiscardPile.Add(cardToDiscard);
        }
Esempio n. 25
0
 void Start()
 {
     owner       = GetComponent <Unit>();
     handManager = HandManager.instance;
     discardPile = DiscardPile.instance;
     turnManager = TurnManager.instance;
     Shuffle();
 }
Esempio n. 26
0
        public Game GetNewGame(List <Player> players)
        {
            Deck        deck        = new Deck();
            DiscardPile discardPile = new DiscardPile();
            Game        game        = new Game(players, deck, discardPile);

            return(game);
        }
Esempio n. 27
0
        public override void AnimateRemoveCardsToDiscardPile(DiscardPile discard, float delay)
        {
            foreach (var cardInHand in _myHand.CardsInHand)
            {
                discard.AnimateRemoveCardToDiscardPile(cardInHand, delay);
            }

            _myHand.CardsInHand.Clear();
        }
Esempio n. 28
0
 /// <summary>
 /// How to handle rehydration from being serialized.
 /// </summary>
 public override void Rehydrated()
 {
     base.Rehydrated();
     DrawPile.Apply(c => c.Options           = CardOptions);
     DiscardPile.Apply(c => c.Options        = CardOptions);
     Table.Apply(c => c.Options              = CardOptions);
     Tableau.Apply(c => c.Options            = CardOptions);
     Hands.Apply(h => h.Apply(c => c.Options = CardOptions));
 }
Esempio n. 29
0
        public void TestDiscard_Fail()
        {
            DiscardPile discardPile = new DiscardPile();
            Card        card1       = new Card(new CardIdType(0), new CardIndexType(0), CardColorType.Blue, CardValueType.Value1);
            Card        card2       = new Card(new CardIdType(0), new CardIndexType(0), CardColorType.Blue, CardValueType.Value1);

            Debug.Assert(discardPile.Discard(card1));
            Debug.Assert(!discardPile.Discard(card2));
        }
Esempio n. 30
0
 public void Shuffle()
 {
     DrawPile = DrawPile.Concat(DiscardPile).ToObservableCollection <Card>();
     DiscardPile.Clear();
     DrawPile = DrawPile.Concat(BurnPile).ToObservableCollection <Card>();
     BurnPile.Clear();
     DrawPile = Shuffler.Shuffle(DrawPile, rnd).ToObservableCollection <Card>();
     OnPropertyChanged(nameof(CardsRemaining));
 }
Esempio n. 31
0
 public void DiscardPileConstructorTest1()
 {
     DiscardPile target = new DiscardPile();
     Assert.IsInstanceOfType(target, typeof(DiscardPile));
 }
Esempio n. 32
0
        public void WhenThereAreTwoPlayersInAGameAndBothPlayersDrawACard_TheFirstPlayerHasTheirTurnAgain()
        {
            var game = Game.New();
            var firstPlayer = game.Join("Player1");
            var secondPlayer = game.Join("Player2");
            game.Start();

            var drawPile = new Deck();
            drawPile.Push(new Number(1, CardColour.Red));
            drawPile.Push(new Number(2, CardColour.Red));
            drawPile.Push(new Number(3, CardColour.Red));
            drawPile.Push(new Number(4, CardColour.Red));
            ((Game)game).DrawPile = drawPile;

            var discardPile = new DiscardPile();
            discardPile.Push(new Number(5, CardColour.Red));
            ((Game)game).DiscardPile = discardPile;

            ((Game)game).SetupDeckEvents();

            game.PlayCard(firstPlayer, game.DrawCard(firstPlayer));
            game.PlayCard(secondPlayer, game.DrawCard(secondPlayer));

            var currentPlayer = game.GetPlayerTurn();

            Assert.AreEqual(firstPlayer.ID, currentPlayer.ID);
        }
Esempio n. 33
0
 private void Initialise(string characterCardFile, string eventCardFile)
 {
     _characterCardDeck = new Deck<CharacterCard>(ReadCharactersFromTxtFile(characterCardFile));
     _eventCardDeck = new Deck<EventCard>(ReadEventsFromTxtFile(eventCardFile));
     _discardPile = new DiscardPile();
 }