Exemplo n.º 1
0
        public void Start()
        {
            while (true)
            {
                if (ResetGame)
                {
                    ResetGame = false;
                    startMenu = new Menu();
                }

                EngineFunctions.GetScreenBuffer();
                DrawScreen();
                EngineFunctions.DrawToBuffer();

                if (startMenu != null)
                {
                    int sel = startMenu.UpdateMenu();
                    switch (sel)
                    {
                    case 0:
                        startMenu = null;
                        LoadGame();
                        break;

                    case 1:
                        LoadSaveGame(startMenu.GetSelection());
                        startMenu = null;
                        break;

                    case 2:
                        startMenu = null;
                        Program.CloseGame();
                        break;
                    }
                }
                else
                {
                    if (gameOver)
                    {
                    }
                    else
                    {
                        if (player.ShouldSave)
                        {
                            SaveGame(player.SaveSlot);
                            player.ShouldSave = false;
                        }

                        if (inShop)
                        {
                            #region Shop Stuff
                            if (mapRoomTransition != FaceDirection.noDir)
                            {
                                player.PlaceInMapAfterShop(new EngineFunctions.COORD((short)(shop.location.X + 2), (short)(shop.location.Y + 4)));
                                inShop             = false;
                                shop.IsShopVisible = false;
                                shop.CanBuy        = true;
                            }
                            if (shop.CanBuy)
                            {
                                if (player.location.X == 31 && player.location.Y == 11)
                                {
                                    if (hud.Money >= shop.GetPrice(shop.itemsForSale[0]))
                                    {
                                        BuyItem(0);
                                        shop.CanBuy = false;
                                    }
                                }
                                else if (player.location.X == 41 && player.location.Y == 11)
                                {
                                    if (hud.Money >= shop.GetPrice(shop.itemsForSale[1]))
                                    {
                                        BuyItem(1);
                                        shop.CanBuy = false;
                                    }
                                }
                                else if (player.location.X == 51 && player.location.Y == 11)
                                {
                                    if (hud.Money >= shop.GetPrice(shop.itemsForSale[2]))
                                    {
                                        BuyItem(2);
                                        shop.CanBuy = false;
                                    }
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region Items
                            int rIndex = -1;
                            for (int item = 0; item < itemsOnMap.Count; item++)
                            {
                                if (player.location.Equals(itemsOnMap[item].Location))
                                {
                                    if (itemsOnMap[item].IType == ItemType.Sphere)
                                    {
                                        hud.Spheres.Add(Map.CurLevelInfo.Key);
                                        player.CurHP = player.HP;
                                        //new level
                                        levelTransition   = true;
                                        endLevelParticles = new ParticleHandler(Map.CurLevelInfo.Value);
                                        endLevelParticles.SpawnParticles();
                                    }
                                    else
                                    {
                                        hud.AddItem(itemsOnMap[item].IType);
                                        if (itemsOnMap[item].IType == ItemType.Heart)
                                        {
                                            if (player.CurHP + 4 > player.HP)
                                            {
                                                player.CurHP = player.HP;
                                            }
                                            else
                                            {
                                                player.CurHP += 4;
                                            }
                                        }
                                    }
                                    rIndex = item;
                                    break;
                                }
                            }
                            if (rIndex >= 0)
                            {
                                itemsOnMap.RemoveAt(rIndex);
                                rIndex = -1;
                            }
                            #endregion

                            #region Enemies
                            enemies = m.getRoom().enemies;
                            foreach (Enemy enemy in enemies)
                            {
                                if (enemy.HP <= 0)
                                {
                                    if (enemy.enemytype == EType.Dragon)
                                    {
                                        itemsOnMap.Add(new Item(ItemType.Sphere, enemy.loc));
                                    }
                                    else if (enemies.Count == 1)
                                    {
                                        itemsOnMap.Add(new Item(ItemType.Key, enemy.loc));
                                    }
                                    else
                                    {
                                        int i = rand.Next(0, 100);
                                        if (i >= 20)
                                        {
                                            i = rand.Next(0, 100);
                                            if (i > 80)
                                            {
                                                itemsOnMap.Add(new Item(ItemType.Heart, enemy.loc));
                                            }
                                            else if (i > 35)
                                            {
                                                itemsOnMap.Add(new Item(ItemType.Crystal, enemy.loc));
                                            }
                                            else if (i > 30)
                                            {
                                                itemsOnMap.Add(new Item(ItemType.Key, enemy.loc));
                                            }
                                            else if (i > 10)
                                            {
                                                itemsOnMap.Add(new Item(ItemType.Magic, enemy.loc));
                                            }
                                            else
                                            {
                                                itemsOnMap.Add(new Item(ItemType.Bomb, enemy.loc));
                                            }
                                        }
                                    }
                                    enemy.Killed();
                                    enemies.Remove(enemy);
                                    break;
                                }
                            }
                            m.getRoom().enemies = enemies;
                            #endregion

                            #region Collision Checking
                            CheckEnemyCollision();
                            if (player.TookDamage)
                            {
                                player.TookDamage = false;
                                hud.ClearHealth(player.HP);
                                hud.DrawHealth(player.CurHP);
                            }
                            #endregion

                            #region Change Rooms
                            if (mapRoomTransition != FaceDirection.noDir)
                            {
                                m.MoveToNextRoom(mapRoomTransition);
                                player.PlaceInNextRoom(mapRoomTransition);
                                shop.ShowShop(player.Sword, player.HP);
                                itemsOnMap.Clear();

                                Room r = m.getRoom();
                                if (!r.IsExplored)
                                {
                                    r.IsExplored = true;
                                    RoomsExplored++;
                                }
                                if (RoomsExplored == m.GetRoomCount())
                                {
                                    r.enemies.Add(new Enemy(EType.Dragon));
                                }
                                m.SetRoom(r);
                            }
                            #endregion

                            #region Enter Shop
                            if (shop.IsShopVisible &&
                                player.location.Equals(new EngineFunctions.COORD((short)(shop.location.X + 2), (short)(shop.location.Y + 3))))
                            {
                                inShop = true;
                                player.PlaceInMapAfterShop(new EngineFunctions.COORD((short)(Console.WindowWidth / 2), 20));
                            }
                            #endregion

                            #region Unlock Door
                            if (player.UseKey)
                            {
                                if (hud.Keys > 0)
                                {
                                    hud.Keys--;
                                    player.UseKey = false;
                                    if (player.location.X == 1)
                                    {
                                        m.UnlockDoor(new Tuple <EngineFunctions.COORD, EngineFunctions.COORD>(
                                                         m.roomLocation,
                                                         new EngineFunctions.COORD((short)(m.roomLocation.X - 1), m.roomLocation.Y)));
                                    }
                                    else if (player.location.X == Console.WindowWidth - 2)
                                    {
                                        m.UnlockDoor(new Tuple <EngineFunctions.COORD, EngineFunctions.COORD>(
                                                         m.roomLocation,
                                                         new EngineFunctions.COORD((short)(m.roomLocation.X + 1), m.roomLocation.Y)));
                                    }
                                    else if (player.location.Y == 1)
                                    {
                                        m.UnlockDoor(new Tuple <EngineFunctions.COORD, EngineFunctions.COORD>(
                                                         m.roomLocation,
                                                         new EngineFunctions.COORD(m.roomLocation.X, (short)(m.roomLocation.Y - 1))));
                                    }
                                    else if (player.location.Y == Console.WindowHeight - 11)
                                    {
                                        m.UnlockDoor(new Tuple <EngineFunctions.COORD, EngineFunctions.COORD>(
                                                         m.roomLocation,
                                                         new EngineFunctions.COORD(m.roomLocation.X, (short)(m.roomLocation.Y + 1))));
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    player.UpdatePlayer(ref enemies, out mapRoomTransition, m.GetLockedDoors());
                }
            }
        }