From f8ecbd203888ccd0b1a27b7823946c3313bc3e72 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 12 Mar 2024 12:44:15 +0100 Subject: [PATCH] Create matrix and generate ships for player 1 --- game.go | 68 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/game.go b/game.go index 698eead..4769df8 100644 --- a/game.go +++ b/game.go @@ -7,26 +7,64 @@ import ( ) func game() { - // var x int - // var y int - - matrix := [][]string{ - {"x", "x", "x", "x", "x", "x", "x"}, - {"x", "x", "x", "x", "x", "x", "x"}, - {"x", "x", "x", "x", "x", "x", "x"}, - {"x", "x", "x", "x", "x", "x", "x"}, - {"x", "x", "x", "x", "x", "x", "x"}, - {"x", "x", "x", "x", "x", "x", "x"}, - {"x", "x", "x", "x", "x", "x", "x"}, + clear() + // PLAYER1_REAL_MATRIX := [][]string{ + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // } + // Holy hell this is a MUCH better way to initialize matrixes + PLAYER1_REAL_MATRIX := make([][]string, 5) + for i := 0; i < 5; i++ { + PLAYER1_REAL_MATRIX[i] = make([]string, 5) } - showMatrix(matrix) + PLAYER1_HIDDEN_MATRIX := PLAYER1_REAL_MATRIX + + // PLAYER2_REAL_MATRIX := [][]string{ + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // {"x", "x", "x", "x", "x", "x"}, + // } + // + // PLAYER2_HIDDEN_MATRIX := PLAYER2_REAL_MATRIX + + // Forget it, I'm just going to implement a single player for now + + // for { + // + // fmt.Scanln() + // } + fmt.Println("Player 1 (You):") + fillMatrix(PLAYER1_REAL_MATRIX) + showMatrix(PLAYER1_REAL_MATRIX) fmt.Println() - fillMatrix(matrix) - showMatrix(matrix) + showMatrix(PLAYER1_HIDDEN_MATRIX) + os.Exit(0) } +// func gameStatus(player1 [][]string, player2 [][]string) { +// fmt.Println("Player 1 (You):") +// fillMatrix(PLAYER1_REAL_MATRIX) +// showMatrix(PLAYER1_REAL_MATRIX) +// fmt.Println() +// showMatrix(PLAYER1_HIDDEN_MATRIX) +// fmt.Printf("\n\n") +// fmt.Println("Player 2:") +// fillMatrix(PLAYER2_REAL_MATRIX) +// showMatrix(PLAYER2_REAL_MATRIX) +// fmt.Println() +// showMatrix(PLAYER2_HIDDEN_MATRIX) +// +// } + func showMatrix(mat [][]string) { for i := 0; i < len(mat); i++ { for _, v := range mat[i] { @@ -42,6 +80,8 @@ func fillMatrix(mat [][]string) { shipChance := rand.IntN(2-0) + 0 if shipChance == 1 { mat[i][i1] = "S" + } else { + mat[i][i1] = "_" } } }