finish game, proceed to finals
This commit is contained in:
parent
09796853cf
commit
c0cebcfc55
@ -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>
|
||||
|
7
client/src/plugins/engine/finishGame.js
Normal file
7
client/src/plugins/engine/finishGame.js
Normal file
@ -0,0 +1,7 @@
|
||||
export default async function() {
|
||||
const { store } = this.context
|
||||
|
||||
await this.callApi('/api/finishGame', {
|
||||
g: store.state.engine.user?.game,
|
||||
})
|
||||
}
|
@ -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,
|
||||
}
|
||||
|
29
server/src/application/finishGame.go
Normal file
29
server/src/application/finishGame.go
Normal 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()
|
||||
}
|
15
server/src/game/finishGame.go
Normal file
15
server/src/game/finishGame.go
Normal 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()
|
||||
}
|
@ -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() {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user