Private
Public Access
1
0

fix game
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 6m49s

This commit is contained in:
Sebastian Unterschütz
2026-03-22 18:46:54 +01:00
parent 656f279a89
commit 6d0d31824e
6 changed files with 265 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
"log"
"syscall/js"
)
@@ -73,3 +74,30 @@ func (g *Game) savePlayerName(name string) {
}
}
}
func (g *Game) loadHighscore() int {
const storageKey = "escape_from_teacher_highscore"
if jsGlobal := js.Global(); !jsGlobal.IsUndefined() {
localStorage := jsGlobal.Get("localStorage")
if !localStorage.IsUndefined() {
stored := localStorage.Call("getItem", storageKey)
if !stored.IsNull() && stored.String() != "" {
var score int
if _, err := fmt.Sscanf(stored.String(), "%d", &score); err == nil {
return score
}
}
}
}
return 0
}
func (g *Game) saveHighscore(score int) {
const storageKey = "escape_from_teacher_highscore"
if jsGlobal := js.Global(); !jsGlobal.IsUndefined() {
localStorage := jsGlobal.Get("localStorage")
if !localStorage.IsUndefined() {
localStorage.Call("setItem", storageKey, fmt.Sprintf("%d", score))
}
}
}