Skip to content

Commit

Permalink
score
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Nov 18, 2023
1 parent 35eb26b commit 9d0b48b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/diagram.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/controller/rules/nineball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class NineBall implements Rules {
cueball: Ball
currentBreak = 0
previousBreak = 0
score = 0

constructor(container) {
this.container = container
Expand Down Expand Up @@ -81,7 +82,9 @@ export class NineBall implements Rules {
return new WatchAim(this.container)
}
if (Outcome.isBallPottedNoFoul(table.cueball, outcome)) {
this.currentBreak += Outcome.potCount(outcome)
const pots = Outcome.potCount(outcome)
this.currentBreak += pots
this.score += pots
this.container.sound.playSuccess(table.inPockets())
if (this.isEndOfGame(outcome)) {
this.container.eventQueue.push(new ChatEvent(null, `game over`))
Expand Down
1 change: 1 addition & 0 deletions src/controller/rules/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Rules {
cueball: Ball
currentBreak: number
previousBreak: number
score: number
update(outcome: Outcome[]): Controller
rack(): Ball[]
tableGeometry()
Expand Down
2 changes: 2 additions & 0 deletions src/controller/rules/snooker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Snooker implements Rules {
currentBreak = 0
previousBreak = 0
foulPoints = 0
score = 0

static readonly tablemodel = "models/snooker.min.gltf"

Expand Down Expand Up @@ -181,6 +182,7 @@ export class Snooker implements Rules {
this.previousPotRed = false
this.targetIsRed = SnookerUtils.redsOnTable(this.container.table).length > 0
this.previousBreak = this.currentBreak
this.score += this.currentBreak
this.currentBreak = 0
this.container.hud.updateBreak(this.currentBreak)
}
Expand Down
3 changes: 3 additions & 0 deletions src/controller/rules/threecushion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ThreeCushion implements Rules {
cueball: Ball
currentBreak = 0
previousBreak = 0
score = 0

constructor(container) {
this.container = container
Expand Down Expand Up @@ -74,6 +75,8 @@ export class ThreeCushion implements Rules {
if (Outcome.isThreeCushionPoint(this.cueball, outcomes)) {
this.container.sound.playSuccess(outcomes.length / 3)
this.container.sendEvent(new WatchEvent(this.container.table.serialise()))
this.currentBreak++
this.score++
return new Aim(this.container)
}

Expand Down
8 changes: 7 additions & 1 deletion src/events/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ export class Recorder {
}

wholeGame() {
return this.state(this.states[0], this.shots, this.start, 0, true)
return this.state(
this.states[0],
this.shots,
this.start,
this.container.rules.score,
true
)
}

last() {
Expand Down

0 comments on commit 9d0b48b

Please sign in to comment.