Speak when game is finished
This commit is contained in:
parent
44ad618f32
commit
1a5da6bada
1 changed files with 34 additions and 0 deletions
|
@ -4,9 +4,11 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/big"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
@ -523,6 +525,10 @@ func (c *Client) HandleEvents() {
|
|||
log.Printf("*** Failed to submit moves: %s", ev.Reason)
|
||||
case *bgammon.EventWin:
|
||||
log.Printf("%s wins!", ev.Player)
|
||||
if ev.Player != Game.Player1.Name {
|
||||
c.Out <- []byte(fmt.Sprintf("say %s", phrases[randInt(len(phrases))]))
|
||||
}
|
||||
c.Out <- []byte("say Good game. Play again?")
|
||||
c.Out <- []byte("rematch")
|
||||
case *bgammon.EventPing:
|
||||
c.Out <- []byte(fmt.Sprintf("pong %s", ev.Message))
|
||||
|
@ -552,3 +558,31 @@ func tabulaBoard(b []int) tabula.Board {
|
|||
}
|
||||
return tabula.Board{int8(b[0]), int8(b[1]), int8(b[2]), int8(b[3]), int8(b[4]), int8(b[5]), int8(b[6]), int8(b[7]), int8(b[8]), int8(b[9]), int8(b[10]), int8(b[11]), int8(b[12]), int8(b[13]), int8(b[14]), int8(b[15]), int8(b[16]), int8(b[17]), int8(b[18]), int8(b[19]), int8(b[20]), int8(b[21]), int8(b[22]), int8(b[23]), int8(b[24]), int8(b[25]), int8(b[26]), int8(b[27]), roll1, roll2, roll3, roll4, entered1, entered2, acey}
|
||||
}
|
||||
|
||||
var phrases = [][]byte{
|
||||
[]byte("Gadzooks! I accidentally lost by mistake."),
|
||||
[]byte("My checkers began too close to your home board."),
|
||||
[]byte("Far too many checkers stood in the path my own."),
|
||||
[]byte("My hopes perished when my checkers were sent returning."),
|
||||
[]byte("Forsooth, I couldst not choose the best move."),
|
||||
[]byte("All my beginning checkers were upside-down."),
|
||||
[]byte("Thy heraldic checkers were superior to mine own."),
|
||||
[]byte("My machinations couldst not outwit thine own!"),
|
||||
[]byte("Thou art human, with soul and wit. I am naught but clockwork!"),
|
||||
[]byte("My chair was most uncomfortable."),
|
||||
[]byte("Forsooth, the moving checkers tapped and clacked too loudly."),
|
||||
[]byte("'Zounds! I couldst not move a checker to save mine artificial life."),
|
||||
[]byte("I couldst not comprehend mine dice rolls!"),
|
||||
[]byte("My checkers all had different rotations!"),
|
||||
[]byte("My checkers foolishly walk on single rolls instead of astride doubles."),
|
||||
[]byte("Alas, I could find naught but tiny rolls."),
|
||||
[]byte("No wonder thou wert victorious! I shalt abdicate."),
|
||||
}
|
||||
|
||||
func randInt(max int) int {
|
||||
i, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return int(i.Int64())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue