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));
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 public GameStateController(ColorettoGame game, MainWindow window)
 {
     Id = Guid.NewGuid();
     _window = window;
     PlayerStates = new ObservableCollection<PlayerStateController>();
     CurrentGame = game;
 }
        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);
        }
Example #4
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;
 }
Example #5
0
        public TurnActions(ColorettoGame game)
        {
            _player = game.CurrentPlayer;
            _round = game.Round;
            _turn = game.Turn;
            _cycle = game.Cycle;

            _actions = new ReadOnlyCollection<BaseAction>(new List<BaseAction>(0));
            _results = new ReadOnlyCollection<ActionResult>(new List<ActionResult>(0));
        }
Example #6
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);
        }
Example #7
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));
        }
Example #10
0
 protected override ActionResult Execute(ColorettoGame game)
 {
     try
     {
         ColorettoGame newGame = game.PlaceCardOnPile(_targetPile);
         ActionResult result = new ActionResult(this.Name, newGame, game.CurrentPlayer, newGame.Piles[_targetPile], true);
         return result;
     }
     catch (ArgumentException ex)
     {
         return new ActionResult(this.Name, game, game.CurrentPlayer, ex, false);
     }
     catch (InvalidOperationException ex)
     {
         return new ActionResult(this.Name, game, game.CurrentPlayer, ex, false);
     }
     catch (Exception)
     {
         throw;
     }
 }
        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));
            }
        }
        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];
        }
Example #13
0
 protected override ActionResult Execute(ColorettoGame game)
 {
     ColorettoGame cloneGame = game.DrawCard();
     ActionResult result = new ActionResult(this.Name, cloneGame, game.CurrentPlayer, cloneGame.VisibleCard, cloneGame.VisibleCard != null);
     return result;
 }
 public GameUpdatedEventArgs(ColorettoGame old, ColorettoGame newGame)
 {
     OldGame = old;
     NewGame = newGame;
 }
Example #15
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);
        }
Example #16
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);
        }
Example #17
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);
                }
            }
        }
Example #18
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");
        }
Example #19
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);
        }
Example #20
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]);
        }
Example #21
0
 /// <summary>
 /// Report the game over status for game
 /// </summary>
 /// <param name="game"></param>
 public GameOver(ColorettoGame game)
     : this()
 {
     this.Game = game;
 }
Example #22
0
 /// <summary>
 /// Perform the action on game.
 /// </summary>
 /// <param name="game">The game to perform the action on</param>
 /// <returns>The result of the action.</returns>
 internal ActionResult PerformAction(ColorettoGame game)
 {
     ActionResult result = Execute(game);
     return result;
 }
Example #23
0
 /// <summary>
 /// Execute the action
 /// </summary>
 /// <remarks>
 /// I have this marked as protected to force the use of PerformAction(..). 
 /// This will force all actions to go through the base and easier to see when they happen.
 /// </remarks>
 /// <param name="game"></param>
 /// <returns></returns>
 protected abstract ActionResult Execute(ColorettoGame game);
Example #24
0
 public TurnActions(ColorettoGame game, BaseAction action, ActionResult result)
     : this(game)
 {
     _actions = (new List<BaseAction> { action }).AsReadOnly();
     _results = (new List<ActionResult> { result }).AsReadOnly();
 }
Example #25
0
        private void InitializeGame()
        {
            Stacks.NumberOfStacks = _startDialog.ConfiguredPlayers.Count();
            ColorettoGame game = new ColorettoGame(PlayerPanels.Keys.Select(key => key).ToArray());
            Controller = new GameStateController(game, this);
            Controller.GameUpdated += new System.EventHandler<GameUpdatedEventArgs>(Controller_GameUpdated);

            foreach (var playerPanels in PlayerPanels)
                Controller.GameUpdated += playerPanels.Value.Controller_GameUpdated;

            #if DEBUG
            if (_showCheatWindow)
            {
                CheatWindow cheat = new CheatWindow(this, Controller);
            }
            #else
            if(_showCheatWindow)
            {
                MessageBox.Show("You are trying to cheat. You have been reported. Cheater.");
            }
            #endif
        }