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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
package main
import (
"fmt"
tc "github.com/gdamore/tcell"
tv "github.com/rivo/tview"
"strconv"
"strings"
)
func RedrawTarget(plyr *player, table *tv.Table) {
// generating slice string for the table:
// We initialize a slice containing all the cells
// The first row will be the label of the columns
boardData := strings.Split(" /A/B/C/D/E/F/G/H/I/J", "/")
// For every row (r)
for r := 0; r < 10; r++ {
// Each row starts with the row label/number
// A space makes the table centered by indenting it...
str := " " + strconv.Itoa(r)
boardData = append(boardData, str)
// For every column (c)
for c := 0; c < 10; c++ {
// First thing: is the coordinate hit or not?
switch plyr.target[r][c][0] {
// The coordinate is NOT hit:
case 0:
// Add the `~` symbol
boardData = append(boardData, boatchars[1][0])
// If the coordinate is NOT hit:
default:
// Is the coordinate water?
switch plyr.prey.primary[r][c][0] {
// It IS water:
case 6:
// Add the `◌` symbol
boardData = append(boardData, boatchars[0][0])
// It's NOT water:
default:
// Is the ID of the boat at that coordinate marked as a gain?
switch plyr.gains[plyr.prey.primary[r][c][0]] {
// It IS marked as a gain:
case true:
// Show the boat as it's meant to be:
// (hit boatchars: with `position` marked in the opponents primary)
boardData = append(boardData, boatchars[0][plyr.prey.primary[r][c][1]])
default:
// Nope, you're getting a censored tile: `▣`
boardData = append(boardData, misteryHit)
}
}
}
}
}
table.Clear()
for r := 0; r < 11; r++ {
for c := 0; c < 11; c++ {
color, selectable := tc.ColorDarkCyan, true
if r < 1 || c < 1 {
color, selectable = tc.ColorPurple, false
}
if boardData[r*11+c] != `~` && !(r < 1 || c < 1) {
selectable, color = false, tc.ColorRed
}
table.SetCell(r, c,
tv.NewTableCell(boardData[r*11+c]).
SetTextColor(color).
SetAlign(tv.AlignCenter).
SetSelectable(selectable))
}
}
}
func RedrawPrimary(plyr *player, table *tv.Table) {
// generating slice string for the table:
// We initialize a slice containing all the cells
// The first row will be the label of the columns
boardData := strings.Split(" /A/B/C/D/E/F/G/H/I/J", "/")
// For every row (r)
for r := 0; r < 10; r++ {
// Each row starts with the row label/number
// A space makes the table centered by indenting it...
str := " " + strconv.Itoa(r)
boardData = append(boardData, str)
// For every column (c)
for c := 0; c < 10; c++ {
// Is the coordinate hit or not?
switch plyr.primary[r][c][2] {
// It is NOT
case 0:
// boatchars selects is character from the not-hit slice
boardData = append(boardData, boatchars[1][plyr.primary[r][c][1]])
// It IS
case 1:
// boatchars selects is character from the hit slice
boardData = append(boardData, boatchars[0][plyr.primary[r][c][1]])
}
}
}
table.Clear()
for r := 0; r < 11; r++ {
for c := 0; c < 11; c++ {
color := tc.ColorDarkCyan
if r < 1 || c < 1 {
color = tc.ColorPurple
}
if boardData[r*11+c] != `~` && !(r < 1 || c < 1) {
color = tc.ColorRed
}
table.SetCell(r, c,
tv.NewTableCell(boardData[r*11+c]).
SetTextColor(color).
SetSelectable(false).
SetAlign(tv.AlignCenter))
}
}
}
func RedrawGains(plyr *player, gains *tv.TextView) {
gains.Clear()
boatlist := []string{
boat0,
boat1,
boat2,
boat3,
boat4,
}
for i := 0; i < 5; i++ {
if plyr.gains[i] {
fmt.Fprintf(gains, "%v\n", boatlist[i])
} else {
fmt.Fprintf(gains, "\n\n")
}
}
}
func RedrawLosses(plyr *player, losses *tv.TextView) {
losses.Clear()
boatlist := []string{
boat0,
boat1,
boat2,
boat3,
boat4,
}
for i := 0; i < 5; i++ {
if plyr.prey.gains[i] {
fmt.Fprintf(losses, "%v\n", boatlist[i])
} else {
fmt.Fprintf(losses, "\n\n")
}
}
}
|