Skip to content

Commit

Permalink
Refactor scoreboard object methods for clarity and consistency (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelRipoll23 authored Jan 4, 2025
1 parent 915e6fe commit 30ba022
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/objects/scoreboard-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ export class ScoreboardObject
private readonly FONT_SIZE: string = "36px";
private readonly FONT_FAMILY: string = "monospace";

private readonly TIME_TEXT_COLOR: string = "white";
private readonly TIME_FONT_SIZE: string = "32px";

private readonly BLUE_SHAPE_COLOR: string = BLUE_TEAM_COLOR;
private readonly RED_SHAPE_COLOR: string = RED_TEAM_COLOR;
private readonly SHAPE_FILL_COLOR: string = "white";
private readonly TIME_BOX_FILL_COLOR: string = "#4caf50"; // Added property for time box fill color

private x: number;
Expand Down Expand Up @@ -86,11 +82,11 @@ export class ScoreboardObject
this.redScore++;
}

public setBlueTeamScore(score: number): void {
public setBlueScore(score: number): void {
this.blueScore = score;
}

public setRedTeamScore(score: number): void {
public setRedScore(score: number): void {
this.redScore = score;
}

Expand Down Expand Up @@ -118,10 +114,8 @@ export class ScoreboardObject

public update(deltaTimeStamp: DOMHighResTimeStamp): void {
if (this.active) {
this.elapsedMilliseconds += deltaTimeStamp;

if (this.elapsedMilliseconds >= this.durationMilliseconds) {
this.stopTimer();
if (this.elapsedMilliseconds < this.durationMilliseconds) {
this.elapsedMilliseconds += deltaTimeStamp;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/screens/world-screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,13 @@ export class WorldScreen extends BaseCollidingGameScreen {
players.forEach((player) => {
const score = player.getScore();
if (player === this.gameState.getGamePlayer()) {
return this.scoreboardObject?.setBlueTeamScore(score);
return this.scoreboardObject?.setBlueScore(score);
}

totalScore += score;
});

this.scoreboardObject?.setRedTeamScore(totalScore);
this.scoreboardObject?.setRedScore(totalScore);
}

private showGoalAlert(
Expand Down

0 comments on commit 30ba022

Please sign in to comment.