Example #1
0
 private char getRepresentation(userTileClass type)
 {
     if (type is emptyUserTileClass)
     {
         return('.');
     }
     else if (type is HeroClass)
     {
         if (ge.getMap().provideHero().died())
         {
             return('.');
         }
         else
         {
             return('H');
         }
     }
     else if (type is GoblinClass)
     {
         return('G');
     }
     else if (type is MagesClass)
     {
         return('M');
     }
     else if (type is GoldClass)
     {
         return('$');
     }
     else
     {
         return('X');
     }
 }
        public void MapRemoval(userTileClass character)


        {
            if (character.getTileType() == userTileClass.tileType.Enemy)
            {
                EnemyClass[] new_list = new EnemyClass[userEnemies.Length - 1];
                int          index    = 0;

                for (int i = 0; i < userEnemies.Length; ++i)
                {
                    if (userEnemies[i].died())
                    {
                        map[userEnemies[i].getY(), userEnemies[i].getX()] = new emptyUserTileClass(userEnemies[i].getY(), userEnemies[i].getX());
                    }
                    else
                    {
                        new_list[index] = userEnemies[i];
                        ++index;
                    }
                }

                userEnemies = new_list;
                updateVision();
            }
        }
        public void findCharacterPosition(userTileClass character, CharacterClass.Movement direction)


        {
            CharacterClass     c = (CharacterClass)map[character.getY(), character.getX()];
            emptyUserTileClass emp;

            switch (direction)

            {
            case CharacterClass.Movement.MoveUp:
                emp = (emptyUserTileClass)map[c.getY() - 1, c.getX()];
                map[c.getY() - 1, c.getX()] = c;
                map[c.getY(), c.getX()]     = emp;
                c.Move(CharacterClass.Movement.MoveUp);
                emp.setY(emp.getY() + 1);
                break;

            case CharacterClass.Movement.MoveDown:
                emp = (emptyUserTileClass)map[c.getY() + 1, c.getX()];
                map[c.getY() + 1, c.getX()] = c;
                map[c.getY(), c.getX()]     = emp;
                c.Move(CharacterClass.Movement.MoveDown);
                emp.setY(emp.getY() - 1);
                break;

            case CharacterClass.Movement.MoveLeft:
                emp = (emptyUserTileClass)map[c.getY(), c.getX() - 1];
                map[c.getY(), c.getX() - 1] = c;
                map[c.getY(), c.getX()]     = emp;
                c.Move(CharacterClass.Movement.MoveLeft);
                emp.setX(emp.getX() + 1);
                break;

            case CharacterClass.Movement.MoveRight:
                emp = (emptyUserTileClass)map[c.getY(), c.getX() + 1];
                map[c.getY(), c.getX() + 1] = c;
                map[c.getY(), c.getX()]     = emp;
                c.Move(CharacterClass.Movement.MoveRight);
                emp.setX(emp.getX() - 1);
                break;
            }

            this.updateVision();
        }
        private userTileClass[] returnVision(int x, int y)



        {
            userTileClass[] characterVision = new userTileClass[8];

            characterVision[0] = map[y - 1, x];
            characterVision[1] = map[y + 1, x];
            characterVision[2] = map[y, x - 1];
            characterVision[3] = map[y, x + 1];
            characterVision[4] = map[y - 1, x + 1];
            characterVision[5] = map[y + 1, x + 1];
            characterVision[6] = map[y + 1, x - 1];
            characterVision[7] = map[y - 1, x - 1];

            return(characterVision);
        }
        public string userAttacksEnemy(CharacterClass h, CharacterClass.Movement dir, userTileClass t)
        {
            userTileClass target = new emptyUserTileClass(0, 0);

            switch (dir)
            {
            case CharacterClass.Movement.MoveUp:
                target = map.provideMap()[h.getY() - 1, h.getX()];
                break;

            case CharacterClass.Movement.MoveDown:
                target = map.provideMap()[h.getY() + 1, h.getX()];
                break;

            case CharacterClass.Movement.MoveLeft:
                target = map.provideMap()[h.getY(), h.getX() - 1];
                break;

            case CharacterClass.Movement.MoveRight:
                target = map.provideMap()[h.getY(), h.getX() + 1];
                break;

            default:
                target = t;
                break;
            }


            if ((h is HeroClass && target is EnemyClass && !h.died()) || (h is GoblinClass && target is HeroClass) || (h is MagesClass && target is CharacterClass))
            {
                h.Attack((CharacterClass)target);
                CharacterClass c_target = (CharacterClass)target;

                if (c_target.died())
                {
                    map.MapRemoval(c_target);
                }


                if (h is HeroClass)
                {
                    enemyAttackedUser();
                    if (!c_target.died())
                    {
                        return("1" + c_target.ToString());
                    }
                    else
                    {
                        return("The enemy is dead");
                    }
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("0");
            }
        }