battleship-cli/game.go

49 lines
823 B
Go

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