Exemplo n.º 1
0
        public static void EstimateScore(Word secretWord, int numberOfMistakes)
        {
            bool isNewTopScore = Scoreboard.ScoreboardInstance.IsNewTopScore(numberOfMistakes);
            string comment = numberOfMistakes == 1 ? " mistake" : " mistakes";

            Console.WriteLine("The secret word is " + secretWord.MaskedWord);
            Console.Write("\nYou won with " + numberOfMistakes + comment);

            if (!usedHelp && isNewTopScore)
            {
                Console.Write("\nPlease enter your name for the top scoreboard: ");

                string newTopPlayerName = Console.ReadLine();
                Player newTopPlayer = new Player(newTopPlayerName, numberOfMistakes);

                Scoreboard.ScoreboardInstance.AddPlayer(newTopPlayer);

                ShowScoreboard();
            }
            else if (!isNewTopScore)
            {
                Console.Write(" but your result is lower than top scores\n");
            }
            else
            {
                Console.Write(" but you have cheated. You are not allowed to enter into the scoreboard.\n");
            }

            usedHelp = false;
        }
 public void Player_CompareTwoPlayerSecondBiggerThanFirstTest()
 {
     Player playerIvan = new Player("Ivan", 2);
     Player playerAsen = new Player("Asen", 3);
     var result = playerIvan.Compare(playerAsen);
     Assert.IsTrue(result == -1);
 }
Exemplo n.º 3
0
 public GameEngine(Player player, IConsole consoleWrapper)
 {
     this.Player = player;
     this.ConsoleWrapper = consoleWrapper;
     this.ChoiceStrategy = new ChoiceRandom();
     this.PathToSecretWordsDirectory = PathToSecretWordsDirectory;
 }
Exemplo n.º 4
0
        public void TopPlayerNameAsEmptyString()
        {
            string name = string.Empty;
            int topScore = 5;

            Player topPlayer = new Player(name, topScore);
        }
Exemplo n.º 5
0
 public CheckManager(Player player)
 {
     this.Player = player;
     this.CommandManager = new CommandManager();
     this.HasHelpUsed = false;
     this.UsedLetters = new HashSet<char>();
 }
 public void Player_CompareTwoPlayersWithNullNameTest()
 {
     Player playerIvan = new Player(null, 2);
     Player playerAsen = new Player("Asen", -4);
     var result = playerAsen.Compare(playerIvan);
     Assert.IsTrue(result == 1);
 }
 public void Player_CompareTwoPlayerWithNegativeMistakesTest()
 {
     Player playerIvan = new Player("Ivan", 2);
     Player playerAsen = new Player("Asen", -4);
     var result = playerAsen.Compare(playerIvan);
     Assert.IsTrue(result == 1);
 }
Exemplo n.º 8
0
        public void PlayerInstantiatedWithIncorrectNegativeScoreThrowsException()
        {
            string testPlayerName = "Rinswind";
            int testPlayerScore = -1234;
            Player testPlayer;

            testPlayer = new Player(testPlayerName, testPlayerScore);
        }
Exemplo n.º 9
0
        public void PlayerInstantiatedWithIncorrectNameThrowsException()
        {
            string testPlayerName = string.Empty;
            int testPlayerScore = 27;
            Player testPlayer;

            testPlayer = new Player(testPlayerName, testPlayerScore);
        }
Exemplo n.º 10
0
        public void TopPlayerCreation()
        {
            string name = "New player";
            int topScore = 5;

            Player topPlayer = new Player(name, topScore);

            Assert.IsNotNull(topPlayer);
            Assert.AreEqual(name, topPlayer.Name);
            Assert.AreEqual(topScore, topPlayer.Score);
        }
Exemplo n.º 11
0
        public void InstatniatePlayerWithCorrectScore()
        {
            string testPlayerName = "Rinswind";
            int testPlayerScore = 27;
            Player testPlayer;

            testPlayer = new Player(testPlayerName, testPlayerScore);
            int referencePlayerScore = testPlayer.Score;

            Assert.AreEqual(testPlayerScore, referencePlayerScore);
        }
Exemplo n.º 12
0
        public void VerifyThatAddPlayerWorksCorrectly()
        {
            string testPlayerName = "Rinswind";
            int testPlayerScore = 29;
            Player testPlayer = new Player(testPlayerName, testPlayerScore);
			var scoreboardMock = Scoreboard.ScoreboardInstance;

			scoreboardMock.AddPlayer(testPlayer);

            var scoreboard = scoreboardMock.ToString();

			Assert.AreEqual("1. "+testPlayer + " mistakes\r\n", scoreboard);
        }
Exemplo n.º 13
0
		public void VerifyScoreboardIsNewTopScoreWorksAsTrue()
		{
			Player testPlayer1 = new Player("Rinswind", 7);
			Player testPlayer2 = new Player("Rinswinda", 4);
			Player testPlayer3 = new Player("Pencho", 19);
			Player testPlayer4 = new Player("Muncho", 10);
			Player testPlayer5 = new Player("Pesho", 23);
			var scoreboardMock = Scoreboard.ScoreboardInstance;

			scoreboardMock.AddPlayer(testPlayer1);
			scoreboardMock.AddPlayer(testPlayer2);
			scoreboardMock.AddPlayer(testPlayer3);
			scoreboardMock.AddPlayer(testPlayer4);
			scoreboardMock.AddPlayer(testPlayer5);

			var check = scoreboardMock.IsNewTopScore(testPlayer5.Score);

			Assert.AreEqual(check, false);
		}
