GG EZ, ima go piss

This commit is contained in:
2025-07-08 04:29:21 +03:00
parent fd78d9283e
commit e3dc8d9d42
31 changed files with 441 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
public class CommandInterpreter
{
public readonly Dictionary<string, ICommand> _commands = new();
public CommandInterpreter()
{
RegisterCommand(new GreetCommand());
RegisterCommand(new HelpCommand(this));
}
public void RegisterCommand(ICommand command)
{
_commands[command.Name.ToLower()] = command;
}
public void Execute(string input)
{
string[] parts = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 0) return;
string commandName = parts[0].ToLower();
string[] args = parts.Length > 1 ? parts[1..] : new string[0];
if (_commands.TryGetValue(commandName, out var command))
{
command.Execute(args);
}
else
{
Console.WriteLine("Err - uknown Command : '{commandName}'. Type help For a list of commands");
}
}
public IEnumerable<ICommand> GetAllCommands()
{
return _commands.Values;
}
}