Beispiel #1
0
        public void CheckGhostAttackSlime()
        {
            var monster = new Ghost();

            Assert.AreEqual("You've been slimed!", monster.Attack());
        }
        public void ApplyAction(List <Ghost> ghosts, List <Buster> busters, string action, bool apply)
        {
            string[] parts = action.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            ViewRange = BUSTER_VIEW;
            if (cooldownTime > 0)
            {
                cooldownTime--;
            }
            if (stunnedTime > 0)
            {
                stunnedTime--;
            }
            if (apply)              // buster is not stunned
            {
                switch (parts [0].ToUpper())
                {
                case "MOVE":
                    this.Move(new Point(int.Parse(parts [1]), int.Parse(parts [2])));
                    break;

                case "BUST":
                    DropGhost(ghosts);
                    Ghost ghost = ghosts.FirstOrDefault(g => g.ID == int.Parse(parts [1]));
                    if (ghost != null && this.Dist(ghost) >= BUSTER_MIN_BUST && this.Dist(ghost) <= BUSTER_MAX_BUST)
                    {
                        ghost.Attack(this);
                    }
                    break;

                case "RELEASE":
                    Release(ghosts);
                    break;

                case "STUN":
                    DropGhost(ghosts);
                    Buster target = busters.FirstOrDefault(b => b.ID == int.Parse(parts [1]));
                    if (cooldownTime == 0 && this.Dist(target) <= BUSTER_MAX_STUN_RANGE)
                    {
                        target.stunnedTime = BUSTER_STUN_HIT;
                        if (target.ID > this.ID)
                        {
                            target.stunnedTime++;                             //will be reduced during target.ApplyAction
                        }
                        this.cooldownTime = BUSTER_STUN_COOLDOWN;
                    }
                    break;

                case "RADAR":
                    if (canRadar)
                    {
                        canRadar  = false;
                        ViewRange = BUSTER_RADAR;
                    }
                    break;

                case "EJECT":
                    DropGhost(ghosts)?.MoveTo(new Point(int.Parse(parts [1]), int.Parse(parts [2])), BUSTER_MAX_EJECT);
                    break;
                }
            }
            foreach (GameObject g in ghosts.Union <GameObject>(busters))
            {
                if (this.Dist(g) <= ViewRange)
                {
                    g.See(this);
                }
            }
        }