Ive created a console program that works. The program launches and asks for the user to input values for the player class.
Then I initialize a list of Monster classes and have values entered into the method to create each monster. But I am receiving an error after the program runs claiming the index value may be overloaded. w/e that means.
List<Monster> monsterlist = new List<Monster>();
monsterlist[0].CreateMonster("Goblin", 4, 4, 4, 1);
monsterlist[1].CreateMonster("Wolf", 2, 2, 2, 1);
This is my list and the values used. I run it and then...
"ArgumentOutOfRangeException was handled
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
pops up highlighting the line.. monsterlist[0].CreateMonster("Goblin", 4, 4, 4, 1);
-- Thats the problem. I have no idea what im doing wrong even after reading the help files. I will conclude with the code of the Monster class. Thanks for the help!
public class Monster
{
private string Name = "Monstername";
private int Damage = 1;
private int Delay = 1;
private int Atk = 1;
private int Treasure = 0;
public Monster()
{
}
public void CreateMonster(string name, int damage, int delay, int atk, int treasure)
{
SetName(name);
this.Damage = damage;
this.Delay = delay;
this.Atk = atk;
this.Treasure = treasure;
}
public void SetName(string n)
{
this.Name = n;
}
}
the files are in the same namespace.