Question: my code is below. for some reason I keep getting an exception unhandled on my DidWeWin method when I run my code and I absolutely
my code is below. for some reason I keep getting an exception unhandled on my DidWeWin method when I run my code and I absolutely cannot figure out why
namespace InClassProject { /* Chris Morris CPT-230-W01 1/30/21 */ public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { HeroTurn(); }
private void HeroTurn() { int villianHP = GetVillianHP(); int villianDEF = Convert.ToInt32(lblVillianDEF.Text); int heroSTR = Convert.ToInt32(lblHeroSTR.Text); villianHP -= HeroAttack(ref heroSTR, villianDEF); lblVillianHP.Text = villianHP.ToString(); if (DidWeWin()) { txtOutput.Text = "The villian was defeated! " + txtOutput.Text; } }
private void MyMethod() { lblVillianHP.Text = 150.ToString(); } private string Update() { return "200"; } private void SetHP(int hP) { lblVillianHP.Text = hP.ToString(); } private int HeroAttack(ref int damage, int armor) { Random random = new Random(); int additionalDamage = random.Next(0, 10); damage += additionalDamage; int totalDamage; if(damage - armor <= 0) { totalDamage = 0; } else { totalDamage = damage - armor; } txtOutput.Text = "the hero hit the villian for " + totalDamage.ToString() + "!!! " + txtOutput.Text; return totalDamage; }
private int GetVillianHP() { return Convert.ToInt32(lblVillianHP.Text); }
private bool DidWeWin() { bool win = false; if (Convert.ToInt32(lblVillianHP) <= 0) { win = true; btnAttack.Visible = false; } return win; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
