Beating my head against the wall on this one. Trying to write a simplified version of a combat routine (to make sure I have all the basic pieces working).
But getting stuck with just getting the basics done and drawing a blank on what I can do to solve this last issue. And hoping I can get some help.
To start with, I have a windows form where some info is entered:
namespace BasicCombatForm
{
public partial class DataEntry : Form
{
int[] fighter1 = new int[2];
int[] fighter2 = new int[2];
public DataEntry()
{
InitializeComponent();
}
private void btnBegin_Click(object sender, EventArgs e)
{
string nameFighter1 = txtFighter1Name.Text;
string nameFighter2 = txtFighter2Name.Text;
fighter1[0] = Convert.ToInt16(txtFighter1Atk.Text);
fighter1[1] = Convert.ToInt16(txtFighter1Def.Text);
fighter2[0] = Convert.ToInt16(txtFighter2Atk.Text);
fighter2[1] = Convert.ToInt16(txtFighter2Def.Text);
Fight war = new Fight();
Display show = new Display();
show.showFight(war.newFight(nameFighter1, nameFighter2, fighter1, fighter2));
}
}
}
Next I have the class that handles the combat routine:
namespace BasicCombatForm
{
public class Fight
{
public string[] newFight(string nameFighter1, string nameFighter2, int[] fighter1, int[] fighter2)
{
Random objRan = new Random();
int roll1 = objRan.Next(1, 21);
int roll2 = objRan.Next(1, 21);
int fighter1Atk = fighter1[0] + roll1;
int fighter1Def = fighter1[1] + roll1;
int fighter2Atk = fighter2[0] + roll2;
int fighter2Def = fighter2[1] + roll2;
string[] result = new string[2];
if (fighter1Atk > fighter2Def)
result[0] = nameFighter1 + " scores a hit on " + nameFighter2;
else
result[0] = nameFighter1 + " misses " + nameFighter2;
if (fighter2Atk > fighter1Def)
result[1] = nameFighter2 + " scorese a hit on " + nameFighter1;
else
result[1] = nameFighter2 + " misses " + nameFighter1;
return result;
}
}
}
And last I have a simple output form I want to write the results to:
namespace BasicCombatForm
{
public partial class Display : Form
{
public Display()
{
InitializeComponent();
}
public object showFight(string[] result)
{
lstDisplayFight.Items.ToString = result[0];
lstDisplayFight.Items.Equals = result[1];
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
After all is said and done, the last issue I am having is at the writing to the lstDisplayFight listbox. I keep coming back to the compile error that tells me that .Add or .Equals or any other function I try, cannot assign because it is a 'method group'. And I have not been able to find anything that helps clear up exactly what my issue is.
Am I just going about this the wrong way? Or is there something else I can do? (Of course, I don't even know if the rest of this is going to work either...)
Thanks all.
Jarod