changes + add uploader
All checks were successful
build / build (push) Successful in 24s
release-tag / release-image (push) Successful in 16m35s

This commit is contained in:
Tijl 2024-08-29 12:36:58 +02:00
parent 1383b52f85
commit 06c6057c7d
Signed by: tijl
GPG Key ID: DAE24BFCD722F053
2 changed files with 231 additions and 206 deletions

View File

@ -121,10 +121,22 @@ func questionHandler(c *fiber.Ctx, newGame NullableUUID, prevError NullableStrin
}
shuffledCountries := shuffleSlice(countries, gameSession.GameSeed.String())
shuffledAnswers := shuffleSlice(countries, gameSession.GameSeed.String()+string(gameSession.QuestionCurrent))
shuffledAnswers = shuffledAnswers[0:4] // 4 random aswers
shuffledAnswers = append(shuffledAnswers, shuffledCountries[gameSession.QuestionCurrent-1]) // add correct answer
shuffledAnswers = shuffleSlice(shuffledAnswers, gameSession.GameSeed.String()+string(gameSession.QuestionCurrent)) // shuffle again
correctAnswer := shuffledCountries[gameSession.QuestionCurrent-1]
// Filter out the correct answer from the countries list
filteredCountries := filterSlice(countries, correctAnswer)
// Shuffle the filtered countries to get random answers
shuffledAnswers := shuffleSlice(filteredCountries, gameSession.GameSeed.String()+string(gameSession.QuestionCurrent))
// Select 4 random answers from the shuffled list
shuffledAnswers = shuffledAnswers[0:4]
// Add the correct answer to the list
shuffledAnswers = append(shuffledAnswers, correctAnswer)
// Shuffle the answers again to randomize the position of the correct answer
shuffledAnswers = shuffleSlice(shuffledAnswers, gameSession.GameSeed.String()+string(gameSession.QuestionCurrent))
if gameSession.QuestionAmount != 0 && int(gameSession.QuestionAmount) < len(countries) {
shuffledCountries = shuffledCountries[0:gameSession.QuestionAmount]
@ -281,6 +293,9 @@ func stopGameHandler(c *fiber.Ctx) error { // exit game
}
func gameStartHandler(c *fiber.Ctx) error {
data := *web.Common(c)
data["Title"] = "tmp"
data["SupportedTags"] = supportedTags

View File

@ -66,3 +66,13 @@ func filterCountriesByTags(tags []string) (error, []string) {
return nil, result
}
func filterSlice(slice []string, value string) []string {
var result []string
for _, v := range slice {
if v != value {
result = append(result, v)
}
}
return result
}