Esempio n. 1
0
        public void SetDirection(Direction direction)
        {
            Point p = DirectionControl.DirectionToXY(direction);

            nextDirection = direction;
        }
Esempio n. 2
0
        private void MoveToDirection()
        {
            Direction prevDirection = _direction;

            ControllAnimation();

            int prevX = _x;
            int prevY = _y;

            _moveTimer++;
            if (_moveTimer != _moveSpeed)
            {
                return;
            }
            _moveTimer = 0;
            Point p = DirectionControl.DirectionToXY(nextDirection);

            if (nextDirection != Direction.NO_DIRECTION && Maze.IsPath(_x + p.x, _y + p.y))
            {
                _direction    = nextDirection;
                nextDirection = Direction.NO_DIRECTION;
            }

            if (_x == 47 && _y == 57)
            {
                if (_direction == Direction.DOWN)
                {
                    _direction = prevDirection;
                }
            }

            switch (_direction)
            {
            case Direction.UP:
                _x--;
                break;

            case Direction.DOWN:
                _x++;
                break;

            case Direction.LEFT:
                _y--;
                break;

            case Direction.RIGHT:
                _y++;
                break;

            default:
                break;
            }

            if (_x < 0)
            {
                _x = Maze.maze.GetLength(0) - 1;
            }
            else if (_x >= Maze.maze.GetLength(0))
            {
                _x = 0;
            }
            else if (_y < 0)
            {
                _y = Maze.maze.GetLength(1) - 1;
            }
            else if (_y >= Maze.maze.GetLength(1))
            {
                _y = 0;
            }

            if (!Maze.IsPath(_x, _y))
            {
                _x = prevX;
                _y = prevY;
            }

            if (Maze.maze[_x, _y] == 1)
            {
                Maze.maze[_x, _y]   = 0;
                Program.game.Score += 100;
                chompPlayer.Play();
                for (int i = 0; i < Maze.pacs.Count; i++)
                {
                    if (Maze.pacs[i].x == _x && Maze.pacs[i].y == _y)
                    {
                        Maze.pacs.RemoveAt(i);
                    }
                }

                if (Maze.pacs.Count == 0 && Maze.pellets.Count == 0)
                {
                    Program.game.isVictory = true;
                    Program.game.GameOver();
                }
            }
            else if (Maze.maze[_x, _y] == 2)
            {
                Maze.maze[_x, _y]   = 0;
                Program.game.Score += 200;
                Program.game.TriggerFrightened();
                pelletPlayer.Play();
                for (int i = 0; i < Maze.pellets.Count; i++)
                {
                    if (Maze.pellets[i].x == _x && Maze.pellets[i].y == _y)
                    {
                        Maze.pellets.RemoveAt(i);
                    }
                }

                if (Maze.pacs.Count == 0 && Maze.pellets.Count == 0)
                {
                    Program.game.isVictory = true;
                    Program.game.GameOver();
                }
            }
        }