Skip to content

Commit

Permalink
add city damange value
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Jan 25, 2025
1 parent a55890d commit 860f9ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/entity/City.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { CityEvent, CityEventType, CityInitializedEvent } from "./CityEvent";
type EventHandler<T extends CityEvent> = (event: T) => void;

export class City {
static readonly MAX_DAMAGE = 100;

private _events: CityEvent[] = [];

constructor(public readonly id: string) {
Expand All @@ -21,6 +23,14 @@ export class City {
this._events.push(event);
}

public get damage(): number {
return 0;
}

public get isDestroyed(): boolean {
return this.damage >= City.MAX_DAMAGE;
}

public get events(): CityEvent[] {
return this._events.map((event) => ({ ...event }) as CityEvent);
}
Expand Down
4 changes: 4 additions & 0 deletions src/usecase/CitySnapshotUsecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { CityRepository } from "./interface";

export type CitySnapshot = {
id: string;
damage: number;
isDestroyed: boolean;
};

export class CitySnapshotUsecase {
Expand All @@ -15,6 +17,8 @@ export class CitySnapshotUsecase {

return {
id: city.id,
damage: city.damage,
isDestroyed: city.isDestroyed,
};
}
}

0 comments on commit 860f9ed

Please sign in to comment.