public IExecutable ManageCommand(string inputArgs) { IExecutable command = null; string commandType = inputArgs; switch (commandType) { case "top": command = new StatusCommand(this.Engine); break; case "restart": command = new RestartCommand(this.Engine); break; case "turn": command = new TurnCommand(this.Engine); break; case "exit": command = new EndCommand(this.Engine); break; default: this.Engine.Writer.WriteLine("\nError! Invalid command\n"); break; } return command; }
private void RaiseCanExecuteChanged(object sender, EventArgs e) { DraftCommand.RaiseCanExecuteChanged(); TemporaryCommand.RaiseCanExecuteChanged(); EndCommand.RaiseCanExecuteChanged(); BackFromEndCommand.RaiseCanExecuteChanged(); PermanentCommand.RaiseCanExecuteChanged(); }
public UserVM() { questions = new ObservableCollection <QuestionDTO>(); answers = new ObservableCollection <ServiceReferenceAnswerOption.AnswerOptionDTO>(); getQuestionscommacd = new GetQuestionsCommand(this); startComand = new StartTestCommand(this); endComand = new EndCommand(this); findComand = new FindCommand(this); logStud = new LogStudCommand(this); startPage = new StartPageLogCommand(this); }
public SyntaxStateMachine(FileManager fileManager) { CurrentState = SyntaxMachineState.START; transitions = new Dictionary <SyntaxStateTransition, SyntaxMachineState> { { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.INT), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.RETURN), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.FINAL), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.PRINT), SyntaxMachineState.PRINT }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.LET), SyntaxMachineState.LET }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.FOR), SyntaxMachineState.FOR }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.DIM), SyntaxMachineState.DIM }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.REMARK), SyntaxMachineState.REMARK }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.GO), SyntaxMachineState.GO }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.GOTO), SyntaxMachineState.GO }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.DATA), SyntaxMachineState.DATA }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.READ), SyntaxMachineState.READ }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.GOSUB), SyntaxMachineState.GOSUB }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.IF), SyntaxMachineState.IF }, { new SyntaxStateTransition(SyntaxMachineState.START, TokenType.NEXT), SyntaxMachineState.NEXT }, { new SyntaxStateTransition(SyntaxMachineState.PRINT, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.LET, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.FOR, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.DIM, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.REMARK, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.GO, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.DATA, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.READ, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.GOSUB, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.IF, TokenType.END), SyntaxMachineState.START }, { new SyntaxStateTransition(SyntaxMachineState.NEXT, TokenType.END), SyntaxMachineState.START }, }; this.fileManager = fileManager; this.variables = new VariableTable(); this.endCommand = new EndCommand(fileManager); this.sequenceId = new SequenceIdLabelCommand(this.variables, fileManager); this.returnCommand = new ReturnCommand(this.variables, fileManager); this.engine = new SyntaxEngine(this.variables, fileManager); }
public ICommand ParseCommand(string input) { string[] data = input.Split(); ICommand command = null; switch (data[0]) { case "Job": string jobName = data[1]; int workHoursRequired = int.Parse(data[2]); string employeeName = data[3]; IEmployee employee = this.employeeRepository.GetEmployeeByName(employeeName); command = new CreateJobCommand(jobName, workHoursRequired, employee); break; case nameof(StandardEmployee): case nameof(PartTimeEmployee): string employeeToCreateName = data[1]; command = new CreateEmployeeCommand(data[0], employeeToCreateName); break; case "Pass": command = new PassWeekCommand(); break; case "Status": command = new StatusCommand(); break; case "End": command = new EndCommand(); break; } InjectFields(command); return(command); }
public IExecutable ManageCommand(string[] inputArgs) { IExecutable command = null; switch (inputArgs[0]) { case "build": command = new BuildCommand(inputArgs[1], this.Engine); break; case "skip": command = new SkipCommand(); break; case "empire-status": command = new StatusCommand(this.Engine); break; case "armistice": command = new EndCommand(); break; } return command; }
public void SetCommand(SceneWord sceneWord, long HeaderOffset) { SceneCommand command; switch ((HeaderCommands)sceneWord.Code) { case HeaderCommands.PositionList: //0x00 command = new PositionListCommand(Game); break; case HeaderCommands.ActorList: //0x01 command = new ActorListCommand(Game); break; case HeaderCommands.Collision: //0x03 command = new CollisionCommand(); break; case HeaderCommands.RoomList: //0x04 command = new RoomListCommand(); break; case HeaderCommands.WindSettings: //0x05 command = new WindSettingsCommand(); break; case HeaderCommands.EntranceDefs: //0x06 command = new EntranceDefinitionsCommand(); break; case HeaderCommands.SpecialObject: //0x07 command = new SpecialObjectCommand(); break; case HeaderCommands.RoomBehavior: //0x08 command = new RoomBehaviorCommand(); break; case HeaderCommands.RoomMesh: //0x0A command = new RoomMeshCommand(); break; case HeaderCommands.ObjectList: //0x0B command = new ObjectListCommand(); break; case HeaderCommands.PathList: //0x0D command = new PathListCommand(); break; case HeaderCommands.TransitionActorList: //0x0E command = new TransitionActorListCommand(Game); break; case HeaderCommands.EnvironmentSettings: //0x0F command = new EnvironmentSettingsCommand(); break; case HeaderCommands.TimeSettings: //0x10 command = new TimeSettingsCommand(); break; case HeaderCommands.SkyboxSettings: //0x11 command = new SkyboxSettingsCommand(); break; case HeaderCommands.SkyboxModifier: //0x12 command = new SkyboxModifierCommand(); break; case HeaderCommands.ExitList: //0x13 command = new ExitListCommand(); break; case HeaderCommands.End: //0x14 command = new EndCommand(); break; case HeaderCommands.SoundSettings: //0x15 command = new SoundSettingsCommand(); break; case HeaderCommands.SoundSettingsEcho: //0x16 command = new SoundSettingsEchoCommand(); break; case HeaderCommands.Cutscene: //0x17 command = new CutsceneCommand(); break; case HeaderCommands.AlternateHeaders: //0x18 command = new AlternateHeadersCommand(Game); break; case HeaderCommands.JpegBackground: //0x19 command = new JpegBackgroundCommand(); break; default: command = new SceneCommand(); break; } command.SetCommand(sceneWord); command.OffsetFromFile = HeaderOffset; cmds.Add(command); }
public static Command Parse(string input) { string[] values = input.Split(' '); if (!values.Any()) { throw new ArgumentException("No command specified."); } // command should be first if (!Enum.TryParse(values[0].ToPascalCase(), out CommandType type)) { throw new ArgumentException($"Invalid command {values[0]}"); } if (type == CommandType.Undefined) { throw new ArgumentException($"Invalid command {type}"); } string[] args = values.Skip(1).ToArray(); Command command = null; switch (type) { case CommandType.End: { command = new EndCommand(); break; } case CommandType.Flag: { command = new FlagCommand(); Dictionary <string, object> requiredArgs = command.GetRequiredArguments(); if (args.Length != requiredArgs.Count) { throw new ArgumentException($"Command type {type} requires {requiredArgs.Count} arguments."); } if (!int.TryParse(args[0], out int x)) { throw new ArgumentException($"Parameter {CommandKeys.XPosition} must be an integer."); } if (!int.TryParse(args[1], out int y)) { throw new ArgumentException($"Parameter {CommandKeys.YPosition} must be an integer."); } requiredArgs[CommandKeys.XPosition] = x; requiredArgs[CommandKeys.YPosition] = y; command.Build(requiredArgs); break; } case CommandType.Help: { command = new HelpCommand(); Dictionary <string, object> requiredArgs = command.GetRequiredArguments(); if (args.Length > 0) { if (args.Length > 1) { throw new ArgumentException($"Command type {type} requires 1 or 0 arguments."); } if (!Enum.TryParse(args[0].ToPascalCase(), out CommandType commandType)) { throw new ArgumentException($"Invalid command type {args[0]}"); } requiredArgs[CommandKeys.CommandName] = commandType; command.Build(requiredArgs); } break; } case CommandType.New: { command = new NewCommand(); Dictionary <string, object> requiredArgs = command.GetRequiredArguments(); if (args.Length != requiredArgs.Count) { throw new ArgumentException($"Command type {type} requires {requiredArgs.Count} arguments."); } if (!int.TryParse(args[0], out int x)) { throw new ArgumentException($"Parameter {CommandKeys.XLength} must be an integer."); } if (!int.TryParse(args[1], out int y)) { throw new ArgumentException($"Parameter {CommandKeys.YLength} must be an integer."); } if (!int.TryParse(args[2], out int b)) { throw new ArgumentException($"Parameter {CommandKeys.Bombs} must be an integer."); } requiredArgs[CommandKeys.XLength] = x; requiredArgs[CommandKeys.YLength] = y; requiredArgs[CommandKeys.Bombs] = b; command.Build(requiredArgs); break; } case CommandType.Open: { command = new OpenCommand(); Dictionary <string, object> requiredArgs = command.GetRequiredArguments(); if (args.Length != requiredArgs.Count) { throw new ArgumentException($"Command type {type} requires {requiredArgs.Count} arguments."); } if (!int.TryParse(args[0], out int x)) { throw new ArgumentException($"Parameter {CommandKeys.XPosition} must be an integer."); } if (!int.TryParse(args[1], out int y)) { throw new ArgumentException($"Parameter {CommandKeys.YPosition} must be an integer."); } requiredArgs[CommandKeys.XPosition] = x; requiredArgs[CommandKeys.YPosition] = y; command.Build(requiredArgs); break; } case CommandType.Quit: { command = new QuitCommand(); Dictionary <string, object> requiredArgs = command.GetRequiredArguments(); break; } case CommandType.Unflag: { command = new UnflagCommand(); Dictionary <string, object> requiredArgs = command.GetRequiredArguments(); if (args.Length != requiredArgs.Count) { throw new ArgumentException($"Command type {type} requires {requiredArgs.Count} arguments."); } if (!int.TryParse(args[0], out int x)) { throw new ArgumentException($"Parameter {CommandKeys.XPosition} must be an integer."); } if (!int.TryParse(args[1], out int y)) { throw new ArgumentException($"Parameter {CommandKeys.YPosition} must be an integer."); } requiredArgs[CommandKeys.XPosition] = x; requiredArgs[CommandKeys.YPosition] = y; command.Build(requiredArgs); break; } case CommandType.Status: { command = new StatusCommand(); Dictionary <string, object> requiredArgs = command.GetRequiredArguments(); if (args.Length != requiredArgs.Count) { throw new ArgumentException($"Command type {type} requires {requiredArgs.Count} arguments."); } if (!int.TryParse(args[0], out int x)) { throw new ArgumentException($"Parameter {CommandKeys.XPosition} must be an integer."); } if (!int.TryParse(args[1], out int y)) { throw new ArgumentException($"Parameter {CommandKeys.YPosition} must be an integer."); } requiredArgs[CommandKeys.XPosition] = x; requiredArgs[CommandKeys.YPosition] = y; command.Build(requiredArgs); break; } } return(command); }
public void End() { var Cmd = new EndCommand(); AddCommand(Cmd); }
public void SetCommand(SceneWord sceneWord, long HeaderOffset) { SceneCommand command; switch ((HeaderCommands)sceneWord.Code) { case HeaderCommands.PositionList: //0x00 command = new ActorSpawnCommand(Game); break; case HeaderCommands.ActorList: //0x01 command = new ActorSpawnCommand(Game); break; case HeaderCommands.Collision: //0x03 command = new CollisionCommand(); break; case HeaderCommands.RoomList: //0x04 command = new RoomListCommand(); break; case HeaderCommands.WindSettings: //0x05 command = new SettingsCommand(); break; case HeaderCommands.EntranceDefs: //0x06 command = new EntranceDefinitionsCommand(); break; case HeaderCommands.SpecialObject: //0x07 command = new SettingsCommand(); break; case HeaderCommands.RoomBehavior: //0x08 command = new RoomBehaviorCommand(Game); break; case HeaderCommands.RoomMesh: //0x0A command = new RoomMeshCommand(); break; case HeaderCommands.ObjectList: //0x0B command = new ObjectListCommand(); break; case HeaderCommands.PathList: //0x0D command = new PathListCommand(); break; case HeaderCommands.TransitionActorList: //0x0E command = new TransitionActorListCommand(Game); break; case HeaderCommands.EnvironmentSettings: //0x0F command = new EnvironmentSettingsCommand(); break; case HeaderCommands.TimeSettings: //0x10 command = new SettingsCommand(); break; case HeaderCommands.SkyboxSettings: //0x11 command = new SettingsCommand(); break; case HeaderCommands.SkyboxModifier: //0x12 command = new SettingsCommand(); break; case HeaderCommands.ExitList: //0x13 command = new ExitListCommand(); break; case HeaderCommands.End: //0x14 command = new EndCommand(); break; case HeaderCommands.SoundSettings: //0x15 command = new SettingsCommand(); break; case HeaderCommands.SoundSettingsEcho: //0x16 command = new SettingsCommand(); break; case HeaderCommands.Cutscene: //0x17 command = new CutsceneCommand(Game); break; case HeaderCommands.AlternateHeaders: //0x18 command = new AlternateHeadersCommand(Game); break; case HeaderCommands.CameraAndWorldMap: //0x19 command = new SettingsCommand(); break; case HeaderCommands.Textures: //0x1A if (Game == Game.MajorasMask) { command = new TexturesCommand(); break; } goto default; case HeaderCommands._0x1B: //0x1B if (Game == Game.MajorasMask) { command = new _0x1BCommand(); break; } goto default; case HeaderCommands.Minimap: if (Game == Game.MajorasMask) { command = new MinimapCommand(); break; } goto default; case HeaderCommands.MinimapChests: if (Game == Game.MajorasMask) { command = new MinimapChestsCommand(); break; } goto default; default: command = new SceneCommand(); break; } command.SetCommand(sceneWord); command.OffsetFromFile = HeaderOffset; cmds.Add(command); }
public Command ParseCommand(string commandInput) { var commandArguments = commandInput.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // first check if it's a valid command var length = commandArguments.Length; Command command = null; var action = commandArguments[0]; var parameters = commandArguments.Skip(1).ToList(); // make it with reflection, if you hate your life switch (action) { case "append": ValidateCommandLength(length, Constants.AppendCommandLength); command = new AppendCommand(parameters); break; case "prepend": ValidateCommandLength(length, Constants.PrependCommandLength); command = new PrependCommand(parameters); break; case "reverse": ValidateCommandLength(length, Constants.ReverseCommandLength); command = new ReverseCommand(parameters); break; case "insert": ValidateCommandLength(length, Constants.InsertCommandLength); command = new InsertCommand(parameters); break; case "delete": ValidateCommandLength(length, Constants.DeleteCommandLength); command = new DeleteCommand(parameters); break; case "roll": ValidateCommandLength(length, Constants.RollCommandLength); command = new RollCommand(parameters); break; case "sort": ValidateCommandLength(length, Constants.SortCommandLength); command = new SortCommand(parameters); break; case "count": ValidateCommandLength(length, Constants.CountCommandLength); command = new CountCommand(parameters); break; case "end": this.logger.Write(Constants.FinishedMessage); command = new EndCommand(parameters); break; default: throw new ArgumentException(Constants.InvalidCommand); } return(command); }
// Update is called once per frame void Update() { List <NetworkCommand> cmds = Network.getPendingCommands(); if (cmds != null) { foreach (NetworkCommand cmd in cmds) { /*** IN-GAME ACTIONS ***/ if (cmd is MoveCommand) { MoveCommand move = (MoveCommand)cmd; Pos start = Network.getPlayer(move.clientID).grid_pos; Pos end = move.end; Debug.Log("Move received! From " + start + " to " + end); mapManager.move(start, end); } if (cmd is AttackCommand) { AttackCommand attack = (AttackCommand)cmd; Pos start = Network.getPlayer(attack.clientID).grid_pos; Pos end = attack.end; Debug.Log("Attack received! From " + start + " to " + end + " action No: " + attack.actionNo); mapManager.attack(start, end, attack.actionNo); } if (cmd is WaitCommand) { WaitCommand wait = (WaitCommand)cmd; Debug.Log("Wait received! From client#" + wait.clientID); Client waitingClient = Network.getPeer(wait.clientID); waitingClient.playerObject.wait(); } if (cmd is InteractCommand) { InteractCommand interact = (InteractCommand)cmd; Pos start = Network.getPlayer(interact.clientID).grid_pos; Pos end = interact.end; Debug.Log("Interact received! From " + start + " to " + end); mapManager.interact(start, end); } if (cmd is UseItemCommand) { UseItemCommand item = (UseItemCommand)cmd; Player player = Network.getPlayer(item.clientID); Item itemToUse = player.inventory.GetItemFromSlot(item.slotIndex); player.inventory.DecrementItemAtSlot(item.slotIndex); InventoryManager.UseItem(itemToUse, player); Debug.Log("Use Item received! From client#" + item.clientID + " for item in slot #" + item.slotIndex); } /*** LOBBY ACTIONS ***/ if (cmd is ReadyCommand) { ReadyCommand ready = (ReadyCommand)cmd; Debug.Log("Received READY"); Client client = Network.getPeer(ready.clientID); if (client == null) { Network.setPeer(ready.clientID); client = Network.getPeer(ready.clientID); } client.ready = !client.ready; } if (cmd is NicknameCommand) { NicknameCommand nickname = (NicknameCommand)cmd; Debug.Log("Received nickname: " + nickname.nickname); Client client = Network.getPeer(nickname.clientID); if (client == null) { Network.setPeer(nickname.clientID); client = Network.getPeer(nickname.clientID); } client.nickname = nickname.nickname; } if (cmd is ClassnameCommand) { ClassnameCommand classname = (ClassnameCommand)cmd; Debug.Log("Received classname: " + classname.classname); Client client = Network.getPeer(classname.clientID); if (client == null) { Network.setPeer(classname.clientID); client = Network.getPeer(classname.clientID); } client.classname = classname.classname; } if (cmd is UpdateClientInfoCommand) // called when a new player joins and needs to be synchronized { UpdateClientInfoCommand update = (UpdateClientInfoCommand)cmd; Debug.Log("Received update from client#" + update.clientID); Client client = Network.getPeer(update.clientID); if (client == null) { Network.setPeer(update.clientID); client = Network.getPeer(update.clientID); } client.nickname = update.nickname; client.classname = update.classname; client.ready = update.ready; } if (cmd is SetSeedCommand) { SetSeedCommand seed = (SetSeedCommand)cmd; Debug.Log("Received seed!"); Settings.MasterSeed = seed.seed; } /*** NETWORK ACTIONS ***/ if (cmd is JoinCommand) { JoinCommand _join = (JoinCommand)cmd; // to avoid conflict with 'join' keyword if (clientID == 0) { clientID = _join.clientID; Debug.Log("Joined game! Client ID #" + clientID + " assigned!"); } else { Debug.Log("New player with client ID #" + _join.clientID + " joined!"); Network.submitCommand(new UpdateClientInfoCommand(Network.getPeer(clientID))); if (clientID == 1) { Network.submitCommand(new SetSeedCommand(Settings.MasterSeed)); } } Network.setPeer(_join.clientID); } if (cmd is StartCommand) { StartCommand start = (StartCommand)cmd; Debug.Log("Received START"); if (SceneManager.GetActiveScene().name == "NewMenu") // only loads new scene if we're in the lobby { SceneManager.LoadScene("Procedural"); foreach (Client client in Network.getPeers()) { client.ready = false; } } else { GameManager.NextLevel(); } } if (cmd is EndCommand) { EndCommand end = (EndCommand)cmd; Debug.Log("Received END"); } if (cmd is DisconnectCommand) { DisconnectCommand disconnect = (DisconnectCommand)cmd; Debug.Log("Received DISCONNECT from client #" + disconnect.clientID); Network.removePeer(disconnect.clientID); if (clientID >= disconnect.clientID) { clientID--; Debug.Log("Changed client ID to " + clientID); } } } } if (!Network.connected()) { clientID = 0; } }