private Graphics ShapeCommand(String[] scaleCmds) { callShape Call = new callShape(); // inherits from the classes through the callshape class Shape s; if (scaleCmds[0] == "rectangle") { s = Call.getShape("RECTANGLE"); s.set(Convert.ToInt16(scaleCmds[1].Trim()) /* x */, Convert.ToInt16(scaleCmds[2].Trim()) /* y */, Convert.ToInt16(scaleCmds[3].Trim()) /* width */, Convert.ToInt16(scaleCmds[4].Trim()) /* height */); s.draw(g); } else if (scaleCmds[0] == "circle") { s = Call.getShape("CIRCLE"); s.set(Convert.ToInt16(scaleCmds[1].Trim()) /* x */, Convert.ToInt16(scaleCmds[2].Trim()) /* y */, Convert.ToInt16(scaleCmds[3].Trim()) /* radius */); s.draw(g); } else if (scaleCmds[0] == "square") { s = Call.getShape("SQUARE"); s.set(Convert.ToInt16(scaleCmds[1].Trim()) /* x */, Convert.ToInt16(scaleCmds[2].Trim()) /* y */, Convert.ToInt16(scaleCmds[3].Trim()) /* width */, Convert.ToInt16(scaleCmds[4].Trim()) /* height */); s.draw(g); } else if (scaleCmds[0] == "triangle") { s = Call.getShape("TRIANGLE"); s.set(Convert.ToInt16(scaleCmds[1].Trim()) /* x */, Convert.ToInt16(scaleCmds[2].Trim()) /* y */, Convert.ToInt16(scaleCmds[3].Trim()) /* x */, Convert.ToInt16(scaleCmds[4].Trim()) /* y */, Convert.ToInt16(scaleCmds[5].Trim()) /* x */, Convert.ToInt16(scaleCmds[6].Trim()) /* y */); s.draw(g); } else if (scaleCmds[0] == "drawto") { Pen pen = new Pen(Color.Black, 2); g.DrawLine(pen, location.x, location.y, /* Gets locations from location.cs */ Convert.ToInt16(scaleCmds[1].Trim()), Convert.ToInt16(scaleCmds[2].Trim())); location.x = Convert.ToInt16(scaleCmds[1].Trim()); // sets new locations, x and y location.y = Convert.ToInt16(scaleCmds[2].Trim()); } else if (scaleCmds[0] == "moveto") { location.x = Convert.ToInt16(scaleCmds[1].Trim()); // sets new x and y location.y = Convert.ToInt16(scaleCmds[2].Trim()); } else if (scaleCmds[0] == "clear") { clear(); } else if (scaleCmds[0] == "reset") { reset(); } else { MessageBox.Show("Please type in a valid input", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(g); }
private Graphics ShapeCommand(String[] scaleCmds) { foreach (var str in scaleCmds) { str.Trim(); } callShape Call = new callShape(); // inherits from the classes through the callshape class Shape s; bool bHeightIsVariable = false; int height = 0; int width = 0; //int radius = 0; if (scaleCmds[0] == "var") { string variable = scaleCmds[1]; if (scaleCmds[2].StartsWith("++")) // Allows you to add 1 to current value { try { varMap.Add(variable, 1); } catch (Exception e) { varMap[variable] += 1; } } else if (scaleCmds[2].StartsWith("--")) // Allows you to minus 1 to current value { try { varMap.Add(variable, -1); } catch (Exception e) { varMap[variable] -= 1; } } else if (scaleCmds[2].StartsWith("+")) // Allows you to add to current value (Variable) { int val = Convert.ToInt16(scaleCmds[2].Substring(1)); // stores value to be added try { varMap.Add(variable, val); } catch (Exception e) { varMap[variable] += val; } } else if (scaleCmds[2].StartsWith("-")) // Allows you to minus to current value (Variable) { int val = Convert.ToInt16(scaleCmds[2].Substring(1)); // stores value to be subtracted try { varMap.Add(variable, -val); } catch (Exception e) { varMap[variable] -= val; } } else { int value = Convert.ToInt16(scaleCmds[2]); try { varMap.Add(variable, value); // stores the variable name and the value associated with it } catch (Exception e) { varMap[variable] = value; } } } string key = ""; // default value is empty, value needs to be populated if (scaleCmds.Length > 1) { foreach (var pair in varMap) { key = pair.Key; int value = pair.Value; if (scaleCmds[1] == key) { bHeightIsVariable = true; } } } if (bHeightIsVariable) { int value = varMap[key]; // gets values from the map key height = value; // stores value for height width = value; // stores value for left } else { try { width = Convert.ToInt16(scaleCmds[1]); try { height = Convert.ToInt16(scaleCmds[2]); // stores value if it is inputted } catch (Exception e) { height = width; // if a 2nd value that is required isn't entered, the width is set to the same as the height } } catch (Exception e) { width = -1; // if no value is set, it is ignored and command wont run, stops crashing height = -1; } } // Below calls from factory class (view classes folder) - inheritance if (scaleCmds[0] == "rectangle") { s = Call.getShape("RECTANGLE"); s.set(location.x, location.y, width, height); s.draw(g); } else if (scaleCmds[0] == "circle") { s = Call.getShape("CIRCLE"); s.set(location.x, location.y, height /*radius */); s.draw(g); } else if (scaleCmds[0] == "square") { s = Call.getShape("SQUARE"); s.set(location.x, location.y, width, height); s.draw(g); } else if (scaleCmds[0] == "triangle") { s = Call.getShape("TRIANGLE"); s.set(location.x, location.y, Convert.ToInt16(scaleCmds[1]) /* x */, Convert.ToInt16(scaleCmds[2]) /* y */, Convert.ToInt16(scaleCmds[3]) /* x */, Convert.ToInt16(scaleCmds[4]) /* y */); s.draw(g); } else if (scaleCmds[0] == "drawto") { Pen pen = new Pen(Color.Black, 2); g.DrawLine(pen, location.x, location.y, /* Gets locations from location.cs */ Convert.ToInt16(scaleCmds[1]), Convert.ToInt16(scaleCmds[2])); location.x = Convert.ToInt16(scaleCmds[1]); // sets new locations, x and y location.y = Convert.ToInt16(scaleCmds[2]); } else if (scaleCmds[0] == "moveto") { location.x = Convert.ToInt16(scaleCmds[1]); // sets new x and y location.y = Convert.ToInt16(scaleCmds[2]); } else if (scaleCmds[0] == "clear") { clear(); } else if (scaleCmds[0] == "reset") { reset(); } else if (scaleCmds[0] == "save") { SaveFile(); } else if (scaleCmds[0] == "load") { commandBox.Text = LoadFile(); } return(g); }