public void TestRemovePlayerByID() { IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository(); int playerID = repository.GetPlayerID("player1"); GamesResult gamesResult; if (playerID == 0) { //Add player repository.AddPlayer("player1", "password"); playerID = repository.GetPlayerID("player1"); } gamesResult = repository.GetGamesResultForPlayer(playerID); if (gamesResult.NumberOfGames == 0) { int wordID = repository.GetWords(1)[0]; repository.RecordGame(playerID, wordID, 3, 3, true); gamesResult = repository.GetGamesResultForPlayer(playerID); } Assert.IsTrue(gamesResult.NumberOfGames > 0); Assert.IsTrue(gamesResult.NumberOfSuccess > 0); Assert.IsTrue(playerID > 0); repository.RemovePlayerByID(playerID); int id2 = repository.GetPlayerID("player1"); gamesResult = repository.GetGamesResultForPlayer(playerID); Assert.IsTrue(id2 == 0); Assert.IsTrue(gamesResult.NumberOfGames == 0); }
public void TestCategoryWords() { IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository(); int[] words = repository.GetWords(2); Assert.IsNotNull(words); Assert.AreEqual(11, words.Length); Assert.AreEqual(13, words[0]); Assert.AreEqual(14, words[1]); }
public Game(int categoryID, string username) { this.categoryID = categoryID; repository = HangmanRepositoryFactory.CreateRepository(); int[] wordIDs = repository.GetWords(categoryID); this.playerID = repository.GetPlayerID(username); Random rnd = new Random(); int n = rnd.Next(wordIDs.Length - 1); wordID = wordIDs[n]; string[] wordInfo = repository.GetWordByID(wordID); Word = wordInfo[0]; Description = wordInfo[1]; StringBuilder sb = new StringBuilder(); sb.Append(Word[0]); for (int i = 1; i < Word.Length - 1; i++) { sb.Append("_"); } sb.Append(Word[Word.Length - 1]); GuessedWord = sb.ToString(); sb.Clear(); sb.Append(GuessedWord[0]); for (int i = 1; i < GuessedWord.Length; i++) { sb.Append(" " + GuessedWord[i]); } DisplayWord = sb.ToString(); WrongChars = ""; WrongCharsCount = 0; Status = ""; }