public void UpdateCharacters() { // update the player's position and stats player.Visible = true; player.Location = game.PlayerLocation; playerHitPoints.Text = game.PlayerHitPoints.ToString(); // update enemy's location and hit points. bool showBat = false; bool showGhost = false; bool showGhoul = false; int enemiesShown = 0; foreach (Enemy enemy in game.Enemies) { if (enemy is Bat) { batPic.Location = enemy.Location; batHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showBat = true; enemiesShown++; } } if (enemy is Ghost) { ghostPic.Location = enemy.Location; ghostHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhost = true; enemiesShown++; } } if (enemy is Ghoul) { ghoulPic.Location = enemy.Location; ghoulHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhoul = true; enemiesShown++; } } } if (showBat) { batPic.Visible = true; } else { batPic.Visible = false; } if (showGhost) { ghostPic.Visible = true; } else { ghostPic.Visible = false; } if (showGhoul) { ghoulPic.Visible = true; } else { ghoulPic.Visible = false; } // update weaponInRoom' picturebox 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 "Bow": weaponControl = bow; break; case "Mace": weaponControl = mace; break; case "Blue Potion": weaponControl = bluePotion; break; case "Red Potion": weaponControl = redPotion; break; } weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.Visible = true; } //check inventory picturebox if (game.CheckPlayerInventory("Sword")) { inventorySword.Visible = true; } else { inventorySword.Visible = false; } if (game.CheckPlayerInventory("Bow")) { inventoryBow.Visible = true; } else { inventoryBow.Visible = false; } if (game.CheckPlayerInventory("Mace")) { inventoryMace.Visible = true; } else { inventoryMace.Visible = false; } if (game.CheckPlayerInventory("Blue Potion")) { inventoryBluePotion.Visible = true; } else { inventoryBluePotion.Visible = false; } if (game.CheckPlayerInventory("Red Potion")) { inventoryRedPotion.Visible = true; } else { inventoryRedPotion.Visible = false; } switch (game.EquipWeapon()) { case "Sword": inventorySword.BorderStyle = BorderStyle.FixedSingle; break; case "Bow": inventoryBow.BorderStyle = BorderStyle.FixedSingle; break; case "Mace": inventoryMace.BorderStyle = BorderStyle.FixedSingle; break; case "Blue Potion": inventoryBluePotion.BorderStyle = BorderStyle.FixedSingle; break; case "Red Potion": inventoryRedPotion.BorderStyle = BorderStyle.FixedSingle; break; } //update attack button if ((inventoryBluePotion.BorderStyle == BorderStyle.FixedSingle) && inventoryBluePotion.Visible == true) { attackUp.Text = "Drink"; attackRight.Visible = false; attackLeft.Visible = false; attackDown.Visible = false; } else { attackUp.Text = "↑"; attackRight.Visible = true; attackLeft.Visible = true; attackDown.Visible = true; } if (game.PlayerHitPoints <= 0) { timer1.Stop(); MessageBox.Show("You died!"); Application.Exit(); } if (enemiesShown < 1) { timer1.Stop(); MessageBox.Show("You have defeated the enemies on this level"); game.NewLevel(random); this.Text = "The Quest - Level " + game.Level; timer1.Start(); UpdateCharacters(); } }