-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (53 loc) · 2.09 KB
/
main.go
File metadata and controls
69 lines (53 loc) · 2.09 KB
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
package main
import (
"fmt"
"time"
"github.com/gigaroby/quick-a/frontend/session"
"github.com/gigaroby/quick-a/frontend/surface"
"honnef.co/go/js/dom"
)
var (
document = dom.GetWindow().Document()
canvas = document.GetElementByID("board").(*dom.HTMLCanvasElement)
messages = document.GetElementByID("messages").(*dom.HTMLPreElement)
game = document.GetElementByID("game").(*dom.HTMLDivElement)
wait = document.GetElementByID("wait").(*dom.HTMLDivElement)
final = document.GetElementByID("final").(*dom.HTMLDivElement)
fReload = document.GetElementByID("f_reload").(*dom.HTMLInputElement)
fCorrect = document.GetElementByID("f_correct").(*dom.HTMLSpanElement)
fWrong = document.GetElementByID("f_wrong").(*dom.HTMLSpanElement)
fMessage = document.GetElementByID("f_message").(*dom.HTMLSpanElement)
wInstructions = document.GetElementByID("w_instructions").(*dom.HTMLSpanElement)
wMessage = document.GetElementByID("w_message").(*dom.HTMLSpanElement)
wReady = document.GetElementByID("w_ready").(*dom.HTMLInputElement)
predictions = document.GetElementByID("predictions").(*dom.HTMLSpanElement)
instructions = document.GetElementByID("instructions").(*dom.HTMLSpanElement)
countdown = document.GetElementByID("countdown").(*dom.HTMLSpanElement)
clear = document.GetElementByID("clr").(*dom.HTMLInputElement)
)
func showError(err error) {
messages.SetInnerHTML(fmt.Sprintf("[%s] %s", time.Now().String(), err.Error()))
}
func main() {
surface := surface.New(canvas)
sess, err := session.New(6, surface, instructions, predictions, countdown, wInstructions, wMessage, fCorrect, fWrong, fMessage, game, wait, final)
if err != nil {
showError(err)
return
}
dom.GetWindow().AddEventListener("resize", false, func(d dom.Event) {
surface.Resize()
})
wReady.AddEventListener("click", false, func(d dom.Event) {
go func() {
sess.NextRound()
}()
})
clear.AddEventListener("click", false, func(d dom.Event) {
surface.Clear()
messages.SetInnerHTML("")
})
fReload.AddEventListener("click", false, func(d dom.Event) {
dom.GetWindow().Location().Call("reload")
})
}