static void Main(string[] args) { ACar smartCar = new SmartCar() { Id = 1, Brand = "SmartBrand", Distance = 0, MaxSpeed = 200, Type = CarType.BERLINE }; //smartCar.State = new StateStart(); //smartCar.Execute(); //smartCar.Execute(); //smartCar.Execute(); User user = new User(); smartCar.users.Add(user); ACommand commandStart = new CommandStart(smartCar); ACommand commandMove = new CommandMove(smartCar); ACommand commandStop = new CommandStop(smartCar); user.SetCommand(commandStart); user.ExecuteCommand(); user.SetCommand(commandMove); user.ExecuteCommand(); user.SetCommand(commandStop); user.ExecuteCommand(); Console.ReadKey(); }
public Command HandleMovementInput() { KeyBindings keyBinds = GameManager.GM.keyBinds; Vector3 moveDir = Vector3.zero; if (Input.GetKey(keyBinds.moveForward)) { moveDir += Vector3.forward; } if (Input.GetKey(keyBinds.moveLeft)) { moveDir += Vector3.left; } if (Input.GetKey(keyBinds.moveBackward)) { moveDir += Vector3.back; } if (Input.GetKey(keyBinds.moveRight)) { moveDir += Vector3.right; } CommandMove newMoveCmd = new CommandMove(moveDir.normalized, player); return(newMoveCmd); }
public void OnGrabStop() { if (_targetPrevPos != this.transform.position && _targetPrevRot != this.transform.rotation) { ICommand moveAction = new CommandMove(this.gameObject, _targetPrevPos, _targetPrevRot, this.transform.position, this.transform.rotation); UndoRedoManager.AddNewAction(moveAction); } }
public void Start() { commandMove = transform.parent.GetComponentInChildren <CommandMove>(); c = commandMove.combatController; c.SelectEvent += Activate; lineRenderer = GetComponent <LineRenderer>(); }
public void CommandMove_Constructor() { var direction = DirectionEnum.E; const int Steps = 20; var sut = new CommandMove(direction, Steps); Assert.Equal(direction, sut.Direction); Assert.Equal(Steps, sut.Steps); }
// Use this for initialization void Start() { mCommandStack = new Stack <Command>(); mCallBackTime = 0; moveUp = new CommandMove(new Vector3(0, 0, Time.deltaTime), mCallBackTime); moveDown = new CommandMove(new Vector3(0, 0, -Time.deltaTime), mCallBackTime); moveRight = new CommandMove(new Vector3(Time.deltaTime, 0, 0), mCallBackTime); moveLeft = new CommandMove(new Vector3(-Time.deltaTime, 0, 0), mCallBackTime); rotateLeft = new CommandRotate(new Vector3(0, -Time.deltaTime * 50, 0), mCallBackTime); rotateRight = new CommandRotate(new Vector3(0, Time.deltaTime * 50, 0), mCallBackTime); }
void Start() { commandMove = this.gameObject.GetComponent <CommandMove>(); commandMove.Clicked += NavPointPlace; commandMove.RemoveWaypoint += DeSpawn; CombatController.DeSelectAllEvent += AddColliderToWaypoint; commandMove.combatController.SelectEvent += RemoveColliderFromWaypoint; lineRenderObject = this.gameObject.AddComponent <SpawnLineRenderer>().spawnLineRenderer(this, this.transform.parent.parent.gameObject, false); SetupDependencies(); }
// Update is called once per frame void Update() { if (distanceCompare == null) { distanceCompare = this.transform.parent.GetComponentInChildren <DistanceCompare>(); distanceCompare.InsideRange += InsideRange; distanceCompare.OutOfRange += OutOfRange; return; } if (commandMove == null) { commandMove = this.transform.parent.GetComponentInChildren <CommandMove>(); commandMove.RemoveWaypoint += InsideRangeRC; return; } }
public Command InterpretRequest(string command) { Command interpretation; if (command.Equals(TextCommands.REGISTER, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandRegister(); } else if (command.Equals(TextCommands.LOGIN, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandLogin(); } else if (command.Equals(TextCommands.LOGOUT, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandLogOut(); } else if (command.Equals(TextCommands.JOINMATCH, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandJoin(); } else if (command.Equals(TextCommands.SELECTCHARACTER, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandSelect(); } else if (command.Equals(TextCommands.MOVE, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandMove(); } else if (command.Equals(TextCommands.ATTACK, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandAttack(); } else if (command.Equals(TextCommands.EXIT, StringComparison.InvariantCultureIgnoreCase)) { interpretation = new CommandExit(); } else { interpretation = new CommandUnknown(); } return(interpretation); }
void OnEnable() { commandMove = this.transform.GetComponent <CommandMove>(); commandMove.Clicked += DistanceAdd; }
public override Command deepCopy() { CommandMove copyCommand = new CommandMove(this.moveDistX, this.moveDistY); return(copyCommand); }
protected virtual void OnCommandMove(CommandEventArgs e) { CommandMove?.Invoke(this, e); }
private void ReceiveCommands() { this.HeroQueue = this.Battlefield.GetAllHeroes(); this.CommandStackNormal.Push(this.Battlefield.CreateMemento()); this.RenderBattleField(); String CommandInput; String[] Tokens; while (true) { CommandInput = Console.ReadLine(); Tokens = CommandInput.Split(' '); switch (Tokens[0]) { case "move": if (Tokens.Length != 2) { Console.WriteLine("Invalid syntax"); continue; } List <(int, int)> Coordinates = new List <(int, int)>(); int start_x = this.HeroQueue.First().GetCoordinates()[0]; int start_y = this.HeroQueue.First().GetCoordinates()[1]; if (Tokens[1].Split(',').Count() != 2) { Console.WriteLine("Invalid syntax"); continue; } int end_x = int.Parse(Tokens[1].Split(',')[0]); int end_y = int.Parse(Tokens[1].Split(',')[1]); int x_incerement = start_x < end_x ? 1 : -1; int y_incerement = start_y < end_y ? 1 : -1; int i = start_x; int j = start_y; while (i != end_x) { Coordinates.Add((i, j)); i += x_incerement; } while (j != end_y) { Coordinates.Add((i, j)); j += y_incerement; } Coordinates.Add((i, j)); Console.WriteLine(Coordinates.Count + " coordinates"); Command MoveCommand = new CommandMove(Coordinates); lock (Refreshlock) { RefreshBattleField = true; Monitor.PulseAll(Refreshlock); } this.ExecuteCommand(MoveCommand); lock (Refreshlock) { RefreshBattleField = false; } Thread.Sleep(500); this.RenderBattleField(); break; case "skill": if (Tokens.Length != 3) { Console.WriteLine("Invalid syntax - need 3 params"); continue; } int SkillID = -1; if (!int.TryParse(Tokens[1], out SkillID)) { Console.WriteLine("Invalid syntax - param 1 must be integer"); continue; } Skill Skill = HeroQueue.First().GetSkill(SkillID); if (Skill == null) { Console.WriteLine("Skill with id " + SkillID + " does not exist"); continue; } if (Skill.Passive) { Console.WriteLine("Cannot actively use passive skill"); continue; } ITriggerBehaviour TargetingStrategy = null; switch (Tokens[2]) { case "one": TargetingStrategy = SelectOneTarget.GetInstance(); break; case "auto": TargetingStrategy = SelectAutoTarget.GetInstance(); break; case "area": TargetingStrategy = SelectArea.GetInstance(); break; case "self": TargetingStrategy = SelectSelf.GetInstance(); break; default: break; } if (TargetingStrategy == null) { Console.WriteLine("Invalid target strategy option"); continue; } Command UseSkillCommand = new CommandUseSkill(Skill, Battlefield.GetField(HeroQueue.First().GetCoordinates()[0], HeroQueue.First().GetCoordinates()[1]), TargetingStrategy); this.ExecuteCommand(UseSkillCommand); this.RenderBattleField(); break; case "gather": Command GatherCommand = new CommandGather(this.HeroQueue.First()); this.ExecuteCommand(GatherCommand); this.RenderBattleField(); break; case "end": this.CommandStackNormal.Clear(); this.CommandStackNormal.Push(this.Battlefield.CreateMemento()); this.CommandStackReverse.Clear(); HeroInterface Temp = this.HeroQueue.First(); Temp.RestoreTurn(); this.HeroQueue.RemoveFirst(); this.HeroQueue.AddLast(Temp); this.RenderBattleField(); break; case "undo": if (this.CommandStackNormal.Count > 1) { this.CommandStackReverse.Push(this.CommandStackNormal.Pop()); this.Battlefield.Restore(this.CommandStackNormal.Peek()); this.RenderBattleField(); } break; case "redo": if (this.CommandStackReverse.Any()) { this.CommandStackNormal.Push(this.CommandStackReverse.Pop()); this.Battlefield.Restore(this.CommandStackNormal.Peek()); this.RenderBattleField(); } break; case "refresh": this.RenderBattleField(); break; case "exit": this.Over = true; break; default: Console.WriteLine("Unknown command"); break; } if (Over) { lock (Refreshlock) { Monitor.PulseAll(Refreshlock); } break; } } ObserverFactory.GetInstance().Finish(); }
//This region handles the two movement commands /// <summary> /// Starts the movement process, /// it is intended to run once when the mouse button is pressed, /// and to be finished with the Move function. /// </summary> /// <param name="shape">The shape to move</param> /// <param name="initialPos">The initial position of the mouse moving the shape</param> public void StartMove(CanvasShape shape, Point initialPos) { ICommand cmd = new CommandMove(shape, initialPos, MainWindow); actionsDone.Push(cmd); }