diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/EntityPosition.ts | 5 | ||||
-rw-r--r-- | src/model/Position.ts | 26 | ||||
-rw-r--r-- | src/model/Transition.ts | 8 |
3 files changed, 38 insertions, 1 deletions
diff --git a/src/model/EntityPosition.ts b/src/model/EntityPosition.ts index 815eceb..28b3837 100644 --- a/src/model/EntityPosition.ts +++ b/src/model/EntityPosition.ts @@ -1,11 +1,14 @@ 'use strict'; -import Direction from '../model/Direction'; +import Direction from './Direction'; import Entity from './Entity'; import Position from './Position'; +import Transition from './Transition'; export default class EntityPosition { + public transition: Transition = null; + constructor(public entity: Entity, public position: Position, public direction: Direction) {} } diff --git a/src/model/Position.ts b/src/model/Position.ts index 1db37af..1f9b719 100644 --- a/src/model/Position.ts +++ b/src/model/Position.ts @@ -1,9 +1,35 @@ 'use strict'; +import Direction from './Direction'; + + export default class Position { constructor(public x: number, public y: number) {} + translate(dir: Direction, amount: number): Position { + var p = new Position(this.x, this.y); + + switch (dir) { + case Direction.North: + p.y -= amount; + break; + + case Direction.East: + p.x += amount; + break; + + case Direction.South: + p.y += amount; + break; + + case Direction.West: + p.x -= amount; + } + + return p; + } + asString(): string { return `${this.x},${this.y}`; } diff --git a/src/model/Transition.ts b/src/model/Transition.ts new file mode 100644 index 0000000..0a3e69b --- /dev/null +++ b/src/model/Transition.ts @@ -0,0 +1,8 @@ +'use strict'; + + +import Position from './Position'; + +export default class Transition { + constructor(public start: number, public end: number, public orig: Position, public dest: Position) {} +}; |