public void FleeFunctionalityTest() { Maze m = new Maze(Game.Width, Game.Height, 0, 0); Player p = CharacterTests.CreatePlayerCharacter(); p.CurrentRoom = new Room("", new Point(0, 0)); int oldX = p.CurrentRoom.LocationOfRoom.X; int oldY = p.CurrentRoom.LocationOfRoom.Y; p.Flee(m); bool different = p.CurrentRoom.LocationOfRoom.X != oldX | p.CurrentRoom.LocationOfRoom.Y != oldY; Assert.IsTrue(different); }
public void UnarmedPlayerDescriptionIsCorrect() { Player p = CharacterTests.CreatePlayerCharacter(); p.EquippedWeapon = null; using (StringWriter consoleOutput = new StringWriter()) { Console.SetOut(consoleOutput); p.PrintStats(); Assert.AreEqual(p.Name + ": " + p.Description + "\r\nHealth: 100" + "\r\nStrength: " + p.Strength + "\r\nUnarmed.\r\n\r\n", consoleOutput.ToString()); } }
public void WeaponDescriptionIsCorrect() { Player p = CharacterTests.CreatePlayerCharacter(); string gunName = "gun"; string gunDescription = "description"; p.EquippedWeapon = new Weapon(gunName, 1, gunDescription); using (StringWriter consoleOutput = new StringWriter()) { Console.SetOut(consoleOutput); p.EquippedWeapon.PrintStats(); Assert.AreEqual(gunName + ": " + gunDescription + "\r\nStrength: " + p.EquippedWeapon.Strength + "\r\n", consoleOutput.ToString()); } }
public void ArmedPlayerDescriptionIsCorrect() { using (StringWriter consoleOutput = new StringWriter()) { Player p = CharacterTests.CreatePlayerCharacter(); Console.SetOut(consoleOutput); p.PrintStats(); string expectedResult = p.Name + ": " + p.Description + "\r\nHealth: 100" + "\r\nStrength: " + p.Strength + "\r\nCurrent weapon:" + "\r\n" + p.EquippedWeapon.Name + ": " + p.EquippedWeapon.Description + "\r\nStrength: " + p.EquippedWeapon.Strength + "\r\n\r\n"; Assert.AreEqual(expectedResult, consoleOutput.ToString()); } }
public void TestBattleEnemy() { using (StringWriter stringWriter = new StringWriter()) { using (var sr = new StringReader("b\n1\nq")) { Console.SetOut(stringWriter); Game game = new Game(); game.player.CurrentRoom.NPCsInRoom.Clear(); NPC npc = CharacterTests.CreateNPC(); npc.CurrentRoom = game.player.CurrentRoom; game.player.CurrentRoom.NPCsInRoom.Add(npc); Console.SetIn(sr); game.Run(); string output = stringWriter.ToString(); Assert.IsTrue(output.Contains("You hit for")); } } }
public void NPCPicksUpWeapon() { using (ShimsContext.Create()) { Zork.Fakes.ShimChance.PercentageInt32 = (_) => { return(true); }; Game game = new Game(); foreach (Room room in game.maze) { room.ObjectsInRoom.Clear(); room.ObjectsInRoom.Add(CharacterTests.CreateWeapon()); } NPC npc = game.NPCS.First(); for (int i = 0; i < NPC.MaxTurnsBetweenMoves; ++i) { npc.OnPlayerMoved(game); } Assert.IsNotNull(npc.EquippedWeapon); } }
public void MurdererTriesToKillEveryXTurns() { Game game = new Game(); Maze m = new Maze(1, 1, 0, 0); MurdererNPC murderer = CreateMurderer(); murderer.Maze = m; murderer.CurrentRoom = m.Rooms[0, 0]; NPC victim = CharacterTests.CreateNPC(); victim.CurrentRoom = murderer.CurrentRoom; murderer.CurrentRoom.NPCsInRoom.Add(victim); murderer.CurrentRoom.NPCsInRoom.Add(murderer); int totalNpcs = CountNPCs(m); for (int i = 0; i < murderer.KillEveryXPlayerSteps; ++i) { murderer.PossiblyKillSomeone(game); } int totalnpcsAfterKill = CountNPCs(m); Assert.IsTrue(totalnpcsAfterKill < totalNpcs); }