import { Direction } from "../core" ; import { MovementState } from "../managers" ; import { Strategy } from "./Strategy" ; /**
 * A movement strategy.
 */ export class MovementStrategy implements Strategy { /**
     * A movement state.
     */ private movementState : MovementState ; /**
     * A direction.
     */ private direction : Direction ; param movementState param direction constructor ( movementState , direction ) { this . movementState = movementState ; this . direction = direction ; } execute ( flag ) { const state = this . movementState ; switch ( this . direction ) { case Direction . BACKWARD : state . backward = flag ; state . backwardBeforeForward = flag ; break ; case Direction . FORWARD : state . forward = flag ; state . backwardBeforeForward = ! flag ; break ; case Direction . RIGHT : state . right = flag ; state . rightBeforeLeft = flag ; break ; case Direction . LEFT : state . left = flag ; state . rightBeforeLeft = ! flag ; break ; case Direction . UP : state . up = flag ; state . upBeforeDown = flag ; break ; case Direction . DOWN : state . down = flag ; state . upBeforeDown = ! flag ; break ; } } }