public void UpdateCharacters() { player.Location = game.PlayerLocation; if (game.MaxPlayerHitPoints != 0) { playerHitPoints.Value = 100 * game.PlayerHitPoints / game.MaxPlayerHitPoints; } List <PictureBox> weaponList = new List <PictureBox>() { ListBow, ListSword, ListMace, ListBluePotion, ListRedPotion, }; int enemiesShown = 0; foreach (Enemy enemy in game.Enemies) { PictureBox picturebox = GetPictureBox(enemy); ProgressBar progressBar = GetProgressBar(enemy); if (enemy.Alive) { picturebox.Location = enemy.Location; picturebox.Visible = true; picturebox.Enabled = true; if (enemy.MaxHitPoints != 0) { progressBar.Value = 100 * enemy.HitPoints / enemy.MaxHitPoints; } enemiesShown++; } else { picturebox.Visible = false; picturebox.Enabled = false; progressBar.Value = 0; } } Control weaponControl = GetPictureBox(game.WeaponInRoom); weaponControl.Visible = true; if (game.CheckPlayerInventory <Sword>()) { ListSword.Visible = true; } if (game.CheckPlayerInventory <Bow>()) { ListBow.Visible = true; } if (game.CheckPlayerInventory <Mace>()) { ListMace.Visible = true; } if (game.CheckPlayerInventory <BluePotion>()) { ListBluePotion.Visible = true; } else { ListBluePotion.Visible = false; } if (game.CheckPlayerInventory <RedPotion>()) { ListRedPotion.Visible = true; } else { ListRedPotion.Visible = false; } foreach (PictureBox picturebox in weaponList) { picturebox.BorderStyle = BorderStyle.None; } if (game.EquippedWeapon != null) { PictureBox weaponEquipped = GetListPictureBox(game.EquippedWeapon); weaponEquipped.BorderStyle = BorderStyle.FixedSingle; } weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.Visible = true; } if (game.PlayerHitPoints <= 0)//玩家死后 { timer1.Enabled = false; MessageBox.Show("You Died"); Application.Exit(); } if (enemiesShown < 1)//打倒所有敌人后 { timer1.Enabled = false; MessageBox.Show("You have defeated the enemies on this level"); weaponControl.Visible = false; if (!game.NewLevel(random)) { Application.Exit(); } else { timer1.Enabled = true; UpdateCharacters(); } } }
private void Form1_Load(object sender, EventArgs e) { game = new Game(new Rectangle(78, 57, 420, 155)); game.NewLevel(random); UpdateCharacters(); }