private void Test() { SchemeFunction f = new SchemeFunction(); f.AddCommand(new CommandAddAction("grab")); f.AddCommand(new CommandAddAction("examine")); f.AddCommand(new CommandRemoveAction("grab")); f.AddCommand(new CommandAddAction("drop")); MapObject @object = new MapObject(); @object.Name = "some_object"; @object.Variables.Add(new ObjectVariable("logical", "isDwarf", false)); @object.Variables.Add(new ObjectVariable("logical", "isElf", false)); @object.Scheme = new Scheme("some_scheme"); @object.Scheme.CompiledScheme = new CompiledScheme(); @object.Scheme.CompiledScheme.AddAction(new SchemeFunction("grab")); @object.Scheme.CompiledScheme.AddAction(new SchemeFunction("examine")); @object.Scheme.CompiledScheme.AddAction(new SchemeFunction("drop")); Config config = new Config(); config.AddScheme(@object.Scheme); Game game = new Game(config); game._AddObject(@object); //Execute function on object f.Execute(@object, new Character(), game); }
private Scheme GetLeverScheme() { Scheme leverScheme = new Scheme(); leverScheme.CompiledScheme = new CompiledScheme(); SchemeFunction use = new SchemeFunction(); use.Name = "use"; use.AddCommand(new CommandOf("ready", "box", "_0")); use.AddCommand(new CommandNot("_0", "_0")); use.AddCommand(new CommandSetOf("ready", "box", "_0")); use.AddCommand(new CommandDesc("LEVER_DESC_2")); leverScheme.CompiledScheme.AddAction(use); return(leverScheme); }
private Scheme GetBoxScheme() { Scheme boxScheme = new Scheme(); boxScheme.CompiledScheme = new CompiledScheme(); boxScheme.CompiledScheme.AddVariable(new ObjectVariable(VariableTypes.Logical, "ready", false)); SchemeFunction pickup = new SchemeFunction(); pickup.Name = "pickup"; pickup.ActionPoints = 1; pickup.AddCommand(new CommandJumpIfFalse("ready", 3)); pickup.AddCommand(new CommandPrint("Picked up")); pickup.AddCommand(new CommandJump(4)); pickup.AddCommand(new CommandPrint("Box is stuck")); boxScheme.CompiledScheme.AddAction(pickup); return(boxScheme); }
public override object VisitBody_variable_definition([NotNull] scheme_langParser.Body_variable_definitionContext context) { //Add predefined variable to scheme var variable_definition = context.variable_definition(); string type = variable_definition?.variable_type()?.GetText(); string name = variable_definition?.variable_name()?.GetText(); if (type == null || name == null) { return(base.VisitBody_variable_definition(context)); } if (!VariableManager.IsTypeValid(type, Config)) { Errors.Add(new ErrorDescriptor($"Type '{type}' is not recognized.", variable_definition.variable_type())); } if (CompiledScheme.GetVariableByName(name) != null || CompiledScheme.GetParameterByName(name) != null) { Errors.Add(new ErrorDescriptor($"Variable or parameter '{name}' already exists.", variable_definition.variable_name())); if (variable_definition.EQUALS() != null) { SetNewExpression(1); } return(base.VisitBody_variable_definition(context)); } ObjectVariable variable = new ObjectVariable(type, name, null); if (variable != null) { CompiledScheme.AddVariable(variable); CommandSetVariable cmd = new CommandSetVariable(variable_definition.variable_name().GetText(), GetRegName(0)); currentFunc.AddCommand(cmd); SetNewExpression(1); } return(base.VisitBody_variable_definition(context)); }