-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
46 lines (35 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"github.com/ladygogo/BattleGopher/player"
)
func main() {
player1, _ := player.InitializePlayer("Linda")
player2, _ := player.InitializePlayer("Player 2")
playerArray := [...]player.Player{player1, player2}
for i, _ := range playerArray {
playerArray[i].NewBoard(2)
}
fmt.Println("Welcome to Battle Gopher!")
fmt.Println("---------------------")
var row, column int
playerIndex := 0
for playerArray[0].Gameboard.AllGophersSunk() == false && playerArray[1].Gameboard.AllGophersSunk() == false {
fmt.Printf("%s's Turn\n", playerArray[(playerIndex)%2].Name)
playerArray[(playerIndex + 1)%2].Gameboard.PrettyPrint()
fmt.Print("Enter a row-> ")
fmt.Scanf("%d", &row)
fmt.Print("Enter a column-> ")
fmt.Scanf("%d", &column)
hit, err := playerArray[(playerIndex + 1)%2].Gameboard.CheckForHit(row - 1, column - 1)
if err != nil {
fmt.Println(err)
fmt.Println("Try again\n")
} else {
playerArray[(playerIndex + 1)%2].Gameboard.PrettyPrint()
}
if hit == false && err == nil {
playerIndex ++
}
}
}