diff options
Diffstat (limited to 'src/model/Position.ts')
-rw-r--r-- | src/model/Position.ts | 26 |
1 files changed, 26 insertions, 0 deletions
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}`; } |