コード例 #1
0
ファイル: UserInputTests.cs プロジェクト: catycaldwell/Zork
 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"));
         }
     }
 }
コード例 #2
0
ファイル: MurdererTests.cs プロジェクト: catycaldwell/Zork
        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);
        }