28 lines
571 B
TypeScript
28 lines
571 B
TypeScript
import { Rectangle } from "./rectangle";
|
|
|
|
export class Door {
|
|
private _day = -1;
|
|
public position: Rectangle;
|
|
|
|
constructor(position: Rectangle);
|
|
constructor(position: Rectangle, day: number);
|
|
constructor(position: Rectangle, day = -1) {
|
|
this.day = day;
|
|
this.position = position;
|
|
}
|
|
|
|
public get day(): number {
|
|
return this._day;
|
|
}
|
|
|
|
public set day(day: unknown) {
|
|
// integer coercion
|
|
const result = Number(day);
|
|
|
|
if (isNaN(result)) {
|
|
this._day = -1;
|
|
} else {
|
|
this._day = Math.max(Math.floor(result), -1);
|
|
}
|
|
}
|
|
}
|