public void PlaceCardActionTest_GameAddition()
        {
            Random random = new Random();
            int targetPile = random.Next(0, 4);

            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            target = target.DrawCard();
            ActionResult result = target + PlaceCardAction.Action(targetPile);
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            Assert.IsNotNull(result.Game);
            Assert.IsInstanceOfType(result.Data, typeof(CardCollection));
            Assert.AreSame(result.Data, result.Game.Piles[targetPile]);
            Assert.IsTrue(result.Success);

            Assert.IsNotNull(target.VisibleCard);
            Assert.IsNull(result.Game.VisibleCard);
            Assert.AreNotEqual<int>(target.Piles[targetPile].Count, result.Game.Piles[targetPile].Count);
            Assert.AreNotEqual<int>(target.CurrentPlayerIndex, result.Game.CurrentPlayerIndex);
        }
        public void InvalidPlaceCardActionTest_GameAddition()
        {
            Random random = new Random();
            int targetPile = random.Next(0, 4);

            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(targetPile)).Game;
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(targetPile)).Game;
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(targetPile)).Game;
            Assert.AreEqual<int>(3, target.Piles[targetPile].Count);

            target = target.DrawCard();
            ActionResult result = target + PlaceCardAction.Action(targetPile);
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            Assert.IsNotNull(result.Game);
            Assert.AreSame(target, result.Game);
            Assert.IsFalse(result.Success);
            Assert.IsInstanceOfType(result.Data, typeof(Exception));
        }
示例#3
0
 /// <summary>
 /// Create an action result.
 /// </summary>
 /// <param name="action"></param>
 /// <param name="game"></param>
 /// <param name="data"></param>
 /// <param name="success"></param>
 internal ActionResult(string action, ColorettoGame game, Profile player, object data, bool success)
 {
     this.Action = action;
     this.Game = game;
     this.Data = data;
     this.Player = player;
     this.Success = success;
 }
示例#4
0
        public void Game_AvailableActions1()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            Assert.AreEqual<GameActions>(GameActions.Draw, target.AvailableActions);
        }
示例#5
0
        public void Game_AvaliableActions2()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(2);

            Assert.AreEqual<GameActions>(GameActions.DrawOrPickupPile, target.AvailableActions);
        }
        public void DrawCardActionTest_GameAddition()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            ActionResult result = target + DrawCardAction.DefaultAction;
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            Assert.IsNotNull(result.Game);
            Assert.IsTrue(result.Success);
            Assert.AreSame(result.Game.VisibleCard, result.Data);
            Assert.AreEqual<int>(target.CurrentPlayerIndex, result.Game.CurrentPlayerIndex);
        }
        public void InvalidPickupPileActionTest_GameAddition()
        {
            Random random = new Random();
            int targetPile = random.Next(0, 4);

            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            ActionResult result = target + PickupPileAction.Action(targetPile);
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            Assert.IsNotNull(result.Game);
            Assert.AreSame(target, result.Game);
            Assert.IsFalse(result.Success);
            Assert.IsInstanceOfType(result.Data, typeof(Exception));
        }
        public void PickupPileActionTest_GameAddition()
        {
            Random random = new Random();
            int targetPile = random.Next(0, 4);

            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(targetPile)).Game;
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(targetPile)).Game;
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(targetPile)).Game;
            Assert.AreEqual<int>(3, target.PreviousActions.Count);
            Assert.AreEqual<Type>(typeof(PlaceCardAction), target.PreviousActions[0].Actions[0].GetType());
            Assert.AreEqual<Type>(typeof(PlaceCardAction), target.PreviousActions[1].Actions[0].GetType());
            Assert.AreEqual<Type>(typeof(PlaceCardAction), target.PreviousActions[2].Actions[0].GetType());
            Assert.AreEqual<int>(3, target.Piles[targetPile].Count);

            ActionResult result = target + PickupPileAction.Action(targetPile);
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            Assert.IsNotNull(result.Game);
            Assert.AreSame(result.Data, result.Game.Hands[target.CurrentPlayerIndex]);
            Assert.IsInstanceOfType(result.Data, typeof(CardCollection));
            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Game.Piles[targetPile]);

            foreach (var card in target.Piles[targetPile])
            {
                Assert.IsTrue(result.Game.Hands[target.CurrentPlayerIndex].Contains(card));
            }
        }
