From 8cd45de78f8907152236e23fe0927b528c687dfd Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 15 Mar 2024 13:06:00 +0100 Subject: [PATCH] Players can now properly input guesses --- game.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/game.go b/game.go index e5f505d..15e7f58 100644 --- a/game.go +++ b/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) }