blob: 1f9b71903bc991ba2b70b7750a968f085b4abb44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
'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}`;
}
}
|