Added coordinate selection for main game
This commit is contained in:
parent
860b50dd59
commit
0aad28a230
41
game.go
41
game.go
|
@ -4,6 +4,9 @@ import (
|
|||
"fmt"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -46,15 +49,43 @@ func game() {
|
|||
fmt.Scanln(&shipNum)
|
||||
clear()
|
||||
fillShips(shipNum)
|
||||
|
||||
fmt.Println("Player 1 (You):")
|
||||
//fillMatrix(PLAYER1_REAL_MATRIX)
|
||||
showMatrix(revealedShips1)
|
||||
fmt.Println()
|
||||
showMatrix(hiddenShips1)
|
||||
for {
|
||||
clear()
|
||||
gameStatus()
|
||||
checkWin()
|
||||
|
||||
fmt.Printf("X coordinate: ")
|
||||
x := scanLine()
|
||||
fmt.Printf("Y coordinate: ")
|
||||
y := scanLine()
|
||||
xint, _ := strconv.Atoi(x)
|
||||
yint, _ := strconv.Atoi(y)
|
||||
xint--
|
||||
yint--
|
||||
bombingText := fmt.Sprintf("Bombing X: %v / Y: %v.", x, y)
|
||||
for i := 0; i < 3; i++ {
|
||||
fmt.Printf("\r%v", bombingText)
|
||||
time.Sleep(time.Second)
|
||||
bombingText = bombingText + "."
|
||||
}
|
||||
fmt.Printf("\nBombed!")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func checkWin() {
|
||||
var winStatus bool = reflect.DeepEqual(revealedShips1, hiddenShips1)
|
||||
if winStatus == true {
|
||||
fmt.Println("You win!")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
func gameStatus() {
|
||||
fmt.Println("Player 1 (You):")
|
||||
showMatrix(hiddenShips1)
|
||||
}
|
||||
|
||||
func showMatrix(mat [][]string) {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func singleplayer() {
|
||||
game()
|
||||
}
|
Loading…
Reference in New Issue