// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 1000)) { if (hit.collider.CompareTag("Player")) { selectedTarget = hit.transform; oldPos = selectedTarget.position; selectedTarget.GetComponent <Player>().PlayerSelected(); return; } if (selectedTarget == null) { return; } newPos = new Vector3(hit.point.x, selectedTarget.position.y, hit.point.z); positions.Add(newPos); ICommand command = new MovePlayerCommand(selectedTarget, oldPos, newPos); CommandInvoker.AddCommand(command); oldPos = newPos; } } if (Input.GetKeyDown(KeyCode.Z)) { CommandInvoker.UndoCommand(); } if (Input.GetKeyDown(KeyCode.Y)) { CommandInvoker.RedoCommand(); } //if (selectedTarget != null &&selectedTarget.position == newPos) { // positions.RemoveRange(0, positions.Count); //} }
public PlayerActionsController(RegisterPlayerCommand registerPlayerCommand, MovePlayerCommand movePlayerCommand) { this.registerPlayerCommand = registerPlayerCommand; this.movePlayerCommand = movePlayerCommand; }
protected virtual void ExecuteCommand(IKeyInfo commandKey) { IGameCommand currentCommand; switch (commandKey.Key) { case ConsoleKey.F1: currentCommand = new HelpCommand(this); currentCommand.Execute(); break; case ConsoleKey.M: ConsoleRenderer.Clear(); currentCommand = new PrintMapCommand(this); currentCommand.Execute(); break; case ConsoleKey.LeftArrow: case ConsoleKey.RightArrow: case ConsoleKey.UpArrow: case ConsoleKey.DownArrow: ConsoleRenderer.Clear(); RenderSuccessMoveMessage(commandKey); currentCommand = new MovePlayerCommand(this); currentCommand.Execute(commandKey); currentCommand = new PrintMapCommand(this); currentCommand.Execute(); break; case ConsoleKey.S: currentCommand = new PlayerStatusCommand(this); currentCommand.Execute(); break; case ConsoleKey.C: ConsoleRenderer.Clear(); break; case ConsoleKey.H: currentCommand = new HealCommand(this); currentCommand.Execute(); break; case ConsoleKey.I: currentCommand = new BoostHealthCommand(this); currentCommand.Execute(); break; case ConsoleKey.R: this.Player.Inventory.BackPack.RemoveLastItem(); break; case ConsoleKey.B: currentCommand = new BackPackCommand(this); currentCommand.Execute(); break; case ConsoleKey.Escape: this.ExitApplication(); break; default: { throw new ArgumentException("Unknown command"); } } }