summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2020-01-12 17:57:24 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2020-01-12 17:57:24 -0500
commit6fc22d9f6dd22ef1a9fc5f1d091f79c4b67726b2 (patch)
tree640e611ef7699568862c98d72f6154951f786175
parent42e7425f98abf04ff770c7ad51b5494a6dfc6238 (diff)
The player sees his own boats
-rw-r--r--aesthetics.go2
-rw-r--r--backend.go11
-rw-r--r--main.go56
3 files changed, 60 insertions, 9 deletions
diff --git a/aesthetics.go b/aesthetics.go
index 343b468..9766f92 100644
--- a/aesthetics.go
+++ b/aesthetics.go
@@ -104,7 +104,7 @@ func (plyr *player) DisplayTarget() string {
|------------+--------+----------------|
*/
var boatchars = [2][7]string{
- {`◌`, `▲`, `▼`, `◀`, `►`, `▮`, `▬`},
+ {`◌`, `▲`, `▼`, `◀`, `▶`, `▮`, `▬`},
{`~`, `△`, `▽`, `◁`, `▷`, `▯`, `▭`},
}
diff --git a/backend.go b/backend.go
index 868739d..6979d59 100644
--- a/backend.go
+++ b/backend.go
@@ -75,7 +75,6 @@ type player struct {
// - HitStatus:
// 0: Unhit
// 1: Hit
- //
target [10][10][2]int
// Target Boat Tile Vector
// [ hit, id ]
@@ -91,12 +90,12 @@ type player struct {
}
func (plyr *player) InitBoard(opponent *player) {
+ // Sets the players' opponent
plyr.prey = opponent
-
- for i := 0; i < 10; i++ {
- for j := 0; j < 10; j++ {
- plyr.primary[i][j] = [3]int{6, 0, 0}
- plyr.target[i][j] = [2]int{0, 6}
+ for r := 0; r < 10; r++ {
+ for c := 0; c < 10; c++ {
+ plyr.primary[r][c] = [3]int{6, 0, 0}
+ plyr.target[r][c] = [2]int{0, 6}
}
}
diff --git a/main.go b/main.go
index 7258e17..8dc26d0 100644
--- a/main.go
+++ b/main.go
@@ -188,11 +188,18 @@ func main() {
// TODO: change this for a dopdown prompt "Are you sure? (Y/N)"
app.Stop()
}
+ if key == tc.KeyEnter {
+ x, y := targetBox.GetSelection()
+ fmt.Println("X:", x)
+ fmt.Println("Y:", y)
+ }
}).
SetBorder(true).
SetTitle("The enemy:")
- primaryBox := tv.NewTable().
+ primaryBox := tv.NewTable()
+ RedrawPrimary(&playerOne, primaryBox)
+ primaryBox.SetFixed(1, 1).
SetBorder(true).
SetTitle("You:")
@@ -250,6 +257,7 @@ func RedrawTarget(plyr *player, table *tv.Table) {
// 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] {
@@ -282,7 +290,6 @@ func RedrawTarget(plyr *player, table *tv.Table) {
}
}
}
-
table.Clear()
for r := 0; r < 11; r++ {
for c := 0; c < 11; c++ {
@@ -301,3 +308,48 @@ func RedrawTarget(plyr *player, table *tv.Table) {
}
}
}
+
+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))
+ }
+ }
+}