battleship-go

Terminal-based battleship written in Go (WIP).
Log | Files | Refs | README | LICENSE

commit ec217654a6e497383e21bb09fe32e7b4abed9b12
parent e85463a03763416c0cf17d96b4e06761468a45e1
Author: Benjamin Chausse <benjamin@chausse.xyz>
Date:   Sun, 19 Jan 2020 22:00:35 -0500

Blank screen between players

Diffstat:
Maesthetics.go | 13+++++++++++++
Mmain.go | 29+++++++++++++++++++++++++++--
2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/aesthetics.go b/aesthetics.go @@ -4,6 +4,7 @@ package main // display or setup visuals without the use of tview. import ( + "github.com/mbndr/figlet4go" "strconv" ) @@ -108,6 +109,18 @@ var boatchars = [2][7]string{ {`~`, `△`, `▽`, `◁`, `▷`, `▯`, `▭`}, } +func figletWrite(text string) string { + ascii := figlet4go.NewAsciiRender() + options := figlet4go.NewRenderOptions() + options.FontName = "larry3d" + options.FontColor = []figlet4go.Color{ + figlet4go.ColorCyan, + } + // The underscore would be an error + renderStr, _ := ascii.Render(text) + return renderStr +} + // This constant keeps information about boats that aren't totally sunk secret. // It therefore substitues the shape of a boat on the target board when it is unsunk. const misteryHit = `▣` diff --git a/main.go b/main.go @@ -163,8 +163,7 @@ func main() { var log string = "Game Started!" // Until Somedody Wins: - for winner := currentPlayer; !(winner.gains == [5]bool{true, true, true, true, true}); { - currentPlayer.Hit(9, 9) + for winner := currentPlayer; winner.gains != [5]bool{true, true, true, true, true}; { // Make the loop toggle between both players if currentPlayer == &playerTwo { @@ -273,5 +272,31 @@ func main() { if err := app.SetRoot(dashboard, true).Run(); err != nil { panic(err) } + + waitScreen := tv.NewApplication() + waitText := tv.NewTextView().SetDoneFunc(func(key tc.Key) { + if key == tc.KeyEnter { + waitScreen.Stop() + } + if key == tc.KeyEscape { + for i := 0; i < 5; i++ { + playerOne.gains[i] = true + playerTwo.gains[i] = true + waitScreen.Stop() + } + } + }) + + fmt.Fprint(waitText, "Waiting for:\n", figletWrite(currentPlayer.name), "\nPress Enter to continue...") + + if winner.gains != [5]bool{true, true, true, true, true} { + if err := waitScreen.SetRoot(waitText, true).Run(); err != nil { + panic(err) + } else if (winner.gains == [5]bool{true, true, true, true, true}) && (winner.prey.gains != [5]bool{true, true, true, true, true}) { + waitText.Clear() + fmt.Fprint(waitText, figletWrite(winner.name), "\n", figletWrite("is the winner!")) + } + } + } }