public class Player
{
public WoodenStick firstWeapon = new WoodenStick(); //Ignore for now
}
public class Warrior : Player
{
public string classType = "Warrior";
}
public class Sorcerer : Player
{
public string classType = "Sorcerer";
}
Though my problem lies within the Main method of the program...
I created a method inside of the Program class called ChooseClass() which I want to get user input and create a class based off of what the user inputs.
See below
class Program
{
static void Main(string[] args)
{
Player player = ChooseClass();
Console.Clear();
Console.WriteLine();
Console.ReadLine();
}
static Player ChooseClass()
{
Warrior warrior = new Warrior();
Sorcerer sorcerer = new Sorcerer();
ChooseClass:
Console.WriteLine("Choose a class: Warrior or Sorcerer");
Console.WriteLine();
string response = Console.ReadLine();
if (response.Equals("Warrior"))
return warrior;
else if (response.Equals("Sorcerer"))
return sorcerer;
else
{
Console.Clear();
Console.WriteLine("Try again");
Console.ReadLine();
Console.Clear();
goto ChooseClass;
}
}
}
Hopefully the code is readable to you. The method kind of works. When I do player.GetType(), it does return either Sorcerer or Warrior, but I can't access the individual properties of Sorcerer or Warrior because the actual object is defined as Player. How can I get it to create the specific object based on the user input?
Thanks for the help!