Create matrix and generate ships for player 1

This commit is contained in:
raul 2024-03-12 12:44:15 +01:00
parent 6f23e5d7a6
commit f8ecbd2038
1 changed files with 54 additions and 14 deletions

68
game.go
View File

@ -7,26 +7,64 @@ import (
) )
func game() { func game() {
// var x int clear()
// var y int // PLAYER1_REAL_MATRIX := [][]string{
// {"x", "x", "x", "x", "x", "x"},
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", "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
{"x", "x", "x", "x", "x", "x", "x"}, 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() fmt.Println()
fillMatrix(matrix) showMatrix(PLAYER1_HIDDEN_MATRIX)
showMatrix(matrix)
os.Exit(0) 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) { func showMatrix(mat [][]string) {
for i := 0; i < len(mat); i++ { for i := 0; i < len(mat); i++ {
for _, v := range mat[i] { for _, v := range mat[i] {
@ -42,6 +80,8 @@ func fillMatrix(mat [][]string) {
shipChance := rand.IntN(2-0) + 0 shipChance := rand.IntN(2-0) + 0
if shipChance == 1 { if shipChance == 1 {
mat[i][i1] = "S" mat[i][i1] = "S"
} else {
mat[i][i1] = "_"
} }
} }
} }