-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.go
118 lines (105 loc) · 2.42 KB
/
events.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
//"github.com/therecipe/qt/widgets"
//"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/core"
"math/rand"
)
/*
func Zoom(window *MainWindow) func(int) {
return func(n int) {
s := float64(n)/100.0
window.View.ResetMatrix()
window.View.Scale(s, s)
}
}
func Rotate(window *MainWindow) func(int) {
return func(n int) {
window.View.ResetMatrix()
window.View.Rotate(float64(n))
}
}
*/
func WindowAdvance(window *MainWindow) func() {
return func() {
window.AdvanceGameState()
window.Scene.Advance()
window.SetWindowModified(true)
}
}
func TimerToggle(window *MainWindow) func(bool) {
return func(checked bool) {
if checked {
window.Timer.Start2()
window.PauseButton.SetText("Pause")
} else {
window.Timer.Stop()
window.PauseButton.SetText("Start")
}
}
}
func Transform(window *MainWindow) func(int) {
return func(int) {
s := float64(window.ZoomSlider.Value())/100.0
r := float64(window.RotateSlider.Value())
window.View.ResetMatrix()
window.View.Scale(s, s)
window.View.Rotate(r)
}
}
func Randomize(window *MainWindow) func(bool) {
return func(bool) {
window.Pause()
N := len(window.GameState)-2
M := len(window.GameState[0])-2
if window.OkToContinue() {
for i := 1; i <= N; i++ {
for j := 1; j <= M; j++ {
if rand.Intn(2)==0 {
window.GameState[i][j] = &Dead
} else {
window.GameState[i][j] = &Live
}
}
}
}
window.Scene.Update(core.NewQRectF())
window.SetWindowModified(true)
}
}
func SetTimeInterval(window *MainWindow) func(int) {
return func(n int) {
window.Timer.SetInterval(n)
}
}
func (window *MainWindow) Pause() {
window.Timer.Stop()
window.PauseButton.SetChecked(false)
window.PauseButton.SetText("Start")
}
func (window *MainWindow) Start() {
window.Timer.Start2()
window.PauseButton.SetChecked(true)
window.PauseButton.SetText("Start")
}
func (window *MainWindow) AdvanceGameState() {
M := len(window.GameState)-2
N := len(window.GameState[0])-2
b := window.GameState
for i:=1; i <= M; i++ {
for j:=1; j <= N; j++ {
//window.GameState[i][j] = !window.GameState[i][j]
live := *b[i-1][j-1] + *b[i-1][j] + *b[i-1][j+1] +
*b[i][j-1] + *b[i][j+1] +
*b[i+1][j-1] + *b[i+1][j] + *b[i+1][j+1]
if live==3 || (live==2 && *b[i][j]==1) {
ReservedState[i][j] = &Live
} else {
ReservedState[i][j] = &Dead
}
}
}
for i:=1; i <= M; i++ {
copy(b[i], ReservedState[i])
}
}