Documented Commander

This commit is contained in:
Lukasz Baldyga committed 2020-11-02 12:23:18 +00:00
1 parent ec11d03cc8
commit 1d53c4c00f
1 file changed
+44 -2
@@ -5,12 +5,19 @@ using System.Drawing.Drawing2D;
using System.Linq;
namespace Advanced_Software_Engineering {
/// <summary>
/// The commander class takes care of commands. It also takes control of the drawer.
/// </summary>
public class Commander {
Graphics graphics;
List<Verb> commands = new List<Verb>();
Drawer drawer;
/// <summary>
/// This command updates the graphics element (usually) when the page repaints.
/// </summary>
/// <param name="updateGraphicsElement">The graphics element to be updated</param>
public void DrawAllCommands(Graphics updateGraphicsElement) {
graphics = updateGraphicsElement;
drawer.ResetDrawer();
@@ -21,27 +28,47 @@ namespace Advanced_Software_Engineering {
}
}
/// <summary>
/// Create a new Commander instance.
/// </summary>
/// <param name="graphics">initial graphics object</param>
public Commander(Graphics graphics) {
this.graphics = graphics;
this.drawer = new Drawer(this.graphics);
drawer.ResetDrawer();
}
public Commander(string command) {
/// <summary>
/// Creates a new Commander instance without a context. Should only be used for testing purpouses.
/// </summary>
/// <param name="command">empty string</param>
public Commander(string command = "") {
Console.WriteLine("Warning! No graphics context!!!");
}
/// <summary>
/// Creates a new Commander instance with a graphics context and commands to process right off the bat.
/// </summary>
/// <param name="graphics">Graphics contetx</param>
/// <param name="rawCommands">Commands to process</param>
public Commander(Graphics graphics, string rawCommands) {
this.graphics = graphics;
this.drawer = new Drawer(this.graphics);
this.ProcessCommands(rawCommands);
drawer.ResetDrawer();
}
/// <summary>
/// Adds a verb to the command list to be executed.
/// </summary>
/// <param name="command">Verb to be added</param>
public void AddCommand(Verb command) {
commands.Add(command);
}
/// <summary>
/// processes commands. Removes all commands if it fails parsing the raw commands.
/// </summary>
/// <param name="rawCommands">Processes commands seperated by \n or \r\n</param>
public void ProcessCommands(string rawCommands) {
//ignore case
rawCommands = rawCommands.ToLower();
@@ -81,6 +108,10 @@ namespace Advanced_Software_Engineering {
}
/// <summary>
/// Processes the commands and executes them at the same time. It's the same as <see></see>
/// </summary>
/// <param name="rawCommands">Processes commands seperated by \n or \r\n</param>
public void ProcessCommandsAndExecute(string rawCommands) {
int start = commands.Count;
ProcessCommands(rawCommands);
@@ -90,11 +121,18 @@ namespace Advanced_Software_Engineering {
}
}
/// <summary>
/// Removes all commands from the Commander and resets the drawer.
/// </summary>
public void RemoveAllCommands() {
commands = new List<Verb>();
drawer.ResetDrawer();
}
/// <summary>
/// Explains all of the commands in order
/// </summary>
/// <returns>Explanation of all the commands</returns>
public string ExplainCommands() {
string desc = "";
foreach (Verb command in commands) {
@@ -103,6 +141,10 @@ namespace Advanced_Software_Engineering {
return desc;
}
/// <summary>
/// Get the numder of commands inside the Commader
/// </summary>
/// <returns>Integer number of commands</returns>
public int GetNumberOfCommands() {
return commands.Count;
}