I have a List<> full of a Class object called 'Creature', 'Creature' contains a List<> that is full of a separate Class object called 'AttackMethod'. Inside of the AttackMethod Class is a public int Method called 'RollDamage' which takes variables assigned inside of AttackMethod and calculates them to return an int.
The problem I'm having is calling that RollDamage method from my List<> of Creatures. Each Creature has a List<> of AttackMethods inside of it. What I'm trying to do is Access each Creature's AttackMethod List<> and activate the RollDamage method. The abbreviated code is as follows:
private static void MobAttacksPlayer(Objects.Creature inMob)
{
MobDamage = (int)inMob.creatureAttacks.RollDamage();
Console.Write(MobDamage);
}
creatureAttacks is my public variable for the List<> inside of the Creature Class. The public was previously protected and the casting to (int) above was something else I tried, but didn't work.
public List<AttackMethod> creatureAttacks = new List<AttackMethod>();
I'm sure it's something simple that I'm overlooking; I'm fairly new to C#, but wanted to try and create and small Roguelike to learn from. As I've been writing this here, I've been going through the list of Similar questions on the right with no success. The following is my AttackMethod Class (Trimmed down to include only the Constructors and the RollDamage Method I'm trying to use)
public class AttackMethod
{
protected string aFlag;
protected string eFlag;
protected int numberDice;
protected int numberSides;
public AttackMethod() { }
public AttackMethod(string inaFlag, string ineFlag, int inNumdie,
int inNumSides)
{
aFlag = inaFlag;
eFlag = ineFlag;
numberDice = inNumdie;
numberSides = inNumSides;
}
~AttackMethod() { }
public int RollDamage()
{
DiceBag.Dice newDie = new DiceBag.Dice();
int ret = newDie.any(numberDice, numberSides);
return ret;
}
}
DiceBag is just my die roller, and has no errors with it. Also, I don't know if it makes a difference or not, but this is a Console program, not a Windows Forms program. I'm using Visual C# Express 2010. Thank you in advance for your help.
Error 2 'System.Collections.Generic.List' does not contain a definition for 'RollDamage' and no extension method 'RollDamage' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?) C:\Users\Carl.Prichard\Documents\Visual Studio 2010\Projects\MyRogueLike\MyRogueLike\Program.cs 1130 60 MyRogueLike
Usually when I get this error, casting it to the variable type I want resolves it