// Update is called once per frame void FixedUpdate() { rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (Input.GetKey("d")) // MOVE RIGHT { //////////////////////////////////////////////////////////////////////////// // --- IMPLEMENTING THE COMMAND PATTERN - START HERE --- // instead of just calling addforce, we want to package this up as a command // and send to an invoker // we'll need a command class, some commands, and an invoker... //rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveRight = new TurnRight(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveRight); invoker.ExecuteCommand(); } if (Input.GetKey("a")) // MOVE LEFT { //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveLeft = new TurnLeft(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveLeft); invoker.ExecuteCommand(); } if (rb.position.y < -1f) { FindObjectOfType <GameManager>().EndGame(null); } }
public void TurnRightWhenFacingWest(int startXCord, int startYCord) { const Heading startingHeading = Heading.West; var command = new TurnRight(); RobotVector result = command.GenerateNewVector(new RobotVector(new Position(startXCord, startYCord), startingHeading)); DirectionAssertions.AssertHasTurnedToFaceNorth(startXCord, startYCord, result); }
public void TurnRoverRightWhenExecuteIsCalled() { TurnRight turnRightCommand = new TurnRight(rover); turnRightCommand.Execute(); int expectedCoordX = 0; int expectedCoordY = 0; char expectedDirectionInfo = 'E'; Assert.Equal(expectedCoordX, rover.currentCoordinates.coordX); Assert.Equal(expectedCoordY, rover.currentCoordinates.coordY); Assert.Equal(expectedDirectionInfo, rover.GetDirection()); }
public float sidewaysForce = 500f; // Variable that determines the sideways force // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A)) { command TurnLeft = new TurnLeft(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(TurnLeft); invoker.ExecuteCommand(); } if (Input.GetKeyDown(KeyCode.D)) { command TurnRight = new TurnRight(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(TurnRight); invoker.ExecuteCommand(); } }
private void InitalizeCommandMapping() { var advanceCommand = new Advance(AppSettings.SafeGet <int>(Instructions.A.ToString())); CommandMapping.Add(Instructions.A, advanceCommand); var backCommand = new Back(AppSettings.SafeGet <int>(Instructions.B.ToString())); CommandMapping.Add(Instructions.B, backCommand); var cleanCommand = new Clean(AppSettings.SafeGet <int>(Instructions.C.ToString())); CommandMapping.Add(Instructions.C, cleanCommand); var turnLeft = new TurnLeft(AppSettings.SafeGet <int>(Instructions.TL.ToString())); CommandMapping.Add(Instructions.TL, turnLeft); var turnRight = new TurnRight(AppSettings.SafeGet <int>(Instructions.TR.ToString())); CommandMapping.Add(Instructions.TR, turnRight); }
public bool DrivingCar(MonsterTruck mTruck, Room room) { foreach (var item in LatestInput) { if (mTruck.XPosition <= room.XAxis && mTruck.YPosition <= room.YAxis && mTruck.XPosition > 0 && mTruck.YPosition > 0) { switch (item.ToString().ToUpper()) { case "F": DriveForward.DriveCarForward(mTruck); break; case "B": DriveBackwards.DriveCarBackwards(mTruck); break; case "L": TurnLeft.TurnCarLeft(mTruck); break; case "R": TurnRight.TurnCarRight(mTruck); break; } } else { //If it crashes before it is finished, there will be no need to continue the simulation break; } } if (mTruck.XPosition > room.XAxis || mTruck.XPosition < 1 || mTruck.YPosition > room.YAxis || mTruck.YPosition < 1) { return(false); } else { return(true); } }
public AgentPosition apply(AgentPosition state, IAction action) { if (action is Forward) { Forward fa = (Forward)action; return(fa.getToPosition()); } else if (action is TurnLeft) { TurnLeft tLeft = (TurnLeft)action; return(new AgentPosition(state.getX(), state.getY(), tLeft.getToOrientation())); } else if (action is TurnRight) { TurnRight tRight = (TurnRight)action; return(new AgentPosition(state.getX(), state.getY(), tRight.getToOrientation())); } // The Action is not understood or is a NoOp // the result will be the current state. return(state); }
// Start is called before the first frame update void Start() { GenerateBoard(); GenerateValues(); Button mov1 = Move1.GetComponent <Button>(); Button mov2 = Move2.GetComponent <Button>(); Button back = BackUp.GetComponent <Button>(); Button left = TurnLeft.GetComponent <Button>(); Button right = TurnRight.GetComponent <Button>(); Button turn180 = UTurn.GetComponent <Button>(); mov1.onClick.AddListener(MovePlayer1); mov2.onClick.AddListener(MovePlayer2); back.onClick.AddListener(BackPlayerUp); left.onClick.AddListener(TurnPlayerLeft); right.onClick.AddListener(TurnPlayerRight); turn180.onClick.AddListener(TurnPlayerU); player.GetComponent <PlayerManager>().ai = ai; ai.GetComponent <AIManager>().player = player; endCanvas.SetActive(false); normalCanvas.SetActive(true); }
public virtual IEnumerator<ITask> TurnLeftHandler(TurnRight turnLeft) { SendNotification(_submgrPort, turnLeft); yield break; }