It's a very very small ( still complex though ) text based RPG that has 3 classes which each offers around 20 minutes of gameplay.
Anyways, the game features a very very basic command-system that has the identifier of '/'.
Some examples are:
/pickup, /talk, /climb, /attack, /open ect ect.
I'm sketching on a small prototype of it using delegate's and .Invoke.
This is what i have so far:
public class Command
{
Delegate Invoker;
public Command(Delegate function, cSystem caller, string[] args)
{
Invoker = function;
Invoker.Method.Invoke(caller, new object[] {args});
}
}
public class cSystem
{
Command a;
delegate void Method(string[] args);
private void Test(string[] args)
{
Console.WriteLine("Hello World, {0}");
}
public cSystem(string[] args)
{
a = new Command(new Method(Test) , this, args);
}
}
class Program
{
static void Main(string[] args)
{
string[] StringArray = new string[1];
StringArray[0] = "By Victor";
cSystem b = new cSystem(StringArray);
Console.ReadLine();
}
}
This is really sweet since Command's can access even the private functions of the cSystem. The idea is that cSystem is the main-game class, it contains everything, character, command-lists, location-lists ect ect also all of the functions the commands are going to use when triggered.
As you can see the above example isn't really developed THAT much but it works and you can feed another class functions from the calling class ( cSystem ).
My idea is to have ( ONE ) instance of each command-type in a dictionary, this way when a location or anything else needs access to the command i don't need to create a new instance of it, i can add it to a
List<Command> CommandList = new List<Command>(); that holds refrences to Command-objects like so:
CommandList.Add(caller.FetchCommand(Commands.Open));
So input anyone? Is this a good implementation?