コード例 #1
0
ファイル: RedGhost.cs プロジェクト: Eriwyr/PacMan_Project
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            //We target a different point according to the mode
            switch (this.mode)
            {
            //We target a fixed point in Scatter mode
            case Mode.Scatter:
                this.target = new Position(-1, 26);
                break;

            //We target the center of the square to stay in it
            case Mode.StayIn:
                target = new Position(14, 14);
                break;

            case Mode.GoOut:     //We target outside the square
                target = new Position(0, 13);
                break;

            case Mode.Normal:
                //We target the player
                this.target = new Position(pac.getPosition().getPosX(), pac.getPosition().getPosY());
                break;
            }
        }
コード例 #2
0
ファイル: YellowGhost.cs プロジェクト: Eriwyr/PacMan_Project
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            switch (this.mode)
            {
            //We target different points according to the mode
            case Mode.Scatter:
                target = new Position(32, 0);     //We target a fixed point
                break;

            case Mode.StayIn:
                target = new Position(14, 14);     //We target the center of the square to stay in iy
                break;

            case Mode.GoOut:
                target = new Position(0, 14);     //We target outside of the square
                break;

            case Mode.Normal:

                //We target either the scatter point or the pacman
                int distance = manhattanDistance(pac.getPosition(), this.getPosition());
                if (distance < 8)     //If we are at less than 8 tiles away from the pacman
                {
                    //We target the scatter position
                    target = new Position(32, 0);
                }
                else
                {
                    //We have the same target has the red ghost
                    target = new Position(pac.getPosition().getPosX(), pac.getPosition().getPosY());
                }
                break;
            }
        }
コード例 #3
0
ファイル: BlueGhost.cs プロジェクト: Eriwyr/PacMan_Project
        //Overriding computeTargetTile so that we can have a different target
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            switch (this.mode)
            {
            case Mode.Scatter:     //If we are in Scatter mode, we target a fixed point in the corner of the map
                target = new Position(32, 28);
                break;

            case Mode.StayIn:     //We stay in the center
                target = new Position(14, 14);
                break;

            case Mode.GoOut:     //We target outside the center
                target = new Position(0, 14);
                break;

            case Mode.Normal:     //We chase the player

                //This ghost target two tiles ahead of the pacman, and create a vector from this
                //new position and the position of the red ghost, this vector timed by 2 gives
                //The target of the blue ghost.
                Position tmp = twoAhead(pac.getState(), pac.getPosition());
                int      xg  = ghost.getPosition().getPosX();
                int      yg  = ghost.getPosition().getPosY();
                int      xp  = pac.getPosition().getPosX();
                int      yp  = pac.getPosition().getPosY();
                target = new Position(2 * xp - xg, 2 * yp - yg);
                break;
            }
        }
コード例 #4
0
      //When we died this function is called to reset everything
      public void reset()
      {
          for (int i = 0; i < ghosts.Length; i++)
          {
              ghosts[i].getPosition().setPosXY(13, 14);
              ghosts[i].setMode(Mode.StayIn);
              ghosts[i].setTurnToGoOut(ghosts[i].getTurnToGoOut() / 2);
              turnToGoOut[i] = 0;
              vulnerabitlitiesChanging[i] = 0;
              countersChanging[i, 0]      = 0;
              countersChanging[i, 1]      = 0;
          }

          pacMan.getPosition().setPosXY(23, 13);
      }
コード例 #5
0
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            //We target a different point according to the mode
            switch (this.mode)
            {
            case Mode.Scatter:
                target = new Position(-1, 2);     //We target a fixed point in a corner
                break;

            case Mode.StayIn:
                target = new Position(14, 14);     //We target the center of the square to stay in it
                break;

            case Mode.GoOut:     //We target outside of the square
                target = new Position(0, 14);
                break;

            case Mode.Normal:
                //This ghost targets four tiles ahead of the pacman
                Position pos = fourAhead(pac.getState(), pac.getPosition());
                if (pac.getState() == State.Up)
                {
                    //According to an overflow bug in the original version,
                    //When the pacman is heading up, the target was also four tiles to the left.
                    //For a purpose of keeping the same artificial intelligence, we decided to keep this
                    //even though it does not causes any bug today.
                    pos.setPosY(pos.getPosY() - 4);
                }
                target = pos;
                break;
            }
        }
コード例 #6
0
ファイル: Ghost.cs プロジェクト: Eriwyr/PacMan_Project
        private void computeAwayTile(PacMan pac, Map map)
        {
            double   distance = 0;
            double   dist;
            Position pacPos = pac.getPosition();
            Position ret    = new Position(0, 0);

            //For each tiles of the map, we store the furthest
            for (int i = 0; i < map.getVX(); i++)
            {
                for (int j = 0; j < map.getVY(); j++)
                {
                    Position tmp = new Position(i, j);
                    dist = euclidianDistance(pacPos, tmp);
                    if (dist >= distance)
                    {
                        distance = dist;
                        ret.setPosXY(tmp.getPosX(), tmp.getPosY());
                    }
                }
            }

            target = ret; //We target the furthests point
        }