Players can now properly input guesses

This commit is contained in:
raul 2024-03-15 13:06:00 +01:00
parent 0aad28a230
commit 8cd45de78f
1 changed files with 19 additions and 7 deletions

26
game.go
View File

@ -30,7 +30,7 @@ func fillShips(tiles int) {
if shipChance == 1 {
revealedShips1[i][i1] = "S"
} else {
revealedShips1[i][i1] = "_"
revealedShips1[i][i1] = "X"
}
}
}
@ -63,18 +63,27 @@ func game() {
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 + "."
}
// 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)
checkShip(xint, yint)
}
}
func checkShip(x int, y int) {
if revealedShips1[x][y] == "S" {
hiddenShips1[x][y] = "S"
} else {
hiddenShips1[x][y] = "X"
}
}
func checkWin() {
var winStatus bool = reflect.DeepEqual(revealedShips1, hiddenShips1)
if winStatus == true {
@ -84,6 +93,9 @@ func checkWin() {
}
func gameStatus() {
fmt.Println("_ = Unknown")
fmt.Println("X = Missed")
fmt.Println("S = Ship")
fmt.Println("Player 1 (You):")
showMatrix(hiddenShips1)
}