Reputation: 197
I wrote the Levels class to store the amount of enemies for each level in it. The Levels class is called once before starting a new level.
For example, if the player chooses Level 1 in the game menu, 5 zombies, 3 spiders and 1 werewolf should be drawn (in another class).
But for the moment, I always get this error message : Method must have a return type.
What is wrong ?
public class Levels
{
int currentLevel, Zombies, Spiders, Werewolfs;
public Levels(int Level)
{
this.currentLevel = Level;
}
public Level1()
{
Zombies = 5;
Spiders = 3;
Werewolfs = 1;
}
public Level2()
{
Zombies = 8;
Spiders = 4;
Werewolfs = 2;
}
public Level3()
{
Zombies = 12;
Spiders = 4;
Werewolfs = 3;
}
public void Load(ContentManager content)
{
if (currentLevel == 1)
Level1();
if (currentLevel == 2)
Level2();
if (currentLevel == 3)
Level3();
}
}
Upvotes: 0
Views: 125
Reputation: 386
You aren't returning anything from your functions. Notice your Load()
function, it is declared as public void
which means nothing or "void" is returned from that function. If you are not going to return anything from these functions, include void
in their declaration. If you are, do something like this:
public int Level1()
{
int Zombies = 5;
return Zombies;
}
Note: Functions can only return one object.
I do not know proper c# syntax so this may be wrong, but the concept is the same.
If you do not want to return something from these functions, declare them as void
, set global variables for your "enemies" and then use the methods (functions) to alter the global variable.
Upvotes: 2
Reputation: 9117
Your Level1(), Level2() etc must have a return type, like void. They are methods not constructors.
Upvotes: 5