private void swordInventory_Click(object sender, EventArgs e) { if (game.CheckPlayerInventory("Sword")) { game.Equip("Sword"); swordInventory.BorderStyle = BorderStyle.FixedSingle; bowInventory.BorderStyle = BorderStyle.None; bluePotionInventory.BorderStyle = BorderStyle.None; redPotionInventory.BorderStyle = BorderStyle.None; maceInventory.BorderStyle = BorderStyle.None; UpdateScroll(); } }
private void pictureBoxItemSword_Click(object sender, EventArgs e) { buttonAttackDown.Show(); buttonAttackLeft.Show(); buttonAttackRight.Show(); buttonAttackUp.Text = "↑"; if (_game.CheckPlayerInventory("Sword")) { _game.Equip("Sword"); SetAllPictureBoxBordersToNone(); pictureBoxItemSword.BorderStyle = BorderStyle.FixedSingle; } }
private void SelectInventoryItem(PictureBox itemSprite, string itemName, string weaponType) { if (game.CheckPlayerInventory(itemName)) { game.Equip(itemName); RemoveInventorySpriteBorders(); itemSprite.BorderStyle = BorderStyle.FixedSingle; SetupAttackButtons(weaponType); } }
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(); } } }
public void UpdateCharacters() { player.Location = game.PlayerLocation; playerHitPoints.Text = game.PlayerHitPoints.ToString(); bool showBat = false; bool showGhost = false; bool showGhoul = false; int enemiesShown = 0; // Check if enemies are still alive. If so, set their show variable to true. 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++; } } } //Sets visibility of enemy objects based on conditions above if (showBat == false) { bat.Visible = false; batHitPoints.Visible = false; batLabel.Visible = false; } else { bat.Visible = true; batHitPoints.Visible = true; batLabel.Visible = true; } if (showGhost == false) { ghost.Visible = false; ghostHitPoints.Visible = false; ghostLabel.Visible = false; } else { ghost.Visible = true; ghostHitPoints.Visible = true; ghostLabel.Visible = true; } if (showGhoul == false) { ghoul.Visible = false; ghoulHitPoints.Visible = false; ghoulLabel.Visible = false; } else { ghoul.Visible = true; ghoulHitPoints.Visible = true; ghoulLabel.Visible = false; } // Makes weapon icons invisible in game window 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 "Red Potion": weaponControl = redPotion; break; case "Blue Potion": weaponControl = bluePotion; break; case "Mace": weaponControl = mace; break; } weaponControl.Visible = true; //Setting intitial attack button text and visibility attackUp.Text = "↑"; attackRight.Visible = true; attackDown.Visible = true; attackLeft.Visible = true; //Setting weapon inventory visibility in game window if (game.CheckPlayerInventory("Sword")) { swordInventory.Visible = true; } else { swordInventory.Visible = false; } if (game.CheckPlayerInventory("Bow")) { bowInventory.Visible = true; } else { bowInventory.Visible = false; } if (game.CheckPlayerInventory("Mace")) { maceInventory.Visible = true; } else { maceInventory.Visible = false; } if (game.CheckPlayerInventory("Blue Potion")) { bluePotionInventory.Visible = true; } else { bluePotionInventory.Visible = false; } if (game.CheckPlayerInventory("Red Potion")) { redPotionInventory.Visible = true; } else { redPotionInventory.Visible = false; } weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.Visible = true; } if (game.PlayerHitPoints <= 0) { MessageBox.Show("You died"); Application.Exit(); } if (enemiesShown < 1 && game.Level < 8) { MessageBox.Show("You have defeated the enemies on this level"); game.NewLevel(random); UpdateCharacters(); } }
public void UpdateCharacters() { //Update player position and stats playerIcon.Location = game.PlayerLocation; playerHP.Text = game.PlayerHitPoints.ToString(); playerIcon.Visible = true; //Update enemies position and stats bool showBat = false; bool showGhost = false; bool showGhoul = false; int enemiesShown = 0; foreach (Enemy enemy in game.Enemies) { if (enemy is Bat) { batIcon.Location = enemy.Location; batHP.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showBat = true; enemiesShown++; } if (showBat) { batIcon.Visible = true; batLabel.Visible = true; batHP.Visible = true; } else { batIcon.Visible = false; batLabel.Visible = false; batHP.Visible = false; } } if (enemy is Ghost) { ghostIcon.Location = enemy.Location; ghostHP.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhost = true; enemiesShown++; } if (showGhost) { ghostIcon.Visible = true; ghostLabel.Visible = true; ghostHP.Visible = true; } else { ghostIcon.Visible = false; ghostLabel.Visible = false; ghostHP.Visible = false; } } if (enemy is Ghoul) { ghoulIcon.Location = enemy.Location; ghoulHP.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhoul = true; enemiesShown++; } if (showGhoul) { ghoulIcon.Visible = true; ghoulLabel.Visible = true; ghoulHP.Visible = true; } else { ghoulIcon.Visible = false; ghoulLabel.Visible = false; ghoulHP.Visible = false; } } } //Update pictureboxes for weapons swordIcon.Visible = false; bowIcon.Visible = false; maceIcon.Visible = false; bluePotionIcon.Visible = false; redPotionIcon.Visible = false; Control weaponControl = null; switch (game.WeaponInRoom.Name) { case "Sword": weaponControl = swordIcon; break; case "Bow": weaponControl = bowIcon; break; case "Mace": weaponControl = maceIcon; break; case "Blue Potion": weaponControl = bluePotionIcon; break; case "Red Potion": weaponControl = redPotionIcon; break; } weaponControl.Visible = true; //Set visibility for inventory options if (game.CheckPlayerInventory("Sword")) { weaponSword.Visible = true; } else { weaponSword.Visible = false; } if (game.CheckPlayerInventory("Bow")) { weaponBow.Visible = true; } else { weaponBow.Visible = false; } if (game.CheckPlayerInventory("Mace")) { weaponMace.Visible = true; } else { weaponMace.Visible = false; } if (game.CheckPlayerInventory("Blue Potion")) { weaponBluePotion.Visible = true; } else { weaponBluePotion.Visible = false; } if (game.CheckPlayerInventory("Red Potion")) { weaponRedPotion.Visible = true; } else { weaponRedPotion.Visible = false; } //See if player picked up weapon weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.Visible = true; } //Did player die? if (game.PlayerHitPoints <= 0) { MessageBox.Show("You died!"); Application.Exit(); } //Did player defeat enemies? if (enemiesShown < 1) { MessageBox.Show("You have defeated your enemies! Get ready for the next level!"); bool next = game.NewLevel(random); if (!next) { Application.Exit(); } else { UpdateCharacters(); } } }
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(); } }
public void UpdateCharacters() { //Update the player’s position and stats. playerIcon.Location = game.PlayerLocation; playerHitPoints.Text = game.PlayerHitPoints.ToString(); bool showBat = false; bool showGhost = false; bool showGhoul = false; int enemiesShown = 0; batHitPoints.Visible = false; batLabel.Visible = false; ghostHitPoints.Visible = false; ghostLabel.Visible = false; ghoulHitPoints.Visible = false; ghoulLabel.Visible = false; //Update each enemy’s location and hit points foreach (Enemy enemy in game.Enemies) { if (enemy is Bat) { batIcon.Location = enemy.Location; batHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showBat = true; enemiesShown++; } } if (enemy is Ghost) { ghostIcon.Location = enemy.Location; ghostHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhost = true; enemiesShown++; } } if (enemy is Ghoul) { ghoulIcon.Location = enemy.Location; ghoulHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhoul = true; enemiesShown++; } } } batHitPoints.Visible = showBat; batLabel.Visible = showBat; batIcon.Visible = showBat; ghostHitPoints.Visible = showGhost; ghostLabel.Visible = showGhost; ghostIcon.Visible = showGhost; ghoulHitPoints.Visible = showGhoul; ghoulLabel.Visible = showGhoul; ghoulIcon.Visible = showGhoul; //Update the weapon PictureBoxes swordIcon.Visible = false; bowIcon.Visible = false; redPotionIcon.Visible = false; bluePotionIcon.Visible = false; maceIcon.Visible = false; Control weaponControl = null; if (game.WeaponInRoom != null) { switch (game.WeaponInRoom.Name) { case "Sword": weaponControl = swordIcon; break; case "Bow": weaponControl = bowIcon; break; case "Mace": weaponControl = maceIcon; break; case "Red Potion": weaponControl = redPotionIcon; break; case "Blue Potion": weaponControl = bluePotionIcon; break; } } if (weaponControl != null) { weaponControl.Visible = true; } //Set the Visible property on each inventory icon PictureBox inventorySword.Visible = game.CheckPlayerInventory("Sword"); inventoryBow.Visible = game.CheckPlayerInventory("Bow"); inventoryMace.Visible = game.CheckPlayerInventory("Mace"); inventoryRedPotion.Visible = game.CheckPlayerInventory("Red Potion"); inventoryBluePotion.Visible = game.CheckPlayerInventory("Blue Potion"); if (game.CheckPlayerInventory("Sword") && game.PlayerWeapons.Count() == 1) { inventorySword.BorderStyle = BorderStyle.FixedSingle; } //The rest of the method does three things. First, it checks to see if the player’s already //picked up the weapon in the room, so it knows whether or not to display it. Then it //checks to see if the player died. And finally, it checks to see if the player’s defeated all of //the enemies. If he has, then the player advances to the next level. if (game.WeaponInRoom != null) { weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.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"); game.NewLevel(random); if (game.Level <= 7) { UpdateCharacters(); } } this.Text = "The Quest: level " + game.Level; }
private void UpdateCharacters() { player.Location = game.PlayerLocation; playerHitPoints.Text = game.PlayerHitPoints.ToString(); 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) { bat.Visible = true; enemiesShown++; } else { bat.Visible = false; batHitPoints.Text = "0"; } } if (enemy is Ghost) { ghost.Location = enemy.Location; ghostHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { ghost.Visible = true; enemiesShown++; } else { ghost.Visible = false; ghostHitPoints.Text = "0"; } } if (enemy is Gnoul) { gnoul.Location = enemy.Location; gnoulHitPoints.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { gnoul.Visible = true; enemiesShown++; } else { gnoul.Visible = false; gnoulHitPoints.Text = "0"; } } } 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 "Red Potion": weaponControl = redPotion; break; case "Blue Potion": weaponControl = bluePotion; break; case "Mace": weaponControl = mace; break; } if (game.CheckPlayerInventory("Sword")) { swordInv.Visible = true; } if (game.CheckPlayerInventory("Bow")) { bowInv.Visible = true; } if (game.CheckPlayerInventory("Red Potion")) { if ((game.CheckPotionInventory("Red Potion")) == false) { redPotionInv.Visible = true; } else { redPotionInv.Visible = false; } } if (game.CheckPlayerInventory("Blue Potion")) { if ((game.CheckPotionInventory("Blue Potion")) == false) { bluePotionInv.Visible = true; } else { RemovePotionFromInventory("Blue Potion"); } } if (game.CheckPlayerInventory("Mace")) { maceInv.Visible = true; } if (weaponControl != null) { weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.Visible = true; } } if (game.PlayerHitPoints <= 0) { MessageBox.Show("You died"); DialogResult playAgain = MessageBox.Show("Would you like to Play again", "Play Again", MessageBoxButtons.YesNo); if (playAgain == DialogResult.Yes) { Application.Restart(); } else { Application.Exit(); } } if (enemiesShown < 1) { MessageBox.Show("You have defeated the enemies on this level"); game.NewLevel(random); UpdateCharacters(); } }
private void UpdateCharacters() { player.Location = game.PlayerLocation; lblPlayerHitPoints.Text = game.PlayerHitPoints.ToString(); int enemiesShown = 0; bat.Visible = false; ghost.Visible = false; ghoul.Visible = false; lblBatHitPoints.Text = "0"; lblGhostHitPoints.Text = "0"; lblGhoulHitPoints.Text = "0"; foreach (Enemy enemy in game.Enemies) { if (enemy is Bat) { if (!enemy.Dead) { bat.Visible = true; bat.Location = enemy.Location; lblBatHitPoints.Text = enemy.HitPoints.ToString(); enemiesShown++; } else { bat.Visible = false; lblBatHitPoints.Text = "0"; } } if (enemy is Ghost) { if (!enemy.Dead) { ghost.Location = enemy.Location; ghost.Visible = true; lblGhostHitPoints.Text = enemy.HitPoints.ToString(); enemiesShown++; } else { ghost.Visible = false; lblGhostHitPoints.Text = "0"; } } if (enemy is Ghoul) { if (!enemy.Dead) { ghoul.Location = enemy.Location; ghoul.Visible = true; lblGhoulHitPoints.Text = enemy.HitPoints.ToString(); enemiesShown++; } else { ghoul.Visible = false; lblGhoulHitPoints.Text = "0"; } } } sword.Visible = false; bow.Visible = false; mace.Visible = false; bomb.Visible = false; redPotion.Visible = false; bluePotion.Visible = false; Control weaponControl = new Control(); switch (game.WeaponInRoom.Name) { case "Sword": weaponControl = sword; break; case "Bow": weaponControl = bow; break; case "Mace": weaponControl = mace; break; case "Bomb": weaponControl = bomb; break; case "Blue Potion": weaponControl = bluePotion; break; case "Red Potion": weaponControl = redPotion; break; default: break; } weaponControl.Visible = true; if (game.CheckPlayerInventory("Sword")) { inventorySwordPictureBox.Visible = true; } else { inventorySwordPictureBox.Visible = false; } if (game.CheckPlayerInventory("Bow")) { inventoryBowPictureBox.Visible = true; } else { inventoryBowPictureBox.Visible = false; } if (game.CheckPlayerInventory("Mace")) { inventoryMacePictureBox.Visible = true; } else { inventoryMacePictureBox.Visible = false; } if (game.CheckPlayerInventory("Bomb")) { inventoryBombPictureBox.Visible = true; } else { inventoryBombPictureBox.Visible = false; } if (game.CheckPlayerInventory("Blue Potion")) { inventoryBluePotionPictureBox.Visible = true; } else { inventoryBluePotionPictureBox.Visible = false; } if (game.CheckPlayerInventory("Red Potion")) { inventoryRedPotionPictureBox.Visible = true; } else { inventoryRedPotionPictureBox.Visible = false; } weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.Visible = true; } if (game.PlayerHitPoints <= 0) { MessageBox.Show("You died"); Application.Exit(); } if (enemiesShown < 1) { MessageBox.Show("You have defeated the enemy on this level"); game.NewLevel(random); UpdateCharacters(); } }
private void UpdateCharacters() { //Update player's position and stats player.Location = game.PlayerLocation; playerHP.Text = game.PlayerHitPoints.ToString(); bool showBat = false; bool showGhost = false; bool showGhoul = false; int enemyShown = 0; //Update enemy's positions and stats; foreach (Enemy enemy in game.Enemies) { if (enemy is Bat) { bat.Location = enemy.Location; batHP.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showBat = true; enemyShown++; } if (!showBat) { bat.Visible = false; batHP.Text = ""; } else { bat.Visible = true; } } if (enemy is Ghost) { ghost.Location = enemy.Location; ghostHP.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhost = true; enemyShown++; } if (!showGhost) { ghost.Visible = false; ghostHP.Text = ""; } else { ghost.Visible = true; } } if (enemy is Ghoul) { ghoul.Location = enemy.Location; ghoulHP.Text = enemy.HitPoints.ToString(); if (enemy.HitPoints > 0) { showGhoul = true; enemyShown++; } if (!showGhoul) { ghoul.Visible = false; ghoulHP.Text = ""; } else { ghoul.Visible = true; } } } //Update weapon's pictureboxes swordField.Visible = false; bowField.Visible = false; redPotionField.Visible = false; bluePotionField.Visible = false; maceField.Visible = false; Control weaponControl = null; if (game.WeaponInRoom != null) { switch (game.WeaponInRoom.Name) { case "Sword": weaponControl = swordField; break; case "Bow": weaponControl = bowField; break; case "Red Potion": weaponControl = redPotionField; break; case "Blue Potion": weaponControl = bluePotionField; break; case "Mace": weaponControl = maceField; break; default: break; } weaponControl.Visible = true; } swordInventory.Visible = false; bowInventory.Visible = false; bluePotionInventory.Visible = false; redPotionInventory.Visible = false; maceInventory.Visible = false; //Check inventory if (game.CheckPlayerInventory("Sword")) { swordInventory.Visible = true; } if (game.CheckPlayerInventory("Bow")) { bowInventory.Visible = true; } if (game.CheckPlayerInventory("Blue Potion")) { bluePotionInventory.Visible = true; } if (game.CheckPlayerInventory("Red Potion")) { redPotionInventory.Visible = true; } if (game.CheckPlayerInventory("Mace")) { maceInventory.Visible = true; } //Check if player's already picked up the weapon if (weaponControl != null) { weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.Visible = true; } } //Check if player died if (game.PlayerHitPoints <= 0) { MessageBox.Show("You died!", "Game over!"); Application.Exit(); } //Check for level up if (enemyShown < 1) { MessageBox.Show("You have defeated the enemies on this level"); game.NewLevel(random); MessageBox.Show("Level " + game.Level.ToString() + "!"); UpdateCharacters(); } }
private void UpdateWeaponsInventory() { 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("Bomb")) { inventoryBomb.Visible = true; } else { inventoryBomb.Visible = false; } if (game.CheckPlayerInventory("Shield")) { inventoryShield.Visible = true; } else { inventoryShield.Visible = false; } if (game.CheckPlayerInventory("Mace")) { inventoryMace.Visible = true; } else { inventoryMace.Visible = false; } if (game.CheckPlayerInventory("Battle Axe")) { inventoryBattleAxe.Visible = true; } else { inventoryBattleAxe.Visible = false; } if (game.CheckPlayerInventory("Quiver")) { inventoryQuiver.Visible = true; } else { inventoryQuiver.Visible = false; } if (game.CheckPlayerInventory("Blue Potion")) { inventoryPotionBlue.Visible = true; } else { inventoryPotionBlue.Visible = false; } if (game.CheckPlayerInventory("Red Potion")) { inventoryPotionRed.Visible = true; } else { inventoryPotionRed.Visible = false; } }
public void UpdateCharacters() { playerImage.Location = new Point(game.PlayerLocation.X - 25, game.PlayerLocation.Y - 25); playerHitPoints.Text = game.PlayerHitPoints.ToString(); playerImage.Visible = true; batHitPoints.Text = null; ghostHitPoints.Text = null; ghoulHitPoints.Text = null; bat.Visible = false; ghost.Visible = false; ghoul.Visible = false; bool showBat = false; bool showGhost = false; bool showGhoul = false; int enemiesShown = 0; foreach (Enemy enemy in game.Enemies) { if (enemy is Bat) { if (enemy.HitPoints > 0) { bat.Location = new Point(enemy.Location.X - 25, enemy.Location.Y - 25); batHitPoints.Text = enemy.HitPoints.ToString(); showBat = true; enemiesShown++; } } if (enemy is Ghost) { if (enemy.HitPoints > 0) { ghost.Location = new Point(enemy.Location.X - 25, enemy.Location.Y - 25); ghostHitPoints.Text = enemy.HitPoints.ToString(); showGhost = true; enemiesShown++; } } if (enemy is Ghoul) { if (enemy.HitPoints > 0) { ghoul.Location = new Point(enemy.Location.X - 25, enemy.Location.Y - 25); ghoulHitPoints.Text = enemy.HitPoints.ToString(); showGhoul = true; enemiesShown++; } } if (showBat) { bat.Visible = true; } if (showGhost) { ghost.Visible = true; } if (showGhoul) { 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 "Bow": weaponControl = bow; break; case "Red Potion": weaponControl = redPotion; break; case "Blue Potion": weaponControl = bluePotion; break; case "Mace": weaponControl = mace; break; } weaponControl.Location = new Point(weaponControl.Location.X - 25, weaponControl.Location.Y - 25); weaponControl.Visible = true; swordItem.Visible = false; bowItem.Visible = false; maceItem.Visible = false; bluePotionItem.Visible = false; redPotionItem.Visible = false; if (game.CheckPlayerInventory("Sword")) { swordItem.Visible = true; } if (game.CheckPlayerInventory("Bow")) { bowItem.Visible = true; } if (game.CheckPlayerInventory("Mace")) { maceItem.Visible = true; } if (game.CheckPlayerInventory("Blue Potion")) { bluePotionItem.Visible = true; } if (game.CheckPlayerInventory("Red Potion")) { redPotionItem.Visible = true; } weaponControl.Location = game.WeaponInRoom.Location; if (game.WeaponInRoom.PickedUp) { weaponControl.Visible = false; } else { weaponControl.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"); game.NewLevel(random); UpdateCharacters(); } }