示例#1
0
        public void TestActIfAble()
        {
            Agent actor   = new Assassin();
            Agent target  = new Drudge();
            Agent blocker = new Saboteur();

            // No target and IsActing is false => no action
            actor.ActIfAble();
            Assert.IsFalse(target.WasAttacked);
            actor.Reset();

            // IsActing is true but no target => no action
            actor.IsActing = true;
            Assert.Throws <NoTargetException>(() => actor.ActIfAble());
            Assert.IsFalse(target.WasAttacked);
            actor.Reset();

            // Has a target but IsActing is false => no action
            actor.Target = target;
            actor.ActIfAble();
            Assert.IsFalse(target.WasAttacked);
            actor.Reset();

            // Has a target and IsActing is true but blocked => no action
            actor.Target   = target;
            actor.IsActing = true;
            actor.Block(blocker);
            actor.ActIfAble();
            Assert.IsFalse(target.WasAttacked);
            actor.Reset();

            // Has a target and IsActing is true, and not blocked => action
            actor.Target   = target;
            actor.IsActing = true;
            actor.ActIfAble();
            Assert.IsTrue(target.WasAttacked);
            actor.Reset();
            target.Reset();

            // Target is dead => no action
            actor.Target   = target;
            actor.IsActing = true;
            actor.ActIfAble();
            Assert.IsFalse(target.WasAttacked);
            actor.Reset();
            target = new Drudge();

            // Actor is dead => no action
            actor.Target   = target;
            actor.IsActing = true;
            actor.Execute();
            actor.ActIfAble();
            Assert.IsFalse(target.WasAttacked);
            actor.Reset();
        }
示例#2
0
 public void Setup()
 {
     Game  = new();
     Agent = (Drudge)Game.Agents[nameof(Drudge)];
 }