Players can now properly input guesses
This commit is contained in:
parent
0aad28a230
commit
8cd45de78f
26
game.go
26
game.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue