fix game
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 6m49s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 6m49s
This commit is contained in:
@@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
@@ -61,3 +62,19 @@ func (g *Game) savePlayerName(name string) {
|
||||
log.Printf("💾 Spielername gespeichert: %s", name)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) loadHighscore() int {
|
||||
const hsFile = "highscore.txt"
|
||||
if data, err := ioutil.ReadFile(hsFile); err == nil {
|
||||
var score int
|
||||
if _, err2 := fmt.Sscanf(strings.TrimSpace(string(data)), "%d", &score); err2 == nil {
|
||||
return score
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (g *Game) saveHighscore(score int) {
|
||||
const hsFile = "highscore.txt"
|
||||
ioutil.WriteFile(hsFile, []byte(fmt.Sprintf("%d", score)), 0644)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user