-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
2次元座標上の位置を扱いやすくするためのクラスの提案
向きによって決まる位置(前や右手など)をどうするか固まっていないので保留中
import { synonymizeClass, PropertyMissing } from './synonyms/synonymize';
import { synonyms } from './synonyms/location';
/**
* 2次元座標上の位置を扱いやすくするクラス
*/
export class Location {
/**
* このばしょがマップの左端から数えて何マス目か(0から数える)
*/
public readonly x: number;
/**
* このばしょがマップの上端から数えて何マス目か(0から数える)
*/
public readonly y: number;
/**
* このばしょが何という名前のマップにあるか
*/
public readonly map: string;
constructor(x: number, y: number, map: string) {
this.x = x;
this.y = y;
this.map = map;
}
/**
* 他のキャラクターがこのばしょにいるかどうかを調べる
* @param other ばしょを調べたいキャラクターの変数
*/
equalsTo(other: Location | { location: Location }): boolean {
return other instanceof Location
? this.x === other.x && this.y === other.y && this.map === other.map
: this.equalsTo(other.location);
}
up() {
return new Location(this.x, this.y - 1, this.map);
}
[PropertyMissing](chainName: string) {}
}
export const LocationWithSynonyms = synonymizeClass(Location, synonyms);Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request