Added matrix randomizer for ship generation

This commit is contained in:
raul 2024-03-12 12:14:06 +01:00
parent 3e8313b118
commit 55b99e0b2c
1 changed files with 48 additions and 0 deletions

48
game.go Normal file
View File

@ -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"
}
}
}
}