void HandleInput() { Command command = null; if (Input.GetKeyDown(KeyCode.W)) { command = new MoveForwardCommand(); } else if (Input.GetKeyDown(KeyCode.S)) { command = new MoveBackwardCommand(); } else if (Input.GetKeyDown(KeyCode.A)) { command = new MoveLeftCommand(); } else if (Input.GetKeyDown(KeyCode.D)) { command = new MoveRightCommand(); } else if (Input.GetKeyDown(KeyCode.Z)) { Undo(); } else if (Input.GetKeyDown(KeyCode.R)) { Redo(); } if (command != null) { undoCommands.Push(command); command.Execute(Box); } }
private void SelectTile(TileViewModel tile) { if (tile == SelectedTile) { tile = null; } SelectedTile?.Deselect(); SelectedTile = tile; SelectedTile?.Select(); MoveDownCommand.OnCanExecuteChanged(); MoveLeftCommand.OnCanExecuteChanged(); MoveUpCommand.OnCanExecuteChanged(); MoveRightCommand.OnCanExecuteChanged(); DeleteTileCommand.OnCanExecuteChanged(); OnPropertyChanged("HintVisibility"); if (SelectedTile != null) { ShowEditInfo(); } else { HideEditInfo(); } }
void Update() { if (Input.GetKey(upKey)) { moveUp = new MoveUpCommand(this.transform, _speed); moveUp.Execute(); CommandManager.Instance.AddBuffer(moveUp); } else if (Input.GetKey(downKey)) { moveDown = new MoveDownCommand(this.transform, _speed); moveDown.Execute(); CommandManager.Instance.AddBuffer(moveDown); } else if (Input.GetKey(rightKey)) { moveRight = new MoveRightCommand(this.transform, _speed); moveRight.Execute(); CommandManager.Instance.AddBuffer(moveRight); } if (Input.GetKey(leftKey)) { moveLeft = new MoveLeftCommand(this.transform, _speed); moveLeft.Execute(); CommandManager.Instance.AddBuffer(moveLeft); } }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Z)) { // Move up command moveUp = new MoveUpCommand(this.transform, this._speed); moveUp.Execute(); MoveCommandManager.Instance.AddCommand(moveUp); } else if (Input.GetKey(KeyCode.S)) { // Move down command moveDown = new MoveDownCommand(this.transform, this._speed); moveDown.Execute(); MoveCommandManager.Instance.AddCommand(moveDown); } else if (Input.GetKey(KeyCode.Q)) { // Move left command moveLeft = new MoveLeftCommand(this.transform, this._speed); moveLeft.Execute(); MoveCommandManager.Instance.AddCommand(moveLeft); } else if (Input.GetKey(KeyCode.D)) { // Move right command moveRight = new MoveRightCommand(this.transform, this._speed); moveRight.Execute(); MoveCommandManager.Instance.AddCommand(moveRight); } }
private void Start() { _moveUp = new MoveUpCommand(this.transform, speed); _moveDown = new MoveDownCommand(this.transform, speed); _moveLeft = new MoveLeftCommand(this.transform, speed); _moveRight = new MoveRightCommand(this.transform, speed); }
void Update() { if (Input.GetKey(KeyCode.W)) { moveUp = new MoveUpCommand(this.transform, _speed); moveUp.Execute(); CommandManger_2.Instance.AddCommand(moveUp); } else if (Input.GetKey(KeyCode.S)) { moveDown = new MoveDownCommand(this.transform, _speed); moveDown.Execute(); CommandManger_2.Instance.AddCommand(moveDown); } else if (Input.GetKey(KeyCode.A)) { moveLeft = new MoveLeftCommand(this.transform, _speed); moveLeft.Execute(); CommandManger_2.Instance.AddCommand(moveLeft); } else if (Input.GetKey(KeyCode.D)) { moveRight = new MoveRightCommand(this.transform, _speed); moveRight.Execute(); CommandManger_2.Instance.AddCommand(moveRight); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { player = new PlayerContext(Content, new Vector2(0, 0)); // Initialize commands ICommand quitCommand = new QuitCommand(this); ICommand moveLeftCommand = new MoveLeftCommand(player); ICommand moveRightCommand = new MoveRightCommand(player); ICommand moveUpCommand = new MoveUpCommand(player); ICommand moveDownCommand = new MoveDownCommand(player); // Link keys to commands Dictionary <Keys, ICommand> keysMap = new Dictionary <Keys, ICommand>(); keysMap.Add(Keys.Q, quitCommand); keysMap.Add(Keys.Left, moveLeftCommand); keysMap.Add(Keys.Right, moveRightCommand); keysMap.Add(Keys.Up, moveUpCommand); keysMap.Add(Keys.Down, moveDownCommand); //secondary commands for WASD keysMap.Add(Keys.W, moveUpCommand); keysMap.Add(Keys.A, moveLeftCommand); keysMap.Add(Keys.S, moveDownCommand); keysMap.Add(Keys.D, moveRightCommand); // Add controls to controller keyboardController = new KeyboardController(keysMap); base.Initialize(); }
public void MoveLeftCommand_When_NewDesk_Then_NoMoving() { var desk = _helper.GenerateDesk(4); var moveCommand = new MoveLeftCommand(desk); bool res = moveCommand.Execute(); Assert.False(res); }
public void MoveLeftCommand_When_NewDesk_Then_DeskDoesntChange() { var newDesk = _helper.GenerateDesk(4); var desk = _helper.GenerateDesk(4); var moveCommand = new MoveLeftCommand(desk); moveCommand.Execute(); Assert.Equal(newDesk.GetDesk(), desk.GetDesk()); }
public void HoverCommand_ShouldExecuteClientMoveLeft() { // arrange moveLeftCommand = new MoveLeftCommand(DroneClientMock.Object); // act moveLeftCommand.Execute(); // assert DroneClientMock.Verify(x => x.MoveLeft(), Times.Once); }
public bool Update() { if (Math.Abs(Peach.Location.X - GoalLocation.X) < 5) { Peach.IdleTransition(); foreach (IEntity entity in Collections.Instance.GetLevelRef().Entities) // explode all remaining brick blocks on ceiling { if (entity is GlassBlock glassBlock) { int count = glassBlock.ContainedItems.Count; glassBlock.ExplodeBrickBlockTransition(); for (int i = Constants.ZERO; i < count; i++) { ExplodingBlock child = (ExplodingBlock)glassBlock.ContainedItems[i]; // must do following for all four exploding blocks child.Visible = true; if (i == 1) { child.Sprite.Velocity = new Vector2(-300, -300); // make the blocks go in different directions } else if (i == 2) { child.Sprite.Velocity = new Vector2(300, 300); } else if (i == 3) { child.Sprite.Velocity = new Vector2(300, -300); } else if (i == 4) { child.Sprite.Velocity = new Vector2(-300, 300); } child.ExplodingBlockTransition(); } } } return(true); } else { if (Peach.Location.X > GoalLocation.X) { ICommand moveLeft = new MoveLeftCommand(Peach); moveLeft.Execute(); } else { ICommand moveRight = new MoveRightCommand(Peach); moveRight.Execute(); } } return(false); }
public InputManager() { moveUp = new MoveUpCommand(); moveDown = new MoveDownCommand(); moveRight = new MoveRightCommand(); moveLeft = new MoveLeftCommand(); stopMoveUp = new StopMoveUpCommand(); stopMoveLeft = new StopMoveLeftCommand(); stopMoveRight = new StopMoveRightCommand(); stopMoveDown = new StopMoveDownCommand(); attack = new AttackCommand(); rangedAttack = new RangedAttackCommand(); }
public void ShouldInvokeMoveLeftAndSetStateToHandled() { var slnControl = new Mock <ISolutionExplorerControl>(); slnControl.Setup(x => x.MoveLeft()); var command = new MoveLeftCommand(slnControl.Object); var context = new Context(); var result = command.Execute(context, Keys.H); Assert.Equal(CommandState.Handled, result.State); slnControl.VerifyAll(); }
public Command CreateCommand(CommandType commandType) { Command command = null; switch (commandType) { case CommandType.Start: command = new StartCommand(drone); break; case CommandType.Stop: command = new StopCommand(drone); break; case CommandType.Configure: command = new ConfigureCommand(drone); break; case CommandType.MoveBackward: command = new MoveBackwardCommand(drone); break; case CommandType.MoveDown: command = new MoveDownCommand(drone); break; case CommandType.MoveForward: command = new MoveForwardCommand(drone); break; case CommandType.MoveLeft: command = new MoveLeftCommand(drone); break; case CommandType.MoveRight: command = new MoveRightCommand(drone); break; case CommandType.MoveUp: command = new MoveUpCommand(drone); break; case CommandType.Hover: command = new HoverCommand(drone); break; default: throw new ArgumentException("Invalid command type"); } return(command); }
public InputManager(GameObject player) { this.player = player; moveUp = new MoveUpCommand(); moveDown = new MoveDownCommand(); moveRight = new MoveRightCommand(); moveLeft = new MoveLeftCommand(); stopMoveUp = new StopMoveUpCommand(); stopMoveLeft = new StopMoveLeftCommand(); stopMoveRight = new StopMoveRightCommand(); stopMoveDown = new StopMoveDownCommand(); attack = new AttackCommand(); rangedAttack = new RangedAttackCommand(); }
void InitInputManager() { ioMgr = GetComponent <InputManager>(); jump = new JumpCommand(pc); stopJump = new StopJumpCommand(pc); dash = new DashCommand(pc); left = new MoveLeftCommand(pc); right = new MoveRightCommand(pc); stopHor = new StopMoveHorCommand(pc); up = new MoveUpCommand(pc); down = new MoveDownCommand(pc); stopVer = new StopMoveVerCommand(pc); attack = new AttackCommand(pc); interact = new InteractCommand(pc); }
public void SetActivePlayer() { up = new MoveUpCommand(); left = new MoveLeftCommand(); down = new MoveDownCommand(); right = new MoveRightCommand(); escape = new EscapeButtonCommand(); actionButtonOne = new ActionButtonOne(); actionButtonTwo = new ActionButtonTwo(); actionButtonThree = new ActionButtonThree(); actionButtonFour = new ActionButtonFour(); actionButtonFive = new ActionButtonFive(); openCloseBook = new EButtonCommand(); openCloseQuests = new TabButtonCommand(); }
public void TestCommandMoveLeft() { // Arrange int originalLocationX = fakeGameComponent.X; Command moveLeft = new MoveLeftCommand(); int finalLocationX; // The amount the game object should move in one command int expectedMoveAmount = 1; // Act moveLeft.Execute(fakeGameComponent); finalLocationX = fakeGameComponent.X; // Assert Assert.AreEqual(finalLocationX, originalLocationX - expectedMoveAmount); }
ICommand GetMoveCommandFromKey() { Command command = null; if (Input.GetKey(KeyCode.D)) { command = new MoveRightCommand(); //keyDirection.x += 1; keyDirection.x = moveComponent.X; } if (Input.GetKey(KeyCode.A)) { command = new MoveLeftCommand(); //keyDirection.x += -1; keyDirection.x = -moveComponent.X; } return(command); }
public Singleplayer() { playfield = new PlayField(); ball = new Ball(); paddle = new Paddle(); scoreboard = new ScoreBoard(); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 10); timer.IsEnabled = false; timer.Tick += timer_Tick; StartCommand = new StartCommand(this); StopCommand = new StopCommand(this); PlayCommand = new PlayCommand(this); PauseCommand = new PauseCommand(this); MoveLeftCommand = new MoveLeftCommand(this); MoveRightCommand = new MoveRightCommand(this); StopMovingCommand = new StopMovingCommand(this); InitializeGame(); }
public GameController(Game1 game) { _keyboard = new KeyboardController(); var quit = new QuitCommand(game); BindCommand(quit, null, Keys.Q); var moveLeft = new MoveLeftCommand(game); var releaseLeft = new ReleaseLeftCommand(game); var moveRight = new MoveRightCommand(game); var releaseRight = new ReleaseRightCommand(game); var jump = new JumpCommand(game); var releaseJump = new ReleaseJumpCommand(game); BindCommand(moveLeft, releaseLeft, Keys.A); BindCommand(moveRight, releaseRight, Keys.D); BindCommand(jump, releaseJump, Keys.W); var boundbox = new DrawBoundBoxCommand(game); BindCommand(boundbox, null, Keys.C); }
private void Awake() { Application.targetFrameRate = 30; jumpCommand = new JumpCommand(); moveLeftCommand = new MoveLeftCommand(); moveRightCommand = new MoveRightCommand(); notMoveCommand = new NotMoveCommand(); doNothingCommand = new DoNothingCommand(); transgressionCommand = new TransgressionCommand(); pauseCommand = new PauseCommand(); interactCommand = new InteractCommand(); commands = new Dictionary <string, Command> { { "Jump", jumpCommand }, { "Teleport", transgressionCommand }, { "Use", interactCommand } }; commandsWithoutPlayer = new Dictionary <string, Command> { { "Exit", pauseCommand } }; }
private void Update() { if (!_isPaused) { if (Input.GetKey(KeyCode.LeftArrow)) { var command = new MoveLeftCommand(rb, _playerSpeed, commandLagTime); command.Execute(); CommandManager.Instance.AddCommand(command); commandLagTime = 0; } if (Input.GetKeyUp(KeyCode.LeftArrow)) { var command = new StopCommand(rb, commandLagTime); command.Execute(); CommandManager.Instance.AddCommand(command); commandLagTime = 0; } if (Input.GetKey(KeyCode.RightArrow)) { var command = new MoveRightCommand(rb, _playerSpeed, commandLagTime); command.Execute(); CommandManager.Instance.AddCommand(command); commandLagTime = 0; } if (Input.GetKeyUp(KeyCode.RightArrow)) { var command = new StopCommand(rb, commandLagTime); command.Execute(); CommandManager.Instance.AddCommand(command); commandLagTime = 0; } commandLagTime += Time.deltaTime; } }
private void MoverRight() { SelectedTile.Column++; MoveLeftCommand.OnCanExecuteChanged(); MoveRightCommand.OnCanExecuteChanged(); }
protected void HandleCommand(MoveLeftCommand lftCmnd) { Walk(Direction.Left); }
private void Form1_Load(object sender, EventArgs e) { _signalR.RegisterPlayer(); // Create Board Matrix Tuple <int, int> PacmanStartCoordinates = gameboard.InitialiseBoardMatrix(1); SetupGame(1); playerData.RegisterObserver(player); playerData.RegisterObserver(highscore); _hubConnection.On("ReceiveRegisterCompletedMessage", () => { facade.Log.AppendText($"\nWait until your friend opens this game then press F1 to join the game!\n" + $"Player1 plays with blue pacman, Player2 plays with red.\n"); facade.Log.AppendText($"\nPlayer lives: {player.Lives}"); }); _hubConnection.On <string>("ReceiveConnectedMessage", (connnectionId) => { this.Invoke((Action)(() => { Player newPlayer = new Player(connnectionId, "Player" + (players.Count + 1)); _api.CreatePlayer(newPlayer); players.Add(newPlayer); if (players.Count == 2) { // Decrator pacman = blueFactory.CreatePacman(_signalR, players.First().Id); //pacman = new PinkBorderDecorator(pacman); pacman.AddPacmanImages(); opponent = redFactory.CreatePacman(_signalR, players.Last().Id); opponent.AddPacmanImages(); pacmans.Add(pacman); pacmans.Add(opponent); moveUp = new MoveUpCommand(opponent); moveDown = new MoveDownCommand(opponent); moveRight = new MoveRightCommand(opponent); moveLeft = new MoveLeftCommand(opponent); ghost.EnableTimer(); foreach (var p in pacmans) { p.CreatePacmanImage(this, PacmanStartCoordinates.Item1, PacmanStartCoordinates.Item2); p.EnableTImer(); } // For Observer testing playerData.EditLives(5); facade.Log.AppendText($"\nPlayer lives: {player.Lives}"); } facade.Log.AppendText($"\n{newPlayer.Name} with id {connnectionId} joined the game!" + $"\nTotal players: {players.Count}"); })); }); _hubConnection.On <int, int, int, string>("ReceivePacmanCoordinates", (xCoordinate, yCoordinate, direction, id) => { this.Invoke((Action)(() => { // Logging movement Pacman currentPacman = pacmans.Single(p => p.Id == id); Player currentPlayer = players.Single(p => p.Id == id); _pacmanLogAdapter = new PacmanLogAdapter(currentPacman); _playerLogAdapter = new PlayerLogAdapter(currentPlayer); _fileLogger.LogData(string.Format("pacman ID: {0} | xCoordinate:{1} | yCordinate:{2} | date:{3}", currentPacman.Id, currentPacman.xCoordinate, currentPacman.yCoordinate, DateTime.UtcNow)); _pacmanLogAdapter.LogData(null); _playerLogAdapter.LogData(null); facade.Log.ScrollToCaret(); pacmans.Single(p => p.Id == id).nextDirection = direction; })); }); }