Ok. So I'm trying to figure out how to implement an overloaded operator. I've searched some tutorials but there's something I'm missing. Maybe it's one of those 'obvious' things I'm thinking too hard about. I don't know. Which is why I'm here.
Here's the overloaded operator:
public static bool operator +(Hero h, Monster m)
{
if (!h.IsRunningAway)
{
if(h.AttackSpeed > m.AttackSpeed)
{
m.takesDamage(h.attackValue());
if (m.isAlive())
{
h.takesDamage(m.AttackValue);
}
}
else if(h.AttackSpeed < m.AttackSpeed)
{
h.takesDamage(m.AttackValue);
if (h.isAlive())
{
m.takesDamage(h.attackValue());
}
}
else
{
h.takesDamage(m.AttackValue);
m.takesDamage(h.attackValue());
}
}
else
{
if(h.AttackSpeed <= m.AttackSpeed)
{
h.takesDamage(m.AttackValue);
}
}
h.IsRunningAway = false;
return h.isAlive();
}
Now, I'm trying to implement this in a button click event in a form.
private void btnAttack_Click(object sender, RoutedEventArgs e)
{
}
Tutorials I've seen aren't being particularly clear on how to do it. Like I said, I maybe overthinking it. I usually do.
If the question can be edited to be clearer, or anything else is needed, let me know. I'm glad to edit.