import { Conversation } from "./Conversation" ; import { GameScene } from "./scenes/GameScene" ; import { Sound } from "./Sound" ; import { asset } from "./Assets" ; const AMOUNT_GATE_COLS = 3 ; const AMOUNT_GATE_ROWS = 5 ; export class MountainRiddle { private attemptCount = 0 ; private failed = false ; private cleared = false ; private solution : number [ ] ; @ asset ( "sounds/item/fanfare.mp3" ) private static sound : Sound ; public constructor ( ) { this . solution = this . getRandomizedSolution ( ) ; } private getRandomizedSolution ( ) { const solution = [ ] ; for ( let index = 0 ; index < AMOUNT_GATE_ROWS ; index ++ ) { solution . push ( Math . floor ( Math . random ( ) * Math . floor ( AMOUNT_GATE_COLS ) ) ) ; } return solution ; } public isCorrectGate ( col , row ) { return this . solution [ row ] === col ; } public checkGate ( col , row ) { if ( ! this . failed && ! this . cleared && ! this . isCorrectGate ( col , row ) ) { this . failRiddle ( ) ; } } public wasAttempted ( ) { return this . attemptCount > 0 ; } public registerAttempt ( ) { this . attemptCount ++ ; } public failRiddle ( ) { Conversation . setGlobal ( "gotTeleported" , "true" ) ; this . failed = true ; this . registerAttempt ( ) ; GameScene . wrong . play ( ) ; } public isFailed ( ) { return this . failed ; } public resetRiddle ( ) { if ( this . failed && ! this . cleared ) { this . solution = this . getRandomizedSolution ( ) ; this . failed = false ; } } public isCleared ( ) { return this . cleared ; } public clearRiddle ( ) { if ( ! this . cleared ) { MountainRiddle . sound . play ( ) ; this . failed = false ; this . cleared = true ; } } }