Ejemplo n.º 1
0
        public Room(int width, int height, int[] exitPos, bool exitOpen, int coinCount, int[,] coinPos,
            int enemyCount, List<Enemy> enemies, List<GameItem> items, Boss boss, Shopkeeper shopkeeper)
        {
            this.width = width;
            this.height = height;
            this.exitPos = exitPos;
            this.exitOpen = exitOpen;
            this.coinCount = coinCount;
            this.coinPos = coinPos;
            this.enemyCount = enemyCount;
            this.enemies = enemies;
            this.items = items;
            this.boss = boss;
            this.shopkeeper = shopkeeper;

            map = new char[height, (width + 1)];

            if (boss != null)
            {
                boss.y = 2;
                boss.x = (width - 1) / 2;
            }

            if (shopkeeper != null)
            {
                shopkeeper.y = 2;
                shopkeeper.x = (width - 1) / 2;
            }
        }
Ejemplo n.º 2
0
        public bool Update(Player player)
        {
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width + 1; x++)
                {
                    if (x == width)
                        map[y, x] = '\n';
                    else if (x == 0 || x == width - 1 || y == 0 || y == height - 1)
                        map[y, x] = '#';
                    else map[y, x] = '=';
                }
            }

            for (int i = 0; i < coinPos.GetLength(0); i++ )
            {
                if (player.y == coinPos[i, 0] && player.x == coinPos[i, 1])
                {
                    coinPos[i, 0] = 0;
                    coinPos[i, 1] = 0;

                    player.gold += (int)Math.Ceiling(player.level / 2.0);
                }

                if (!(coinPos[i, 0] == 0 && coinPos[i, 1] == 0))
                    map[coinPos[i, 0], coinPos[i, 1]] = 'c';

            }

            if (exitOpen)
            {
                map[exitPos[0], exitPos[1]] = '█';

                if (exitPos[0] == player.y && exitPos[1] == player.x)
                    return true;
            }

            List<Enemy> deadEnemies = new List<Enemy>();
            List<GameItem> collectedItems = new List<GameItem>();

            foreach (GameItem item in items)
            {
                map[item.y, item.x] = item.ToChar();

                if (item.x == player.x && item.y == player.y)
                {
                    player.inventory.Add(item);
                    collectedItems.Add(item);
                }
            }

            foreach (Enemy e in enemies)
            {
                e.Update(player);
                map[e.y, e.x] = e.ToChar();

                if (e.y == player.y && e.x == player.x)
                {
                    BattleScreen battle = new BattleScreen(player, e);
                    if (battle.DoBattle())
                        deadEnemies.Add(e);
                    else Environment.Exit(0);
                }
            }

            foreach (GameItem i in collectedItems)
            {
                items.Remove(i);
            }

            foreach (Enemy e in deadEnemies)
            {
                enemies.Remove(e);
            }

            if (shopkeeper != null)
            {
                map[shopkeeper.y, shopkeeper.x] = shopkeeper.ToChar();

                if (player.x == shopkeeper.x && player.y == shopkeeper.y)
                {
                    shopkeeper.Shop(player);
                    player.y++;
                }
            }

            if (boss != null)
            {
                map[boss.y, boss.x] = boss.ToChar();

                if (player.x == boss.x && player.y == boss.y)
                {
                    BattleScreen battle = new BattleScreen(player, boss);
                    if (battle.DoBattle())
                    {
                        player.y++;
                        exitOpen = true;
                        map[boss.y, boss.x] = boss.itemDrop.ToChar();
                        boss.itemDrop.x = boss.x;
                        boss.itemDrop.y = boss.y;
                        items.Add(boss.itemDrop);
                        boss = null;
                    }
                    else Environment.Exit(0);
                }
            }

            map[player.y, player.x] = '@';

            return false;
        }
Ejemplo n.º 3
0
        public Room(int width, int height, Boss boss)
        {
            random = new Random();

            this.width = width;
            this.height = height;
            this.coinCount = 0;
            this.enemyCount = 0;

            exitOpen = false;

            enemies = new List<Enemy>();
            items = new List<GameItem>();

            this.boss = boss;

            map = new char[height, (width + 1)];
            coinPos = new int[coinCount, 2];

            exitPos = new int[2] { height - 2, (width - 1) / 2 };

            boss.y = 2;
            boss.x = (width - 1) / 2;
        }