Skip to content

Commit

Permalink
clear guesses on round start, fixed isCodeBreaker, log both team phases
Browse files Browse the repository at this point in the history
  • Loading branch information
Loomie committed Jul 30, 2023
1 parent dbd261f commit 04150c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Bugs
====

- reset code on round start (empty ui dropdowns)
- end game for both encryption games/teams
- fixed height of marks so team switcher is at fixed position
- larger marks (4em)
Expand Down
34 changes: 9 additions & 25 deletions logic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,7 @@ createApp({
},

visiblePhaseName() {
switch (this.visiblePhase) {
case GamePhase.AwaitOtherConfirmation:
return "Await Confirmation"
case GamePhase.AwaitRemainingCode:
return "Await Code"
case GamePhase.BreakCode:
return "Guess Code"
case GamePhase.ConstructCode:
return "Encode Keywords"
case GamePhase.End:
return "End"
case GamePhase.Init:
return "Initialization"
case GamePhase.Results:
return "Results"
default:
return "Unknown"
}
return GamePhase.getName(this.visiblePhase)
},

visibleTeamName() {
Expand All @@ -202,7 +185,7 @@ createApp({

isCodeBreaker() {
// in phase BreakCode everybody but the encoder is a code breaker. But in the first round only the own code can be guessed
return GamePhase.BreakCode === this.visiblePhase && !this.isEncoder && (this.isOwnTeam || this.visibleTeam.round > 1)
return GamePhase.BreakCode === this.visiblePhase && !this.isEncoder && (this.isOwnTeam || this.round > 1)
},

submit_text() {
Expand Down Expand Up @@ -353,17 +336,17 @@ createApp({

submit_guess() {
this.sendGameEvent('submit guess', this.visibleTeamId, this.visibleTeam.guess)
console.log(`submitted guess: ${this.visibleTeam.guess}`)
console.info(`submitted guess: ${this.visibleTeam.guess}`)
},

submit_hints() {
this.sendGameEvent('hints', this.myTeam.current_hints)
console.log(`submitted hints: ${this.myTeam.current_hints}`)
console.info(`submitted hints: ${this.myTeam.current_hints}`)
},

submit_results() {
this.sendGameEvent('confirm result')
console.log(`confirmed result`)
console.info(`confirmed result`)
},

sendGameEvent(eventName, ...eventArguments) {
Expand All @@ -374,7 +357,7 @@ createApp({
this.round = gameData.round
this.copyState(this.team1, gameData.team1)
this.copyState(this.team2, gameData.team2)
console.info(`Game state synced. Round ${this.round}, own phase ${this.myTeam.phase}`)
console.debug(`Game state synced. Round ${this.round}, phase for team1 is '${GamePhase.getName(this.team1.phase)}', phase for team2 is '${GamePhase.getName(this.team2.phase)}'`)
},

copyState(localTeam, remoteTeam) {
Expand Down Expand Up @@ -402,7 +385,8 @@ createApp({
localTeam.code = remoteEncoding.code
localTeam.keywords = remoteEncoding.keyWords
localTeam.encoder = remoteEncoding.encoder
localTeam.guess = remoteEncoding.guess[this.myTeamId]?.value ?? localTeam.guess
// keep local guesses if other team changes state because server does not yet know about the guesses in progress
localTeam.guess = remoteEncoding.guess[this.myTeamId]?.value ?? (localTeam.phase === GamePhase.BreakCode ? localTeam.guess : [])
}
},

Expand Down Expand Up @@ -448,7 +432,7 @@ createApp({
data.visibleTeamId = data.myTeamId
})
socket.on('initGame', (gameData) => {
console.debug(`received game data ${JSON.stringify(gameData)}`)
//console.debug(`received game data ${JSON.stringify(gameData)}`)
data.updateState(gameData)
})
socket.on('guess changed', (forTeamId, team1Guess, team2Guess) => {
Expand Down
23 changes: 22 additions & 1 deletion server/model/model-game.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ export const GamePhase = {
AwaitRemainingCode: 25,
Results: 30,
AwaitOtherConfirmation: 35,
End: 100
End: 100,

getName(phaseValue) {
switch (phaseValue) {
case this.AwaitOtherConfirmation:
return "Await Confirmation"
case this.AwaitRemainingCode:
return "Await Code"
case this.BreakCode:
return "Guess Code"
case this.ConstructCode:
return "Encode Keywords"
case this.End:
return "End"
case this.Init:
return "Initialization"
case this.Results:
return "Results"
default:
return "Unknown"
}
}
}

const codeLength = 3
Expand Down

0 comments on commit 04150c2

Please sign in to comment.