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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package game
import (
"strings"
"thehouseoficarus/internal/casino"
"thehouseoficarus/internal/color"
)
func renderSlotSnapshot(snapshot *casino.SlotSnapshot, mode string, unicode bool) string {
if snapshot == nil {
return ""
}
left, junction, right, horizontal, vertical := '+', '+', '+', '-', '|'
bottomLeft, bottomJunction, bottomRight := '+', '+', '+'
if unicode {
left, junction, right, horizontal, vertical = '\u250c', '\u252c', '\u2510', '\u2500', '\u2502'
bottomLeft, bottomJunction, bottomRight = '\u2514', '\u2534', '\u2518'
}
separator := string(left)
for reel := 0; reel < 5; reel++ {
if reel > 0 {
separator += string(junction)
}
separator += strings.Repeat(string(horizontal), 9)
}
separator += string(right)
lines := []string{casinoFrame(mode, separator)}
frameVertical := casinoFrame(mode, string(vertical))
for row := 0; row < 3; row++ {
line := frameVertical
for reel := 0; reel < 5; reel++ {
value := "..."
if reel < snapshot.StoppedReels {
value = snapshot.Grid[row][reel]
}
// Pad to the fixed 7-cell reel width; a malformed profile could
// otherwise make this negative and panic. Validation caps the id
// length, so this is a defence-in-depth backstop.
pad := 7 - len(value)
if pad < 0 {
pad = 0
}
line += " " + colorSlotSymbol(mode, value) + strings.Repeat(" ", pad) + " " + frameVertical
}
lines = append(lines, line)
}
bottom := string(bottomLeft)
for reel := 0; reel < 5; reel++ {
if reel > 0 {
bottom += string(bottomJunction)
}
bottom += strings.Repeat(string(horizontal), 9)
}
bottom += string(bottomRight)
lines = append(lines, casinoFrame(mode, bottom))
return strings.Join(lines, "\n")
}
func casinoFrame(mode, text string) string {
spec := color.NoColor()
spec.Fg = 244
return color.Render(mode, spec, text)
}
func colorSlotSymbol(mode, symbol string) string {
spec := color.NoColor()
spec.Fg = 250
switch symbol {
case "straw":
spec.Fg = 220
case "stick":
spec.Fg = 46
case "brick":
spec.Fg = 196
case "hat":
spec.Fg = 201
case "wolf":
spec.Fg = 39
case "scatter":
spec.Fg = 226
default:
spec.Dim = true
}
return color.Render(mode, spec, symbol)
}
|