So far i can take info from a textbox and draw shapes based on it, but i'm trying to allow the user to create variables within the textbox.
the program currently successfully splits text and draws multiple shapes using basic commands like:
circle 50
square 100,100
but i am trying to expand the program to allow for variables to be defined in the text box and then use them to draw shapes. This is what i would like to be able to run in the text box which would in turn draw two circles:
num = 50
circle num
num = num + 50
circle num
And this is what i currently have which splits the text and uses each part as parameters for the shapes which are then used to used to draw the lines/shapes etc.
private void button1_Click(object sender, EventArgs e)
{
String[] Lines = ProgramWindow.Text.Split('\n');
int NumberOfCommands = Lines.Length;
{
for (int i = 0; i <= NumberOfCommands - 1; i++)
{
String VariableName = "";
int VariableValue = 0;
String[] Input = Lines[i].ToLower().Split(' ', (char)StringSplitOptions.RemoveEmptyEntries);
String Command = Input[0];
int[] Parameters = Input.Length <= 1 ? new int[0] : Input[1].Split(',').Select(item => int.Parse(item)).ToArray();
int X = Parameters.Length >= 1 ? Parameters[0] : 0;
int Y = Parameters.Length >= 2 ? Parameters[1] : 0;
Console.WriteLine(Command);
Console.WriteLine(X);
Console.WriteLine(Y);
Commands(Command, X, Y, VariableName, VariableValue);
Refresh();
}
}
void Commands(string Command, int X, int Y, String VariableName, int VariableValue)
{
if (X.Equals("="))
{
VariableName = Command;
VariableValue = Y;
}
else if (Command.Equals("circle"))
{
if (Checked == true)
{
MyCanvas.FillCircle(X);
}
else if (VariableValue > 0)
{
MyCanvas.DrawCircle(VariableValue);
}
else
MyCanvas.DrawCircle(X);