knowyt/server/src/game/getQuote.go

44 lines
723 B
Go
Raw Normal View History

2021-09-06 21:31:09 +00:00
package game
import (
"fmt"
2022-08-28 18:01:30 +00:00
"sirlab.de/go/knowyt/quote"
2021-09-06 21:31:09 +00:00
)
func (gm *Game) getQuoteById(id string) (*quote.Quote, error) {
gm.mu.Lock()
defer gm.mu.Unlock()
quote := gm.quotes[id]
if quote == nil {
2022-08-28 18:01:30 +00:00
return nil, fmt.Errorf("quote id \"%s\" not found in game", id)
2021-09-06 21:31:09 +00:00
}
return quote, nil
}
2021-09-11 12:03:44 +00:00
func (gm *Game) getAllQuotes() []*quote.Quote {
gm.mu.Lock()
defer gm.mu.Unlock()
quotes := make([]*quote.Quote, 0)
for _, quote := range gm.quotes {
quotes = append(quotes, quote)
}
return quotes
}
func (gm *Game) countQuotes() (int, int) {
allQuotes := gm.getAllQuotes()
numQuotesLeft := 0
for _, q := range allQuotes {
if !q.IsPlayed() {
numQuotesLeft++
}
}
return numQuotesLeft, len(allQuotes)
}