knowyt/server/src/game/getQuote.go
2022-08-28 20:01:30 +02:00

44 lines
723 B
Go

package game
import (
"fmt"
"sirlab.de/go/knowyt/quote"
)
func (gm *Game) getQuoteById(id string) (*quote.Quote, error) {
gm.mu.Lock()
defer gm.mu.Unlock()
quote := gm.quotes[id]
if quote == nil {
return nil, fmt.Errorf("quote id \"%s\" not found in game", id)
}
return quote, nil
}
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)
}