Пример #1
0
        public void UpdateCharacters()
        {
            Player.Location      = game.PlayerLocation;
            playerHitPoints.Text = game.PlayerHitPoints.ToString();

            bool showBat      = false;
            bool showGhost    = false;
            bool showGhoul    = false;
            int  enemiesShown = 0;

            foreach (Enemy enemy in game.Enemies)
            {
                if (enemy is Bat)
                {
                    bat.Location      = enemy.Location;
                    batHitPoints.Text = enemy.HitPoints.ToString();
                    if (enemy.HitPoints > 0)
                    {
                        showBat = true;
                        enemiesShown++;
                    }
                }
                if (enemy is Ghost)
                {
                    ghost.Location      = enemy.Location;
                    ghostHitPoints.Text = enemy.HitPoints.ToString();
                    if (enemy.HitPoints > 0)
                    {
                        showGhost = true;
                        enemiesShown++;
                    }
                }
                if (enemy is Ghoul)
                {
                    ghoul.Location      = enemy.Location;
                    ghoulHitPoints.Text = enemy.HitPoints.ToString();
                    if (enemy.HitPoints > 0)
                    {
                        showGhoul = true;
                        enemiesShown++;
                    }
                }
            }

            if (!showBat)
            {
                bat.Visible       = false;
                batHitPoints.Text = "";
            }
            else
            {
                bat.Visible = true;
            }

            if (!showGhost)
            {
                ghost.Visible       = false;
                ghostHitPoints.Text = "";
            }
            else
            {
                ghost.Visible = true;
            }

            if (!showGhoul)
            {
                ghoul.Visible       = false;
                ghoulHitPoints.Text = "";
            }
            else
            {
                ghoul.Visible = true;
            }

            sword.Visible      = false;
            bow.Visible        = false;
            redPotion.Visible  = false;
            bluePotion.Visible = false;
            mace.Visible       = false;
            Control weaponControl = null;

            switch (game.WeaponInRoom.Name)
            {
            case "Sword":
                weaponControl = sword; break;

            case "Blue Potion":
                weaponControl = bluePotion; break;

            case "Bow":
                weaponControl = bow; break;

            case "Red Potion":
                weaponControl = redPotion; break;

            case "Mace":
                weaponControl = mace; break;

            default:
                break;
            }
            weaponControl.Location = game.WeaponInRoom.Location;
            if (game.WeaponInRoom.PickedUp)
            {
                weaponControl.Visible = false;
            }
            else
            {
                weaponControl.Visible = true;
            }

            if (game.CheckPlayerInventory("Sword"))
            {
                swordIcon.Visible = true;
                if (!game.IsEquippedWeaponNull())
                {
                    if (game.GetEquippedWeaponName() == "Sword")
                    {
                        swordIcon.BorderStyle = BorderStyle.FixedSingle;
                    }
                }
            }

            if (game.CheckPlayerInventory("Blue Potion"))
            {
                bluePotionIcon.Visible = true;
            }
            else
            {
                bluePotionIcon.Visible = false;
            }

            if (game.CheckPlayerInventory("Bow"))
            {
                bowIcon.Visible = true;
            }

            if (game.CheckPlayerInventory("Red Potion"))
            {
                redPotionIcon.Visible = true;
            }
            else
            {
                redPotionIcon.Visible = false;
            }

            if (game.CheckPlayerInventory("Mace"))
            {
                maceIcon.Visible = true;
            }

            if (game.PlayerHitPoints <= 0)
            {
                MessageBox.Show("You died");
                Application.Exit();
            }

            if (enemiesShown < 1)
            {
                MessageBox.Show("You have defeated the enemies on this level");
                if (game.Level > 6)
                {
                    Application.Exit();
                }
                else
                {
                    game.NewLevel(random);
                    UpdateCharacters();
                }
            }
        }