From 55b99e0b2cc4f0caae6b67ee0cfd3bdc93267557 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 12 Mar 2024 12:14:06 +0100 Subject: [PATCH] Added matrix randomizer for ship generation --- game.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 game.go diff --git a/game.go b/game.go new file mode 100644 index 0000000..698eead --- /dev/null +++ b/game.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "math/rand/v2" + "os" +) + +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"}, + } + showMatrix(matrix) + fmt.Println() + fillMatrix(matrix) + showMatrix(matrix) + os.Exit(0) + +} + +func showMatrix(mat [][]string) { + for i := 0; i < len(mat); i++ { + for _, v := range mat[i] { + fmt.Printf("%v ", v) + } + fmt.Println() + } +} + +func fillMatrix(mat [][]string) { + for i := 0; i < len(mat); i++ { + for i1 := range mat[i] { + shipChance := rand.IntN(2-0) + 0 + if shipChance == 1 { + mat[i][i1] = "S" + } + } + } +}