示例#9
0
        public void Game_PreviousActionsTest()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();

            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(0)).Game;
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(1)).Game;
            target = target.DrawCard();
            target = (target + PlaceCardAction.Action(2)).Game;

            Assert.AreEqual<int>(3, target.PreviousActions.Count);
        }
示例#10
0
        public void Game_PlaceCardOnPileTest()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            target = target.PlaceCardOnPile(0);
            target = target.PlaceCardOnPile(0);
            target = target.PlaceCardOnPile(0);
            target = target.PlaceCardOnPile(0);
        }
示例#11
0
        public void Game_PickupPileTest()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            target = target.DrawCard();
            target = target.PlaceCardOnPile(0);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(0);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(0);

            int numberOfPlayersWithNonZeroScore = target.Hands.Where(cc => cc.Score > 0).Count();
            Assert.IsTrue(numberOfPlayersWithNonZeroScore == 0, "Somehow someone started with a non-zero score.");

            target = target.PickupPile(0);

            CardCollection nullPileBecauseItWasPickedUp = target.Piles.First();
            Assert.IsNull(nullPileBecauseItWasPickedUp);

            numberOfPlayersWithNonZeroScore = target.Hands.Where(cc => cc.Score > 0).Count();
            Assert.IsTrue(numberOfPlayersWithNonZeroScore > 0, "Someone picked up a pile but nobody has a non-zero score");
        }
示例#12
0
        public void Game_FullRound()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            // Loop through 5 times.
            // There are 76 cards. The last cycle card should be the 61st.
            // Each cycle, which is in this for loop, uses 12 cards.
            // 12 * 5 = 60 cards. So, the next cycle will be in the 6th loop
            for (int i = 0; i < 6; i++)
            {
                if (i == 5)
                {
                    Assert.AreEqual<int>(1, target.Round);
                }

                target = target.DrawCard();
                target = target.PlaceCardOnPile(0);
                target = target.DrawCard();
                target = target.PlaceCardOnPile(0);

                if (i == 5)
                {
                    Assert.AreEqual<int>(1, target.Round);
                    Assert.IsTrue(target.IsLastCycleForRound);
                }

                target = target.DrawCard();
                target = target.PlaceCardOnPile(0);

                target = target.DrawCard();
                target = target.PlaceCardOnPile(1);
                target = target.DrawCard();
                target = target.PlaceCardOnPile(1);
                target = target.DrawCard();
                target = target.PlaceCardOnPile(1);

                target = target.DrawCard();
                target = target.PlaceCardOnPile(2);
                target = target.DrawCard();
                target = target.PlaceCardOnPile(2);
                target = target.DrawCard();
                target = target.PlaceCardOnPile(2);

                target = target.DrawCard();
                target = target.PlaceCardOnPile(3);
                target = target.DrawCard();
                target = target.PlaceCardOnPile(3);
                target = target.DrawCard();
                target = target.PlaceCardOnPile(3);

                target = target.PickupPile(0);
                target = target.PickupPile(1);
                target = target.PickupPile(2);
                target = target.PickupPile(3);

                if (i == 5)
                {
                    Assert.AreEqual<int>(2, target.Round);
                }
            }
        }
示例#13
0
        public void Game_FullCycle()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            target = target.DrawCard();
            target = target.PlaceCardOnPile(0);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(0);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(0);

            target = target.DrawCard();
            target = target.PlaceCardOnPile(1);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(1);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(1);

            target = target.DrawCard();
            target = target.PlaceCardOnPile(2);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(2);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(2);

            target = target.DrawCard();
            target = target.PlaceCardOnPile(3);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(3);
            target = target.DrawCard();
            target = target.PlaceCardOnPile(3);

            Assert.AreEqual<int>(1, target.Cycle);
            Assert.AreEqual<int>(13, target.Turn);
            Assert.AreEqual<GameActions>(GameActions.PickupPile, target.AvailableActions);

            target = target.PickupPile(0);
            target = target.PickupPile(1);
            target = target.PickupPile(2);
            target = target.PickupPile(3);

            // Make sure that a new cycle is created
            Assert.AreEqual<int>(2, target.Cycle);
            Assert.AreEqual<int>(17, target.Turn);
            Assert.AreEqual<GameActions>(GameActions.Draw, target.AvailableActions);
        }
