I'm in the process of writing a basic text game using WinForms; this started off as a Console app.
In my Player class, I have this method, which currently reads a name and characterClass from Console.ReadLine() and builds the Player object from these parameters:
public static Player CreateCharacter()
{
string name;
string characterClass;
//InputOutput.Write("Please enter your character's name: ");
name = Console.ReadLine();
characterClass = Console.ReadLine(); //SelectClass();
switch (characterClass.ToLower())
{
case "warrior":
return new Player(name, new Warrior());
case "archer":
return new Player(name, new Archer());
case "mage":
return new Player(name, new Mage());
default:
throw new ArgumentException();
}
}
This method worked well with the Console project, but now that I'm moving over to WinForms I'm unsure how to get similar functionality from a TextBox.
I am trying to build a method similar to the following:
public void StartNewGame()
{
AddTextToOutputBox("To begin, please enter a name for your character: ");
GetInputFromTextbox(input1); //wait for input from textbox
AddTextToOutputBox("Now, enter a class. [Warrior], [Archer], or [Mage]:");
GetInputFromTextbox(input2); //wait for input from textbox
Player.CreateCharacter(input1, input2); //create the player
}
Where I output a message to OutputBox, wait for input from InputBox, and create a Player from these parameters.
I'm unsure how to proceed here, but I would like the functionality to be similar to that of Console.ReadLine() because (as it stands now), the method I'm trying to call depends on input from the user.
- What options are available to mimic the functionality of
Console.ReadLine()with aTextBoxin WinForms? Is there a different control better suited to this task? - Is this method the "right" way to do what I'm trying to accomplish, or would I be better off with a different method altogether?