-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cbb405
commit e27f2d0
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Prop from "./prop"; | ||
|
||
export default Prop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, it, expect } from "bun:test"; | ||
import Prop from "./prop"; | ||
|
||
describe("Prop", () => { | ||
it("Has health", () => { | ||
const p = new Prop({ health: 1000 }); | ||
expect(p.health).toBe(1000); | ||
}); | ||
|
||
it("Has level 1", () => { | ||
const p = new Prop(); | ||
expect(p.level).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Vec2d from "../utils/vec2d"; | ||
import { AttackTarget } from "../actions"; | ||
import { Neutral } from "../factions"; | ||
|
||
interface PropOptions { | ||
health?: number; | ||
position?: Vec2d; | ||
} | ||
|
||
export default class Prop implements AttackTarget, Neutral { | ||
#health: number; | ||
readonly position: Vec2d; | ||
readonly isNeutral = true; | ||
|
||
constructor({ health = 1000, position = new Vec2d() }: PropOptions = {}) { | ||
this.#health = health; | ||
this.position = position; | ||
} | ||
|
||
get level() { | ||
return 1; | ||
} | ||
|
||
get isAlive() { | ||
return this.health > 0; | ||
} | ||
|
||
get health() { | ||
return this.#health; | ||
} | ||
|
||
set health(value: number) { | ||
this.#health = Math.max(0, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters