From 6d852e08a93eec6f1fb6940253bf21ebc2dacb9e Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Thu, 9 Jan 2020 15:53:32 -0500 Subject: Layout placeholders scale correctly! --- aesthetics.go | 76 +++---------------------------- backend.go | 1 + main.go | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 129 insertions(+), 88 deletions(-) diff --git a/aesthetics.go b/aesthetics.go index 5d580f6..e8f88a4 100644 --- a/aesthetics.go +++ b/aesthetics.go @@ -1,5 +1,8 @@ package main +// aesthetics.go contains all the functions which +// display or setup visuals without the use of tview. + import ( "strconv" ) @@ -20,7 +23,7 @@ import ( // 8 ~ ~ ~ ~ ◀ ▬ ▬ ▷ ~ ~ // 9 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Only E8, F8, and G8 were hit. -func (plyr player) PrimaryDisplay() string { +func (plyr player) DisplayPrimary() string { text := "\n A B C D E F G H I J \n" for i := 0; i < 10; i++ { text += strconv.Itoa(i) @@ -59,7 +62,7 @@ func (plyr player) PrimaryDisplay() string { // 9 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Since the boat in F8, E8, G8 is not sunk, The player does not see // it's shape. Upon sinking it, he will be able to see it. -func (plyr player) TargetDisplay() string { +func (plyr player) DisplayTarget() string { text := "\n A B C D E F G H I J \n" for i := 0; i < 10; i++ { text += strconv.Itoa(i) @@ -88,75 +91,6 @@ func (plyr player) TargetDisplay() string { return text } -// printPrimary displays using ASCII art the primary battleship board -func (plyr player) PrimarySlice() []string { - board := []string{ - " ", - "A", - "B", - "C", - "D", - "E", - "F", - "G", - "H", - "I", - "J", - } - for i := 0; i < 10; i++ { - board = append(board, strconv.Itoa(i)) - for j := 0; j < 10; j++ { - switch plyr.primary[i][j][2] { - case 0: // That coordinate was not hit - board = append(board, boatchars[1][plyr.primary[i][j][1]]) - case 1: // That coordinates was hit - board = append(board, boatchars[0][plyr.primary[i][j][1]]) - // default: - // return errors.New("Unknown State (hit/unhit) at a given coordinate") - } - } - } - // fmt.Println(text) - return board -} - -func (plyr player) TargetSlice() []string { - board := []string{ - " ", - "A", - "B", - "C", - "D", - "E", - "F", - "G", - "H", - "I", - "J", - } - for i := 0; i < 10; i++ { - board = append(board, strconv.Itoa(i)) - for j := 0; j < 10; j++ { - switch plyr.target[i][j][0] { - case 0: - board = append(board, boatchars[1][0]) - case 1: - if plyr.gains[plyr.prey.primary[i][j][0]] { - board = append(board, boatchars[0][plyr.prey.primary[i][j][1]]) - } else { - switch plyr.prey.primary[i][j][0] { - case 0: - board = append(board, boatchars[0][0]) - default: - board = append(board, mistery_hit) - } - } - } - } - } - return board -} - // TODO: Function which returns what was hit as a commentary for the hitter /* Boats Info: diff --git a/backend.go b/backend.go index d1cd758..ad9149b 100644 --- a/backend.go +++ b/backend.go @@ -55,6 +55,7 @@ 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 primary [10][10][3]int // Primary Boat Tile Vector // [y][x][boatID, position, hitStatus]int diff --git a/main.go b/main.go index c96c518..fc3203d 100644 --- a/main.go +++ b/main.go @@ -13,30 +13,136 @@ func main() { } // SETUP: - var player_one = player{} - var player_two = player{} + var playerOne = player{name: "Ben"} + var playerTwo = player{name: "Hugo"} // Setting up prey for when using Hit function - player_one.prey = &player_two - player_two.prey = &player_one + playerOne.prey = &playerTwo + playerTwo.prey = &playerOne if settings.debug { - fmt.Println(player_one.PrimarySlice()) + // PLACING PLAYER ONE BOATS: + // Carrier: (ID=0), horizontal, (1,1) + initBoat(&playerOne, [4]int{0, 0, 1, 1}) + // Battleship: (ID=1), horizontal, (0,9) + initBoat(&playerOne, [4]int{1, 0, 0, 9}) + // Destroyer: (ID=2), vertical, (5,6) + initBoat(&playerOne, [4]int{2, 1, 5, 6}) + // Submarine: (ID=3), horizontal, (6,2) + initBoat(&playerOne, [4]int{3, 0, 6, 2}) + // Patrol Boat: (ID=4), vertical, (1,5) + initBoat(&playerOne, [4]int{4, 1, 1, 5}) + // PLACING PLAYER TWO BOATS: + // Carrier: (ID=0), vertical, (9,0) + initBoat(&playerTwo, [4]int{0, 1, 9, 0}) + // Battleship: (ID=1), horizontal, (1,8) + initBoat(&playerTwo, [4]int{1, 0, 1, 8}) + // Destroyer: (ID=2), vertical, (5,3) + initBoat(&playerTwo, [4]int{2, 1, 5, 3}) + // Submarine: (ID=3), horizontal, (2,2) + initBoat(&playerTwo, [4]int{3, 0, 2, 2}) + // Patrol Boat: (ID=4), vertical, (7,6) + initBoat(&playerTwo, [4]int{4, 1, 6, 6}) + + // HITTING PLAYER ONE AT DIFFERENT COORDINATES + playerTwo.Hit([2]int{5, 6}) // (F,6) + playerTwo.Hit([2]int{5, 7}) // (F,7) + playerTwo.Hit([2]int{5, 8}) // (F,8) + playerTwo.Hit([2]int{3, 4}) // (D,4) + playerTwo.Hit([2]int{3, 9}) // (D,9) + playerTwo.Hit([2]int{6, 6}) // (G,6) + playerTwo.Hit([2]int{2, 9}) // (C,9) + + // HITTING PLAYER TWO AT DIFFERENT COORDINATES + playerOne.Hit([2]int{1, 4}) // (B,4) + playerOne.Hit([2]int{1, 8}) // (B,8) + playerOne.Hit([2]int{2, 7}) // (C,7) + playerOne.Hit([2]int{2, 8}) // (C,8) + playerOne.Hit([2]int{3, 8}) // (D,8) + playerOne.Hit([2]int{4, 8}) // (E,8) + playerOne.Hit([2]int{9, 2}) // (I,2) + + // Display both primary boards in stdout + fmt.Println("Player One:", playerOne.DisplayPrimary()) + fmt.Println("Player Two:", playerTwo.DisplayPrimary()) + + // Setting the Player header box + headerBox := tv.NewBox().SetTitle(playerOne.name). + SetBorder(true) + + // Setting up the keybindings box + // Where the keybindings list will be + keybindingsBox := tv.NewBox(). + SetTitle("Keybindings:"). + SetBorder(true) + // TODO: Add text/documentation to box + + // Setting the log box whoch shows a history of past moves + logBox := tv.NewBox(). + SetTitle("Log:"). + SetBorder(true) + + // Setting up the target box + targetBox := tv.NewTable(). + SetBorder(true). + SetTitle("The ennemy:") + + // Setting up the primary box + primaryBox := tv.NewTable(). + SetBorder(true). + SetTitle("You:") + + // Setting up the gains box + gainsBox := tv.NewList(). + SetBorder(true). + SetTitle("Gains:") + + // Setting up the losses box + lossesBox := tv.NewList(). + SetBorder(true). + SetTitle("Losses:") + + // Setting up the command prompt box + commandBox := tv.NewInputField(). + SetBorder(true). + SetTitle("Command:") + + // Setting up the target flex + targetFlex := tv.NewFlex().SetDirection(tv.FlexColumn). + AddItem(targetBox, 26, 0, true). + AddItem(gainsBox, 26, 0, false) + + // Setting up the primary flex + primaryFlex := tv.NewFlex().SetDirection(tv.FlexColumn). + AddItem(primaryBox, 26, 0, false). + AddItem(lossesBox, 26, 0, false) + + // // Setting up the play flex + playFlex := tv.NewFlex().SetDirection(tv.FlexRow). + AddItem(targetFlex, 13, 0, false). + AddItem(primaryFlex, 13, 0, false). + AddItem(commandBox, 0, 1, false) + + // // Setting up the info flex + infoFlex := tv.NewFlex().SetDirection(tv.FlexRow). + AddItem(keybindingsBox, 0, 3, false). + AddItem(logBox, 0, 1, false) + + // Setting up the bottom flex + bottomFlex := tv.NewFlex().SetDirection(tv.FlexColumn). + AddItem(infoFlex, 0, 1, false). + AddItem(playFlex, 52, 0, false) + + // Setting up the application layout app := tv.NewApplication() - flex := tv.NewFlex(). - //AddItem(item, fixedSize, proportion, focus) - AddItem(tv.NewBox().SetBorder(true).SetTitle("Left (1/2 x width of Top)"), 0, 1, false). - AddItem(tv.NewFlex().SetDirection(tv.FlexRow). - AddItem(tv.NewBox().SetBorder(true).SetTitle("Top "), 0, 1, false). - AddItem(tv.NewBox().SetBorder(true).SetTitle("Middle (3 x height of Top)"), 0, 3, false). - AddItem(tv.NewBox().SetBorder(true).SetTitle("Bottom (5 rows) "), 5, 1, false), 0, 2, false). - AddItem(tv.NewFlex().SetDirection(tv.FlexRow). - AddItem(tv.NewBox().SetBorder(true).SetTitle("Gains"), 0, 1, false). - AddItem(tv.NewBox().SetBorder(true).SetTitle("Losses"), 0, 1, false), 12, 2, false) - if err := app.SetRoot(flex, true).SetFocus(flex).Run(); err != nil { + // Dashboard is the Flex containing everything. + dashboard := tv.NewFlex().SetDirection(tv.FlexRow). + AddItem(headerBox, 2, 1, false). + AddItem(bottomFlex, 0, 1, false) + + if err := app.SetRoot(dashboard, true).Run(); err != nil { panic(err) } } - } -- cgit v1.2.3