Exemplo n.º 14
0
		public void VerifyScoreboardToStringWorks()
		{
			Player testPlayer1 = new Player("Rinswind", 7);
			Player testPlayer2 = new Player("Rinswinda", 4);
			Player testPlayer3 = new Player("Pencho", 19);
			Player testPlayer4 = new Player("Muncho", 10);
			Player testPlayer5 = new Player("Pesho", 23);
			var scoreboardMock = Scoreboard.ScoreboardInstance;

			scoreboardMock.AddPlayer(testPlayer1);
			scoreboardMock.AddPlayer(testPlayer2);
			scoreboardMock.AddPlayer(testPlayer3);
			scoreboardMock.AddPlayer(testPlayer4);
			scoreboardMock.AddPlayer(testPlayer5);

			var scoreboard = scoreboardMock.ToString();

			Assert.AreEqual("1. Rinswinda --> 4 mistakes\r\n2. Rinswind --> 7 mistakes\r\n3. Muncho --> 10 mistakes\r\n4. Pencho --> 19 mistakes\r\n5. Pesho --> 23 mistakes\r\n", scoreboard);
		}
Exemplo n.º 15
0
        public void TopPlayerScoreAsNull()
        {
            string name = "New player";

            Player topPlayer = new Player(name, int.Parse(null));
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            bool keepPlaying = true;

            while (keepPlaying)
            {
                // Intro
                Player player = new Player();
                word = new Word();
                ProgramStart();
                player.Name = GetPlayerName();
                Welcome(player.Name);
                DifficultySetup();

                // Loopa spelrundan
                while (gameContinues)
                {
                    DrawGame(player.Life);
                    char guessedLetter = GuessLetter();
                    bool guess = word.CheckLetter(guessedLetter);
                    if (guess == true)
                    {
                        Console.WriteLine("Du gissade rätt bokstav!");
                    }
                    else
                    {
                        player.Damage();
                        Console.WriteLine("Du gissade fel! Du har " + player.Life + " försök kvar!");
                    }

                    if (word.IsComplete())
                    {
                        Console.WriteLine("\n\rOrdet är [" + word.ShownWord + "]");
                        Console.WriteLine("Du vann spelet!");
                        gameContinues = false;
                    }

                    if (player.Life <= 0)
                    {
                        string gameOver = File.ReadAllText("../../../gubbe/gameover.txt");
                        Console.WriteLine(gameOver);
                        Console.WriteLine("Det rätta ordet var {0}", word.SecretWord);
                        gameContinues = false;
                    }
                }

                // Spelrundan är över
                keepPlaying = AskPlayAgain();
            }

            // Game Over
            GameEnd();
            Console.ReadLine();
        }
Exemplo n.º 17
0
        public void TopPlayerNameAsWhitespace()
        {
            string name = " ";
            int topScore = 5;

            Player topPlayer = new Player(name, topScore);
        }
 /// <summary>
 /// Save the result of the player in a scoreboard.
 /// </summary>
 /// <param name="firstFreePosition">First free position in Scoreboard.</param>
 private void GetHighScoreEntry(int firstFreePosition)
 {
     string playerName = InputUserName();
     Player player = new Player(playerName, this.MistakesCounter); // used to be newResult
     PlayersScore.Scoreboard[firstFreePosition] = player;
     PlayersScore.PlaceScore(firstFreePosition);
 }
Exemplo n.º 19
0
 public void AddPlayer(Player newPlayer)
 {
     this.topPlayers.Add(newPlayer);
 }
Exemplo n.º 20
0
        public void TopPlayerScoreLessThanZero()
        {
            string name = "New player";
            int topScore = -1;

            Player topPlayer = new Player(name, topScore);
        }
Exemplo n.º 21
0
 public void AddScore(Player player)
 {
     this.TopScores.Add(player.Name, player.AttemptsToGuess);
     this.ExtractSpecificTopScores();
 }
Exemplo n.º 22
0
 public void Update(Player player)
 {
     this.Load();
     if (this.TopScores.Count < NumberOfTopScores || player.AttemptsToGuess < this.TopScores.Values.Last())
     {
         while (true)
         {
             UIMassages.EnterPlayerNameMessage();
             player.Name = this.ConsoleWrapper.ReadLine();
             if (player.Name == string.Empty)
             {
                 throw new ArgumentException(" the player's name cann't be an empty string");
             }
             else if (this.TopScores.ContainsKey(player.Name))
             {
                 throw new ArgumentException("Existing name!");
             }
             break;
         }
         this.AddScore(player);
         this.Save();
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// Compare mistakes of two players.
 /// </summary>
 /// <param name="otherPlayer">Other player.</param>
 /// <returns> -1 if mistakes of current player are less or equal to mistakes of the other player;
 /// 1 if mistakes of current player are more than mistakes of the other person.
 /// </returns>
 public int Compare(Player otherPlayer)
 {
     if (this.NumberOfMistakes <= otherPlayer.NumberOfMistakes)
     {
         return -1; // what happens if number of mistakes is equal?
     }
     else
     {
         return 1; // the newer one replaces the older
     }
 }
Exemplo n.º 24
0
        public void TopPlayerScoreAsEmptyString()
        {
            string name = "New player";

            Player topPlayer = new Player(name, int.Parse(string.Empty));
        }