changes + add uploader
This commit is contained in:
parent
1383b52f85
commit
06c6057c7d
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user