You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
m349pmma edited this page Apr 4, 2025
·
1 revision
Quick Start
The engine class has a protected property IReadOnlyDictionary<string, ICommandParser> Commands,
which per default is initialized to Engine.DefaultCommands.
If the engine receives a line, it is split in to an array of args and args[0] is looked up in Commands.
If this key exists the ICommandParser is used else new Unknown(args) is returned
Lets say, we wanted a printboard command.
Now we simply create a class/record that implements ICommand, and a class that implements ICommandParser. Note: I like record classes in this situation since i just use them as tokens
Now we need to add our new new command to the Commands dictionary in our engine.
// in YourEngine : EnginepublicYourEngine(){varcommands=newDictionary<string,ICommandParser>(Engine.DefaultCommands);commands.Add(PrintBoard.arg0,newPrintPoard.Parser());this.Commands=commands;}