-
Notifications
You must be signed in to change notification settings - Fork 138
/
games.go
47 lines (39 loc) · 1021 Bytes
/
games.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"strings"
"github.com/shurcooL/tictactoe"
)
var (
tttGame = new(tictactoe.Board)
currentPlayer = tictactoe.X
hangGame = new(hangman)
)
type hangman struct {
word string
triesLeft int
guesses string // string containing all the guessed characters
}
func hangPrint(hangGame *hangman) string {
display := ""
for _, c := range hangGame.word {
if strings.ContainsRune(hangGame.guesses, c) {
display += string(c)
} else {
display += "_"
}
}
return display
}
func tttPrint(cells [9]tictactoe.State) string {
return strings.ReplaceAll(strings.ReplaceAll(
fmt.Sprintf(` %v │ %v │ %v
───┼───┼───
%v │ %v │ %v
───┼───┼───
%v │ %v │ %v `, cells[0], cells[1], cells[2],
cells[3], cells[4], cells[5],
cells[6], cells[7], cells[8]),
tictactoe.X.String(), Chalk.BrightYellow(tictactoe.X.String())), // add some coloring
tictactoe.O.String(), Chalk.BrightGreen(tictactoe.O.String()))
}