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

            stickGame.AddPlayer(new Player("mario"));
            stickGame.Players.First(a => a.Name == "mario");
        }
Ejemplo n.º 2
0
        private static void CreatePlayersStep(int cont, StickGame stickGame)
        {
            while (true)
            {
                Console.WriteLine($"\nPlayer {cont}");
                Console.Write($"Name:");
                var userInput = Console.ReadLine();
                if (!string.IsNullOrEmpty(userInput.Trim()))
                {
                    stickGame.AddPlayer(new Player(userInput));
                    cont++;
                }
                else
                {
                    Console.WriteLine($"Name cannot be empty or white space!");
                    continue;
                }

                while (userInput != "y" && userInput != "n")
                {
                    Console.WriteLine($"\nDo you want add one more player? (y to yes - n to no)");
                    userInput = Console.ReadLine();
                    if (userInput == "y")
                    {
                        continue;
                    }
                    if (userInput == "n")
                    {
                        return;
                    }
                }
            }
        }
Ejemplo n.º 3
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.º 4
0
        public void GameDecreaseQuantitySticksCorretlyAfterAPlayerRemoveOne()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            stickGame.RemoveSticks("mario", 2);
            Assert.IsTrue(stickGame.QtdSticks == 29);
        }
Ejemplo n.º 5
0
        public void GameDoesNotAllowAddMorePlayersThanSticks()
        {
            var          stickGame     = new StickGame();
            const int    TOTAL_STICKS  = StickGame.TOTAL_STICKS;
            var          stickersCount = new int[TOTAL_STICKS].ToList();
            TestDelegate code          = () => { stickersCount.ForEach((i) => stickGame.AddPlayer(new Player($"player{i}"))); };

            Assert.Throws <InvalidOperationException>(code);
        }
Ejemplo n.º 6
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.º 7
0
        public void GameThrowsKeyNotFoundExceptionWhenWasInputedAInvalidPlayer()
        {
            var stickGame = new StickGame();

            AddDefaultPlayers(stickGame);
            Assert.Throws <KeyNotFoundException>(() =>
            {
                stickGame.RemoveSticks("incorrectPlayer", 5);
            });
        }
Ejemplo n.º 8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            OuyaController.Init(this);
            StickGame.Activity = this;
            StickGame g = new StickGame();
            SetContentView(g.Window);
            g.Run();
        }
Ejemplo n.º 9
0
        public void GameDoesNotPermitAddMoreThanOnePlayerWithSameName()
        {
            var stickGame = new StickGame();

            Assert.Throws <InvalidOperationException>(() =>
            {
                stickGame.AddPlayer(new Player("mario"));
                stickGame.AddPlayer(new Player("mario"));
            }
                                                      );
        }
Ejemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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);
        }
Ejemplo n.º 15
0
        public void GameStartsWithTurnsListInitialized()
        {
            var stickGame = new StickGame();

            Assert.IsTrue(stickGame.Players != null);
        }
Ejemplo n.º 16
0
 private static void AddDefaultPlayers(StickGame stickGame)
 {
     stickGame.AddPlayer(new Player("mario"));
     stickGame.AddPlayer(new Player("pc"));
 }
Ejemplo n.º 17
0
        public void GameStartsWith31Sticks()
        {
            var stickGame = new StickGame();

            Assert.IsTrue(stickGame.QtdSticks == 31);
        }