Esempio n. 1
0
        public void MoveEnemies()
        {
            for (int index = 0; index < gameMap.Enemies.Length; index++)
            {
                if (!gameMap.Enemies[index].isDead())
                {
                    MovementEnum randomMovementDirection = gameMap.Enemies[index].ReturnMove();                                         // Obtain randon direction
                    EmptyTile    tempt = new EmptyTile(gameMap.Enemies[index].getX(), gameMap.Enemies[index].getY());                   // Enemy's position to be occupied by empty tile
                                                                                                                                        // update enemy position
                    if (randomMovementDirection != MovementEnum.No_Movement)
                    {
                        gameMap.Enemies[index].Move(randomMovementDirection);

                        switch (randomMovementDirection)
                        {
                        case MovementEnum.No_Movement: break;

                        case MovementEnum.Up:

                            gameMap.Mymap[gameMap.Enemies[index].getX(), gameMap.Enemies[index].getY()] = gameMap.Enemies[index];       // update the enemy on the map
                            gameMap.Mymap[tempt.getX(), tempt.getY()] = tempt;                                                          // update the empty tile on the map
                            gameMap.UpdateVision(); break;                                                                              // update the vision of all objects

                        case MovementEnum.Down:

                            gameMap.Mymap[gameMap.Enemies[index].getX(), gameMap.Enemies[index].getY()]     = gameMap.Enemies[index];
                            gameMap.Mymap[gameMap.Enemies[index].getX(), gameMap.Enemies[index].getY() - 1] = tempt;
                            gameMap.UpdateVision(); break;

                        case MovementEnum.Left:

                            gameMap.Mymap[gameMap.Enemies[index].getX(), gameMap.Enemies[index].getY()]     = gameMap.Enemies[index];
                            gameMap.Mymap[gameMap.Enemies[index].getX() + 1, gameMap.Enemies[index].getY()] = tempt;
                            gameMap.UpdateVision(); break;

                        case MovementEnum.Right:

                            gameMap.Mymap[gameMap.Enemies[index].getX(), gameMap.Enemies[index].getY()]     = gameMap.Enemies[index];
                            gameMap.Mymap[gameMap.Enemies[index].getX() - 1, gameMap.Enemies[index].getY()] = tempt;
                            gameMap.UpdateVision(); break;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public bool MovePlayer(MovementEnum direction)
        {
            bool isValid = false;

            switch (direction)
            {
            case MovementEnum.No_Movement: break;

            case MovementEnum.Up:

                if (gameMap._Hero.isMoveValid(MovementEnum.Up))
                {
                    // accomodate pick up items
                    Item itemToBeConsumed = gameMap.GetItemAtPosition(gameMap._Hero.getX(), gameMap._Hero.getY() - 1);
                    if (itemToBeConsumed != null)
                    {
                        gameMap._Hero.Pickup(itemToBeConsumed);
                    }

                    Tile tempt = new EmptyTile(gameMap._Hero.getX(), gameMap._Hero.getY());     // store position before update
                    gameMap._Hero.setY(gameMap._Hero.getY() - 1);
                    gameMap.Mymap[gameMap._Hero.getX(), gameMap._Hero.getY()] = gameMap._Hero;
                    gameMap.Mymap[tempt.getX(), tempt.getY()] = tempt; gameMap.UpdateVision(); isValid = true;
                }
                break;


            case MovementEnum.Down:

                if (gameMap._Hero.isMoveValid(MovementEnum.Down))
                {
                    Item itemToBeConsumed = gameMap.GetItemAtPosition(gameMap._Hero.getX(), gameMap._Hero.getY() + 1);
                    if (itemToBeConsumed != null)
                    {
                        gameMap._Hero.Pickup(itemToBeConsumed);
                    }

                    Tile tempt = new EmptyTile(gameMap._Hero.getX(), gameMap._Hero.getY());
                    gameMap._Hero.setY(gameMap._Hero.getY() + 1);
                    gameMap.Mymap[gameMap._Hero.getX(), gameMap._Hero.getY()]     = gameMap._Hero;
                    gameMap.Mymap[gameMap._Hero.getX(), gameMap._Hero.getY() - 1] = tempt; gameMap.UpdateVision(); isValid = true;
                }
                break;


            case MovementEnum.Left:

                if (gameMap._Hero.isMoveValid(MovementEnum.Left))
                {
                    Item itemToBeConsumed = gameMap.GetItemAtPosition(gameMap._Hero.getX() - 1, gameMap._Hero.getY());
                    if (itemToBeConsumed != null)
                    {
                        gameMap._Hero.Pickup(itemToBeConsumed);
                    }

                    Tile tempt = new EmptyTile(gameMap._Hero.getX(), gameMap._Hero.getY());
                    gameMap._Hero.setX(gameMap._Hero.getX() - 1);
                    gameMap.Mymap[gameMap._Hero.getX(), gameMap._Hero.getY()]     = gameMap._Hero;
                    gameMap.Mymap[gameMap._Hero.getX() + 1, gameMap._Hero.getY()] = tempt; gameMap.UpdateVision(); isValid = true;
                }
                break;

            case MovementEnum.Right:

                if (gameMap._Hero.isMoveValid(MovementEnum.Right))
                {
                    Item itemToBeConsumed = gameMap.GetItemAtPosition(gameMap._Hero.getX() + 1, gameMap._Hero.getY());
                    if (itemToBeConsumed != null)
                    {
                        gameMap._Hero.Pickup(itemToBeConsumed);
                    }

                    Tile tempt = new EmptyTile(gameMap._Hero.getX(), gameMap._Hero.getY());
                    gameMap._Hero.setX(gameMap._Hero.getX() + 1);
                    gameMap.Mymap[gameMap._Hero.getX(), gameMap._Hero.getY()]     = gameMap._Hero;
                    gameMap.Mymap[gameMap._Hero.getX() - 1, gameMap._Hero.getY()] = tempt; gameMap.UpdateVision(); isValid = true;
                }
                break;
            }

            return(isValid);
        }