diff --git a/manager.go b/manager.go index f494aa2..d67bf80 100644 --- a/manager.go +++ b/manager.go @@ -42,10 +42,10 @@ func (tg *Manager) NewGame() { Question: questions[r.Intn(len(questions))], StartTime: time.Now(), } - log.Printf("Question: %s", tg.currentGame.Question.question) - log.Printf("Answer: %s", tg.currentGame.Question.answer) + log.Printf("[Question]: %s", tg.currentGame.Question.question) + log.Printf("[Answer]: %s", tg.currentGame.Question.answer) - tg.Send(fmt.Sprintf("Question: %s?", tg.currentGame.Question.question), nil) + tg.Send(fmt.Sprintf("[New Question]: %s?::..", tg.currentGame.Question.question), nil) } func (tg *Manager) CurrentGame() *Game { @@ -57,9 +57,14 @@ func (tg *Manager) CurrentGame() *Game { func (tg *Manager) TryAnswer(p *Player, a string) { tg.mutex.Lock() + if tg.currentGame == nil { + tg.mutex.Unlock() + return + } if !strings.EqualFold(tg.currentGame.Question.answer, a) { - tg.Send(fmt.Sprintf("..::Wrong Answer by: %s::..", p.Name), p) + tg.Send(fmt.Sprintf("[Wrong Answer]: %s", p.Name), p) + tg.Send(fmt.Sprintf("[Question]: %s?", tg.currentGame.Question.question), p) tg.mutex.Unlock() return } @@ -71,7 +76,7 @@ func (tg *Manager) TryAnswer(p *Player, a string) { tg.Players[p.Id] = p } - tg.Send(fmt.Sprintf("..::Correct Answer By: %s::..", p.Name), p) + tg.Send(fmt.Sprintf("[Correct Answer]: %s", p.Name), p) tg.mutex.Unlock() tg.NewGame() @@ -80,16 +85,28 @@ func (tg *Manager) TryAnswer(p *Player, a string) { func (tg *Manager) GetQuestion() { tg.mutex.Lock() defer tg.mutex.Unlock() - tg.Send(fmt.Sprintf("..::Current Question: %s? ::..", tg.currentGame.Question.question), nil) + + if tg.currentGame == nil { + tg.Send("[NO GAME]", nil) + } else { + tg.Send(fmt.Sprintf("[Current Question]: %s? ", tg.CurrentGame().Question.question), nil) + } +} + +func (tg *Manager) Skip() { + tg.mutex.Lock() + tg.Send(fmt.Sprintf("[Skipped] Answer: %s ", tg.currentGame.Question.answer), nil) + tg.mutex.Unlock() + tg.NewGame() } func (tg *Manager) GetScore(p *Player) { tg.mutex.Lock() defer tg.mutex.Unlock() if player, found := tg.Players[p.Id]; found { - tg.Send(fmt.Sprintf("...::%s Score: %d", p.Name, player.Correct), nil) + tg.Send(fmt.Sprintf("[%s Score]: %d", p.Name, player.Correct), nil) } else { - tg.Send(fmt.Sprintf("...::%s Score: 0", p.Name), nil) + tg.Send(fmt.Sprintf("[%s Score]: 0", p.Name), nil) } } // communication