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:
parent
c1a84a47d5
commit
860b50dd59
101
game.go
101
game.go
|
@ -41,7 +41,60 @@ func fillShips(tiles int) {
|
|||
}
|
||||
|
||||
func game() {
|
||||
fillShips(10)
|
||||
fmt.Printf("How many rows/columns would you like to have?\nChoice: ")
|
||||
var shipNum int
|
||||
fmt.Scanln(&shipNum)
|
||||
clear()
|
||||
fillShips(shipNum)
|
||||
|
||||
fmt.Println("Player 1 (You):")
|
||||
//fillMatrix(PLAYER1_REAL_MATRIX)
|
||||
showMatrix(revealedShips1)
|
||||
fmt.Println()
|
||||
showMatrix(hiddenShips1)
|
||||
|
||||
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(3-0) + 0
|
||||
if shipChance == 1 {
|
||||
mat[i][i1] = "S"
|
||||
} else {
|
||||
mat[i][i1] = "_"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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"},
|
||||
|
@ -76,49 +129,3 @@ func game() {
|
|||
//
|
||||
// fmt.Scanln()
|
||||
// }
|
||||
fmt.Println("Player 1 (You):")
|
||||
//fillMatrix(PLAYER1_REAL_MATRIX)
|
||||
showMatrix(revealedShips1)
|
||||
fmt.Println()
|
||||
showMatrix(hiddenShips1)
|
||||
|
||||
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) {
|
||||
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(3-0) + 0
|
||||
if shipChance == 1 {
|
||||
mat[i][i1] = "S"
|
||||
} else {
|
||||
mat[i][i1] = "_"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue