diff --git a/game.go b/game.go index 126507a..e5f505d 100644 --- a/game.go +++ b/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() + 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) - - os.Exit(0) - } func showMatrix(mat [][]string) { diff --git a/singleplayer.go b/singleplayer.go new file mode 100644 index 0000000..97748d9 --- /dev/null +++ b/singleplayer.go @@ -0,0 +1,5 @@ +package main + +func singleplayer() { + game() +}