my English isn't good. I have a problem with object specific class. I creating that object using function (WFA: button_click)
public void button1_Click(object sender, EventArgs e)
{
clas = comboBox1.Text;
name = textBox1.Text;
sex = radioButton1.Checked;
if (nazwa.Length != 0 && nazwa.Length != 0)
{
Hero Bohater = new Hero(name, clas, sex);
}
}
And, when I using another button:
private void chodzenie_Click(object sender, EventArgs e)
{
int r = rnd.Next(1, 100);
if (r % 10 == 0 || r % 10 == 5)
{
attack_mode();
}
}
private void attack_mode()
{
int wybor = rnd.Next(0, 1);
if (wybor == 0)
{
small_enemy wojo = new small_enemy("Antek");
while (Bohater.hp >= 0 || wojo.hp >= 0)
{
Bohater.hp -= (wojo.atack - Bohater.defence_p);
wojo.hp -= (Bohater.atack_p - wojo.defence);
}
}
else
{
big_enemy wojo = new big_enemy("Waldek");
while (Bohater.hp != 0 || wojo.hp != 0)
{
Bohater.hp -= (wojo.atack - Bohater.defence_p);
wojo.hp -= (Bohater.atack_p - wojo.defence);
}
}
}
Visual can't see my object and receive Error
The name 'Bohater' does not exist in the current context
How to make usable creating object (in function), and uses in global scope?
Ofc all of this is in one file, but another function. I'm try to get Answer in internet, maybe my searching isn't good.