示例#14
0
        void PlayerPanel_Loaded(object sender, RoutedEventArgs e)
        {
            Profile p1 = new Profile() { Username = "******", Color = "Red" };
            Profile p2 = new Profile() { Username = "******", Color = "Green" };
            Profile p3 = new Profile() { Username = "******", Color = "Blue" };
            ColorettoGame game = new ColorettoGame(p1, p2, p3);

            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;

            game = (game + PickupPileAction.Action(0)).Game;
            game = (game + PickupPileAction.Action(1)).Game;
            game = (game + PickupPileAction.Action(2)).Game;

            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;

            game = (game + PickupPileAction.Action(0)).Game;
            game = (game + PickupPileAction.Action(1)).Game;
            game = (game + PickupPileAction.Action(2)).Game;

            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;

            game = (game + PickupPileAction.Action(0)).Game;
            game = (game + PickupPileAction.Action(1)).Game;
            game = (game + PickupPileAction.Action(2)).Game;

            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;

            game = (game + PickupPileAction.Action(0)).Game;
            game = (game + PickupPileAction.Action(1)).Game;
            game = (game + PickupPileAction.Action(2)).Game;

            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(0)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(1)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;
            game = (game + PlaceCardAction.Action(2)).Game;

            game = (game + PickupPileAction.Action(0)).Game;
            game = (game + PickupPileAction.Action(1)).Game;
            game = (game + PickupPileAction.Action(2)).Game;

            playerHand.Cards = game.Hands[0];
        }
示例#15
0
        public void Game_BasicConstructorTest()
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            ColorettoGame target = new ColorettoGame(player1, player2, player3, player4);

            using(FileStream fs = new FileStream(@"test.zip", FileMode.Create))
            using (GZipStream stream = new GZipStream(fs, CompressionMode.Compress))
            {
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, target);
            }

            Profile[] loadedProfiles = target.Players.ToArray();
            Assert.AreEqual<int>(4, loadedProfiles.Length);
            Assert.AreSame(player1, loadedProfiles[0]);
            Assert.AreSame(player2, loadedProfiles[1]);
            Assert.AreSame(player3, loadedProfiles[2]);
            Assert.AreSame(player4, loadedProfiles[3]);
        }
示例#16
0
        public Coloretto.Actions.ActionResult DrawCard(int pileNumber)
        {
            Profile player1 = new Profile();
            Profile player2 = new Profile();
            Profile player3 = new Profile();
            Profile player4 = new Profile();
            Game.ColorettoGame target = new Game.ColorettoGame(player1, player2, player3, player4);

            ActionResult result = target + DrawCardAction.DefaultAction;
            return result;
        }
示例#17
0
        private void InitializePlayers()
        {
            _playerSlots = new ContentControl[] { ThisPlayer, PlayerSlot1, PlayerSlot2, PlayerSlot3, PlayerSlot4 };
            PlayerPanels = new Dictionary<Profile, PlayerPanel>(5);

            List<Profile> profiles = new List<Profile>(5);
            int i = 0;
            foreach (string player in _startDialog.ConfiguredPlayers)
            {
                Profile profile = new Profile { Username = player, Color = ((ColorettoCardColors)(PlayerPanels.Count + 1)).ToString() };
                PlayerPanel panel = new PlayerPanel { PlayerProfile = profile, PlayerIndex = i++ };
                PlayerPanels.Add(profile, panel);

                _playerSlots[profiles.Count].Content = panel;
                profiles.Add(profile);
            }

            PlayerPanels[profiles[0]].IsPlayersTurn = true;
        }