finish game, proceed to finals

This commit is contained in:
Settel 2021-09-24 20:46:10 +02:00
parent 09796853cf
commit c0cebcfc55
8 changed files with 60 additions and 3 deletions

View File

@ -1,8 +1,9 @@
<template>
<nav v-if="isGamemaster" class="gamecontrols">
<button @click="startGame">Start</button>
<button @click="resetGame">Reset</button>
<button @click="resetGame">Reset Round</button>
<button @click="continueGame">Continue</button>
<button @click="finishGame">Finish Game</button>
</nav>
</template>
@ -27,6 +28,9 @@ export default {
continueGame() {
this.$engine.continueGame()
},
finishGame() {
this.$engine.finishGame()
},
},
}
</script>

View File

@ -0,0 +1,7 @@
export default async function() {
const { store } = this.context
await this.callApi('/api/finishGame', {
g: store.state.engine.user?.game,
})
}

View File

@ -6,6 +6,7 @@ import fetchUserInfo from './fetchUserInfo'
import startGame from './startGame'
import resetGame from './resetGame'
import continueGame from './continueGame'
import finishGame from './finishGame'
import parseSyncData from './parseSyncData'
import saveSelection from './saveSelection'
@ -24,6 +25,7 @@ export default (context, inject) => {
startGame,
resetGame,
continueGame,
finishGame,
parseSyncData,
saveSelection,
}

View File

@ -0,0 +1,29 @@
package application
import (
"fmt"
"net/http"
"sirlab.de/go/knyt/user"
)
func (app *Application) FinishGame(usr *user.User, w http.ResponseWriter, r *http.Request) {
gameRef := r.URL.Query().Get("g")
gm, err := app.GetGameById(gameRef)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "game not found")
return
}
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
w.WriteHeader(http.StatusForbidden)
fmt.Fprintf(w, "forbidden")
return
}
if err := app.saveGame(gm); err != nil {
fmt.Println(err)
}
gm.FinishGame()
}

View File

@ -0,0 +1,15 @@
package game
import (
"fmt"
)
func (gm *Game) FinishGame() {
state, _ := gm.GetState()
if state != STATE_PLAY {
fmt.Printf("invalid state, can't continue game in %s state\n", state)
return
}
gm.runFinal()
}

View File

@ -6,8 +6,7 @@ import (
func (gm *Game) StartGame() {
// go gm.runCountdown()
// go gm.runRound()
go gm.runFinal()
go gm.runRound()
}
func (gm *Game) ResetGame() {

View File

@ -26,6 +26,7 @@ func main() {
mux.PrivateHandleFunc("/api/startGame", app.StartGame)
mux.PrivateHandleFunc("/api/resetGame", app.ResetGame)
mux.PrivateHandleFunc("/api/continueGame", app.ContinueGame)
mux.PrivateHandleFunc("/api/finishGame", app.FinishGame)
mux.PrivateHandleFunc("/api/saveSelection", app.SaveSelection)
// default handler