-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdk-demo.go
86 lines (71 loc) · 1.66 KB
/
sdk-demo.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"log"
"github.com/gervasioamy/minesweeper-sdk/sdk"
)
var client *sdk.SDK
//const host string = "http://localhost:8080/api/"
const host string = "https://gamy-minesweeper-api.herokuapp.com/api/"
func main() {
log.Print("Starting SDK test ...")
sdk.Initialize(host, false)
client = sdk.GetInstance()
// Test happy path
log.Print("Let's test a happy path...")
gameid, err := client.CreateGame(5, 5, 4, "John Doe")
if err != nil {
fmt.Errorf("Error: %v", err)
}
discoverOne(gameid, 0, 0)
// force and eror
discoverOne(gameid, 0, 0)
flagOne(gameid, 4, 4)
unflagOne(gameid, 4, 4)
pause(gameid)
// force error
pause(gameid)
resume(gameid)
//force error
resume(gameid)
}
func discoverOne(gameid string, row, col int) {
discoverResponse, err := client.DiscoverCell(gameid, 0, 0)
if err != nil {
fmt.Errorf("Error: %v", err)
return
}
if discoverResponse.GameStatus == "GAME OVER" {
log.Print("GAME OVER")
return
}
log.Printf("Cell (%v, %v) discovered successfully, toghether with other %v cells", 0, 0, len(discoverResponse.DiscoveredCells))
}
func flagOne(gameid string, row, col int) bool {
response, err := client.FlagCell(gameid, row, col)
if err != nil {
log.Println(err)
}
return response
}
func unflagOne(gameid string, row, col int) bool {
response, err := client.UnflagCell(gameid, row, col)
if err != nil {
log.Println(err)
}
return response
}
func pause(gameid string) bool {
response, err := client.Pause(gameid)
if err != nil {
log.Println(err)
}
return response
}
func resume(gameid string) bool {
response, err := client.Resume(gameid)
if err != nil {
log.Println(err)
}
return response
}