Ejemplo n.º 1
0
        public String attackEnemy(Character.Movement dir)
        {
            Hero h      = map.getHero();
            Tile target = new EmptyTile(0, 0); // Set as an empty tile for placeholding

            switch (dir)
            {
            case Character.Movement.Up:
                target = map.getMap()[h.getY() - 1, h.getX()];
                break;

            case Character.Movement.Down:
                target = map.getMap()[h.getY() + 1, h.getX()];
                break;

            case Character.Movement.Left:
                target = map.getMap()[h.getY(), h.getX() - 1];
                break;

            case Character.Movement.Right:
                target = map.getMap()[h.getY(), h.getX() + 1];
                break;
            }

            if (target is Enemy)
            {
                h.attack((Character)target);
                Character c_target = (Character)target;

                if (c_target.isDead())
                {
                    map.removeFromMap(c_target);
                }

                moveEnemies();

                if (!c_target.isDead())
                {
                    return("1" + c_target.ToString());     //Returning 1 infront of string indicates success
                }
                else
                {
                    return("1The enemy is dead");
                }
            }
            else
            {
                return("0");                         //Returning 0 infront of string indicates failure
            }
        }
Ejemplo n.º 2
0
        // Q 3.2
        public Map(int minHeight, int maxHeight, int minWidth, int maxWidth, int numEnemies)
        {
            int height = rand.Next(minHeight, maxHeight);
            int width  = rand.Next(minWidth, maxWidth);

            gameMap = new Tile[width, height];

            this.height = height;
            this.width  = width;

            enemies = new Enemy[numEnemies];

            // fill game map with empty tiles
            for (int i = 0; i < gameMap.GetLength(0); i++)
            {
                for (int j = 0; j < gameMap.GetLength(1); j++)
                {
                    gameMap[i, j] = new EmptyTile(i, j);
                }
            }

            // border map with obstacles
            for (int x = 0; x < gameMap.GetLength(0); x++)
            {
                // Left Row
                gameMap[x, 0] = new Obstacle(x, 0);
                // Right Row
                gameMap[x, gameMap.GetLength(1) - 1] = new Obstacle(x, gameMap.GetLength(1) - 1);
            }

            for (int y = 0; y < gameMap.GetLength(1); y++)
            {
                // Top Row
                gameMap[0, y] = new Obstacle(0, y);
                // Bottom Row
                gameMap[gameMap.GetLength(0) - 1, y] = new Obstacle(gameMap.GetLength(0) - 1, y);
            }

            Create(TileType.Hero);

            for (int z = 0; z < enemies.Length; z++)
            {
                enemies[z] = (Enemy)Create(TileType.Enemy);
            }

            UpdateVision();
        }
Ejemplo n.º 3
0
 private void generateEmptyMap()
 {
     for (int i = 0; i < height; ++i)
     {
         for (int j = 0; j < width; ++j)
         {
             if (i == 0 || i == (height - 1))
             {
                 map[i, j] = new Obstacle(i, j);
             }
             else if (j == 0 || j == (width - 1))
             {
                 map[i, j] = new Obstacle(i, j);
             }
             else
             {
                 map[i, j] = new EmptyTile(i, j);
             }
         }
     }
 }
Ejemplo n.º 4
0
        public String attackEnemy(Character h, Character.Movement dir, int range, Tile t)
        {
            Tile target = new EmptyTile(0, 0); // Set as an empty tile for placeholding

            if (h is Hero && h.getWeapon() != null)
            {
                if ((range + 1) > h.getWeapon().getRange())
                {
                    return("0");
                }
            }
            else if (h is Hero && h.getWeapon() == null)
            {
                if (range != 0)
                {
                    return("0");
                }
            }

            try
            {
                switch (dir)
                {
                case Character.Movement.Up:
                    target = map.getMap()[h.getY() - 1 - range, h.getX()];
                    break;

                case Character.Movement.Down:
                    target = map.getMap()[h.getY() + 1 + range, h.getX()];
                    break;

                case Character.Movement.Left:
                    target = map.getMap()[h.getY(), h.getX() - 1 - range];
                    break;

                case Character.Movement.Right:
                    target = map.getMap()[h.getY(), h.getX() + 1 + range];
                    break;

                default:
                    target = t;
                    break;
                }
            }
            catch (Exception e)
            {
                return("0");
            }

            //Goblins only harm heroes
            //Mages harm the hero, goblins and other mages
            if ((h is Hero && target is Enemy && !h.isDead()) || (h is Goblin && target is Hero) || (h is Leader && target is Hero) || (h is Mage && target is Character))
            {
                h.attack((Character)target);
                Character c_target = (Character)target;
                string    loot     = "";

                if (c_target.isDead())
                {
                    loot = h.loot(c_target, h is Mage);
                    map.removeFromMap(c_target);
                }


                if (h is Hero)
                {
                    //moveEnemies();                        //Enemies no longer move after being attacked
                    damage_taken = enemyAttacks();                         //Enemies now attack after the player attacks
                    if (!c_target.isDead())
                    {
                        return("1" + c_target.ToString());   //Returning 1 infront of string indicates success
                    }
                    else
                    {
                        return("1The enemy is dead" + loot);
                    }
                }
                else if (c_target is Hero)
                {
                    return("hero" + h.getDamage());
                }
                else if (!c_target.isDead())
                {
                    return("enemy");
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("0");                         //Returning 0 infront of string indicates failure
            }
        }
Ejemplo n.º 5
0
        public String attackEnemy(Character h, Character.Movement dir, Tile t)
        {
            Tile target = new EmptyTile(0, 0); // Set as an empty tile for placeholding

            switch (dir)
            {
            case Character.Movement.Up:
                target = map.getMap()[h.getY() - 1, h.getX()];
                break;

            case Character.Movement.Down:
                target = map.getMap()[h.getY() + 1, h.getX()];
                break;

            case Character.Movement.Left:
                target = map.getMap()[h.getY(), h.getX() - 1];
                break;

            case Character.Movement.Right:
                target = map.getMap()[h.getY(), h.getX() + 1];
                break;

            default: target = t;
                break;
            }

            //Goblins only harm heroes
            //Mages harm the hero, goblins and other mages
            if ((h is Hero && target is Enemy && !h.isDead()) || (h is Goblin && target is Hero) || (h is Mage && target is Character))
            {
                h.attack((Character)target);
                Character c_target = (Character)target;

                if (c_target.isDead())
                {
                    map.removeFromMap(c_target);
                }


                if (h is Hero)
                {
                    //moveEnemies();                        //Enemies no longer move after being attacked
                    damage_taken = enemyAttacks();                         //Enemies now attack after the player attacks
                    if (!c_target.isDead())
                    {
                        return("1" + c_target.ToString());   //Returning 1 infront of string indicates success
                    }
                    else
                    {
                        return("1The enemy is dead");
                    }
                }
                else if (c_target is Hero)
                {
                    return("hero" + h.getDamage());
                }
                else if (!c_target.isDead())
                {
                    return("enemy");
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("0");                         //Returning 0 infront of string indicates failure
            }
        }