Exemple #1
0
        public void ChangeStateMethodTest_IntoChasing()
        {
            Ghost ghost = getGhost();

            ghost.ChangeState(GhostState.Scared);
            ghost.ChangeState(GhostState.Chasing);
            GhostState expected = GhostState.Chasing;
            GhostState actual   = ghost.CurrentState;

            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        string tag = collision.collider.tag;

        switch (tag)
        {
        case "Pellet":
            // TODO: play sound
            collision.gameObject.SetActive(false);
            GameLogic.instance.AddScore(GameSettings.instance.PelletScore);
            break;

        case "SuperPellet":
            // TODO: play sound
            GameLogic.instance.AddScore(GameSettings.instance.SuperPelletScore);

            // Set all the ghosts to frightened
            List <Ghost> ghosts = GameLogic.instance.GetAllGhosts();
            for (int i = 0; i < ghosts.Count; i++)
            {
                Ghost.State ghostState = ghosts[i].CurrentState;
                if (ghostState != Ghost.State.consumed && ghostState != Ghost.State.inHouse)
                {
                    ghosts[i].ChangeState(Ghost.State.frightened);
                }
            }

            collision.gameObject.SetActive(false);
            break;

        case "Fruit":
            collision.gameObject.SetActive(false);
            int score = GameSettings.instance.FruitScore;
            GameLogic.instance.AddScore(score);

            GameLogic.instance.SpawnScoreText(currentPos, 1, score);
            break;

        case "Ghost":
            if (currentState != State.dead)
            {
                Ghost ghost = collision.gameObject.GetComponent <Ghost>();
                if (ghost.CurrentState == Ghost.State.frightened)
                {
                    int scoreToAdd = GameSettings.instance.GhostEatScore;

                    GameLogic.instance.AddScore(scoreToAdd);
                    ghost.ChangeState(Ghost.State.consumed);

                    GameLogic.instance.SpawnGhostEatText(this, ghost, 1, scoreToAdd);
                }
                else if (ghost.CurrentState != Ghost.State.consumed && !invulerable)
                {
                    ChangeState(State.dead);
                }
            }
            break;
        }
    }
Exemple #3
0
        public void TestChangeState()
        {
            Ghost ghost = new Ghost(GetGameState(), new Vector2(10, 10), new Vector2(15, 15),
                                    GhostState.Scared, new Color(255, 0, 0));

            //Ghost is scared and gonna be Chased now.
            ghost.ChangeState(GhostState.Chase);
            Assert.AreEqual(ghost.CurrenState, GhostState.Chase);
        }
        public void TestChangeGhostState()
        {
            GameState g = GameState.Parse(level1);

            Ghost gh = new Ghost(g, 14, 15, GhostState.Chase, new Color(255, 255, 255), GhostName.Blinky);

            gh.ChangeState(GhostState.Scared);

            Assert.AreEqual(gh.CurrentState, GhostState.Scared);
        }
Exemple #5
0
        public void CollideMethodTest_CollisionEventRaised()
        {
            Ghost ghost = getGhost();

            ghost.ChangeState(GhostState.Scared);

            bool expected = true;
            bool actual   = false;

            ghost.CollisionEvent += (x) =>
            {
                actual = true;
            };
            ghost.Collide();
            Assert.AreEqual(expected, actual);
        }