summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2020-05-28 21:42:56 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2020-05-28 21:42:56 -0400
commit0e726cfb2de232eaf364cdd9cfdfc663363e0ad5 (patch)
treea8b52daf3bf1d4592a292f38480c5fee0014aae3
parentec217654a6e497383e21bb09fe32e7b4abed9b12 (diff)
Documentation cleanup (more go-like)HEADmaster
-rw-r--r--.gitignore2
-rw-r--r--backend.go74
-rw-r--r--main.go2
3 files changed, 48 insertions, 30 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f752b36
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+# Ignore tag files
+tags
diff --git a/backend.go b/backend.go
index 3be4bd5..e01df1d 100644
--- a/backend.go
+++ b/backend.go
@@ -55,40 +55,56 @@ var boatlist = [5][2][5]int{
// target stores info the player knows about the ennemy.
// gains keeps track of the ships the player has managed to sink.
type player struct {
- name string
+ // name of the player
+ // It is used for scoreboards but also throughout
+ // the game to announce turns.
+ name string
+ // primary is a 3 dimensional slice containing information
+ // about the players' own boats.
+ // Structure:
+ // [y][x][boatID, position, hitStatus]int
+ // - [y][x]
+ // The last slice index defines his coordinates in the x,y axis.
+ // - BoatID:
+ // n+1: Water
+ // n: ID of the boat
+ // - Position:
+ // 0: Water
+ // 1: North arrow
+ // 2: South arrow
+ // 3: West arrow
+ // 4: East arrow
+ // 5: Vertical middle
+ // 6: Horizontal middle
+ // - HitStatus:
+ // 0: Unhit
+ // 1: Hit
primary [10][10][3]int
- // Primary Boat Tile Vector
- // [y][x][boatID, position, hitStatus]int
- // - [y][x]
- // The last slice index defines his coordinates in the x,y axis.
- // - BoatID:
- // n+1: Water
- // n: ID of the boat
- // - Position:
- // 0: Water
- // 1: North arrow
- // 2: South arrow
- // 3: West arrow
- // 4: East arrow
- // 5: Vertical middle
- // 6: Horizontal middle
- // - HitStatus:
- // 0: Unhit
- // 1: Hit
+ // target is a 3 dimensional slice containing the information
+ // the player knows about his opponent.
+ // Structure:
+ // [ hit, id ]
+ // - hit:
+ // true: Was hit
+ // false: Has not been hit
+ // - id:
+ // 0: water or unknown
+ // n: ID of the boat
target [10][10][2]int
- // Target Boat Tile Vector
- // [ hit, id ]
- // - hit:
- // true: Was hit
- // false: Has not been hit
- // - id:
- // 0: water or unknown
- // n: ID of the boat
+ // gains is a slice containing the list of boats the player
+ // has destroyed.
+ // Structure:
+ // - The index in the slice refers to the boatID
+ // - true if the boat is sunk
gains [5]bool
- // True if a boat index (ID) is sunk
+ // prey is a pointer targetting the player's opponent.
+ // It allows to access it's board to retrieve and edit it's
+ // information when the current player makes a move.
prey *player
}
+// InitBoard creates two blank 3 dimensional slice:
+// The primary slice and the prey slice
func (plyr *player) InitBoard(opponent *player) {
// Sets the players' opponent
plyr.prey = opponent
@@ -101,7 +117,7 @@ func (plyr *player) InitBoard(opponent *player) {
}
}
-// initBoat places a boat on a players primary grid.
+// InitBoat places a boat on a players primary grid.
// boat sizes are defined by the boatlist variable.
// Consult it for more info.
func (plyr *player) InitBoat(boatID, orientation, x, y int) {
diff --git a/main.go b/main.go
index 46e0403..964492c 100644
--- a/main.go
+++ b/main.go
@@ -287,7 +287,7 @@ func main() {
}
})
- fmt.Fprint(waitText, "Waiting for:\n", figletWrite(currentPlayer.name), "\nPress Enter to continue...")
+ fmt.Fprint(waitText, "Waiting for:\n", figletWrite(currentPlayer.prey.name), "\nPress Enter to continue...")
if winner.gains != [5]bool{true, true, true, true, true} {
if err := waitScreen.SetRoot(waitText, true).Run(); err != nil {