Skip to content

Commit

Permalink
feat(game): Force user to click correct answer in practice mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CaedenPH committed Apr 6, 2024
1 parent a354b0b commit 857c941
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/routes/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ export class CogSpeedGame {
currentRoundTimeout: NodeJS.Timeout | undefined;

// Misc
isInPause: number | null;
isInPauseFromTimeout: number | null;


constructor(
public config: Config,
private app: Application | null = null,
private ui: CogSpeedGraphicsHandler | null = null,
private sleepData: SleepData | null = null,
) {
this.isInPause = null;
this.isInPauseFromTimeout = null;
}

/**
Expand Down Expand Up @@ -99,6 +100,7 @@ export class CogSpeedGame {
* Simply runs the next round
*/
nextRound() {
console.log("next round called", this.currentRound);
this.ui?.clearStage();

// Create random answer location
Expand Down Expand Up @@ -135,13 +137,13 @@ export class CogSpeedGame {

async displayCorrectAnswer() {
if (!this.ui?.inputButtons) return;
this.isInPause = this.answer;
this.isInPauseFromTimeout = this.answer;

const answerSprite = this.ui.inputButtons[6 - this.answer];

// TODO: Exit if incorrect button was pressed immediately
if (await this.ui.waitForKeyPressCorrectAnswer(answerSprite, this.config.practice_mode.no_response_duration)) {
this.isInPause = null;
this.isInPauseFromTimeout = null;
return
}
return this.stop(4);
Expand Down Expand Up @@ -404,7 +406,7 @@ export class CogSpeedGame {
* @param {number} timeClicked The time (performance.now) the button was clicked
*/
public buttonClicked(location: number | null = null, timeClicked: number | null = null): boolean {
if (this.ui && this.isInPause !== null && this.isInPause !== location) {
if (this.ui && this.isInPauseFromTimeout !== null && this.isInPauseFromTimeout !== location) {
// It should only respond to one in this mode
this.ui.rippleAnimation(this.ui.inputButtons[6 - this.answer]);
return false;
Expand Down Expand Up @@ -474,6 +476,12 @@ export class CogSpeedGame {
this.previousAnswers[this.previousAnswers.length - 1].correctRollingMeanRatio = this.getCorrectRollingMean();
}

if (location && location !== this.answer && [0, 1].includes(this.currentRound)) {
// Force the correct answer to be clicked before moving on
this.displayCorrectAnswer();
return false;
}

this.nextRound();
return true;
}
Expand Down
1 change: 0 additions & 1 deletion src/ui/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ export class CogSpeedGraphicsHandler {
// Block until the start page is removed
let i = 0;
while (container.destroyed === false) {
console.log(i)
// Ripple 3 times every 300 ms
if (i % 3 === 0 && i < 9) this.rippleAnimation(sprite);
// Timed out
Expand Down

0 comments on commit 857c941

Please sign in to comment.