Ejemplo n.º 1
0
        public void GameMustInformGameStatus()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            Assert.IsTrue(stickGame.GetStatus() == GameStatus.NotStarted);
            stickGame.RemoveSticks("mario", 10);
            Assert.IsTrue(stickGame.GetStatus() == GameStatus.Happening);
            stickGame.RemoveSticks("pc", 10);
            stickGame.RemoveSticks("mario", 4);
            stickGame.RemoveSticks("pc", 7);
            Assert.IsTrue(stickGame.GetStatus() == GameStatus.Finished);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello! Stick Game has started!");
            Console.WriteLine("\nThe 1rst step is create the players");
            var cont       = 1;
            var playerName = "";
            var stickGame  = new StickGame();

            CreatePlayersStep(cont, stickGame);
            Console.Clear();
            Console.WriteLine("\n\nLet's go to the game!");

            while (stickGame.GetStatus() != GameStatus.Finished)
            {
                foreach (var player in stickGame.Players)
                {
                    Console.WriteLine($"\n[Player {player.Name}] - How many sticks?");
                    int.TryParse(Console.ReadLine(), out int quantity);
                    stickGame.RemoveSticks(player.Name, quantity);
                    GiveFeedBack(quantity);
                    Console.WriteLine($"{stickGame.QtdSticks} sticks remaining!");

                    if (stickGame.GetStatus() == GameStatus.Finished)
                    {
                        break;
                    }
                }
            }
            Console.WriteLine($"And the winner was {stickGame.GetWinner().Name} with {stickGame.GetWinner().Score} points!");
            Console.WriteLine($"Really nice! Bye!");
        }
Ejemplo n.º 3
0
        public void GameDecreaseQuantitySticksCorretlyAfterAPlayerRemoveOne()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            stickGame.RemoveSticks("mario", 2);
            Assert.IsTrue(stickGame.QtdSticks == 29);
        }
Ejemplo n.º 4
0
        public void GameRegistersAmountOfScoreAfterAPlayerRemoveAStick()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            stickGame.RemoveSticks("mario", 2);
            var playerMario = stickGame.Players.FirstOrDefault(a => a.Name == "mario");

            Assert.IsTrue(playerMario.Score == 20);
        }
Ejemplo n.º 5
0
        public void GameThrowsKeyNotFoundExceptionWhenWasInputedAInvalidPlayer()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            Assert.Throws <KeyNotFoundException>(() =>
            {
                stickGame.RemoveSticks("incorrectPlayer", 5);
            });
        }
Ejemplo n.º 6
0
        public void GameMustInformTheWinnerCorrectly()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            stickGame.RemoveSticks("mario", 14);
            stickGame.RemoveSticks("pc", 16);
            Assert.IsTrue(stickGame.GetWinner().Name == "pc");

            stickGame = new StickGame();
            AddDefaultPlayers(stickGame);
            stickGame.RemoveSticks("mario", 5);
            stickGame.RemoveSticks("pc", 5);
            stickGame.RemoveSticks("mario", 5);
            stickGame.RemoveSticks("pc", 5);
            stickGame.RemoveSticks("mario", 5);
            stickGame.RemoveSticks("pc", 2);
            stickGame.RemoveSticks("mario", 1);
            Assert.IsTrue(stickGame.GetWinner().Name == "mario");
        }
Ejemplo n.º 7
0
        public void GameThrowsInvalidOperationExceptionWhenSomeoneTriesToRemoveMoreSticksThanTheTotalOfSticks()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            Assert.Throws <InvalidOperationException>(() =>
            {
                stickGame.RemoveSticks("pc", 32);
            });

            stickGame = new StickGame();
            AddDefaultPlayers(stickGame);

            Assert.Throws <InvalidOperationException>(() =>
            {
                stickGame.RemoveSticks("mario", 10);
                stickGame.RemoveSticks("pc", 10);
                stickGame.RemoveSticks("mario", 6);
                stickGame.RemoveSticks("pc", 6);
            });
        }
Ejemplo n.º 8
0
        public void GameControlTurnsPlayerShouldPlayOnceByGame_ThrowsInvalidOperationExceptionWhenPlayerPlaysInWrongMoment()
        {
            var stickGame = new StickGame();

            stickGame.AddPlayer(new Player("mario"));
            stickGame.AddPlayer(new Player("pc"));
            stickGame.AddPlayer(new Player("maria"));
            stickGame.AddPlayer(new Player("anacleto"));
            stickGame.AddPlayer(new Player("malu"));

            TestDelegate assert = () => stickGame.RemoveSticks("anacleto", 1);

            Assert.Throws <InvalidOperationException>(assert);
        }
Ejemplo n.º 9
0
        public void GameMustInformScoreOfPlayersCorrectly()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            stickGame.RemoveSticks("mario", 10);
            stickGame.RemoveSticks("pc", 10);
            stickGame.RemoveSticks("mario", 4);
            stickGame.RemoveSticks("pc", 6);
            Assert.IsTrue(stickGame.Players.First(a => a.Name == "mario").Score == 140);
            Assert.IsTrue(stickGame.Players.First(a => a.Name == "pc").Score == 160);

            stickGame = new StickGame();
            AddDefaultPlayers(stickGame);
            stickGame.RemoveSticks("mario", 5);
            stickGame.RemoveSticks("pc", 5);
            stickGame.RemoveSticks("mario", 5);
            stickGame.RemoveSticks("pc", 5);
            stickGame.RemoveSticks("mario", 5);
            stickGame.RemoveSticks("pc", 2);
            stickGame.RemoveSticks("mario", 1);
            Assert.IsTrue(stickGame.Players.First(a => a.Name == "mario").Score == 160);
            Assert.IsTrue(stickGame.Players.First(a => a.Name == "pc").Score == 120);
        }