Added ability to choose size of ship board

Also reordered the code and sent all comments to the bottom so they
woudln't bother me
This commit is contained in:
raul 2024-03-14 11:11:33 +01:00
parent c1a84a47d5
commit 860b50dd59
1 changed files with 56 additions and 49 deletions

105
game.go
View File

@ -41,41 +41,12 @@ func fillShips(tiles int) {
}
func game() {
fillShips(10)
// 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)
// }
//PLAYER1_HIDDEN_MATRIX := PLAYER1_REAL_MATRIX
// PLAYER1_HIDDEN_MATRIX := make([][]string, len(PLAYER1_REAL_MATRIX))
// copy(PLAYER1_HIDDEN_MATRIX, PLAYER1_REAL_MATRIX)
fmt.Printf("How many rows/columns would you like to have?\nChoice: ")
var shipNum int
fmt.Scanln(&shipNum)
clear()
fillShips(shipNum)
// 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(revealedShips1)
@ -86,21 +57,6 @@ func game() {
}
// 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] {
@ -122,3 +78,54 @@ func fillMatrix(mat [][]string) {
}
}
}
// Trash zone:
// 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)
//
// }
// 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)
// }
//PLAYER1_HIDDEN_MATRIX := PLAYER1_REAL_MATRIX
// PLAYER1_HIDDEN_MATRIX := make([][]string, len(PLAYER1_REAL_MATRIX))
// copy(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()
// }