-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex-existcyclegraph.go
129 lines (110 loc) · 3.21 KB
/
ex-existcyclegraph.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
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"image"
"math/rand"
"github.com/hajimehoshi/ebiten/v2"
)
func initExistCycleGraph(correction bool, graphCode, questionCode, answerCode int) (e exo, gCode, qCode int) {
e.BasicSetup()
e.id = existCycleGraph
e.successRequired = 5
numNodes := 6
elementSpacing := 100
// title setup
e.titleImage = titleExistCycleGraphImage
xTitleShift, yTitleShift := e.titleImage.Size()
e.titleXPosition = (windowWidth - xTitleShift) / 2
e.titleYPosition = elementSpacing
e.successCounterY = elementSpacing + yTitleShift
yTitleShift += spriteSide
// graph setup part 1
e.modifiableGraph = false
e.modifiableAdjMatr = false
e.displayGraph = true
e.displayAdjMatr = false
// question setup part 1
var from int
if correction {
from, _ = decodeFromToQuestion(questionCode, numNodes)
qCode = questionCode
} else {
from = rand.Intn(numNodes)
qCode = encodeFromToQuestion(from, from, numNodes)
}
// graph setup part 2
if correction {
e.g.decode(graphCode, numNodes)
gCode = graphCode
} else {
e.g.genConnectedGraph(numNodes, 8, 12, from, from)
gCode = e.g.encode()
}
e.g.linkMatrGraph = false
nodeSpacing := 300
e.g.xposition = (windowWidth - 2*nodeSpacing) / 2
e.g.yposition = 2*elementSpacing + yTitleShift
e.g.xsize = 2 * nodeSpacing
e.g.ysize = nodeSpacing
e.g.nodes[0].loopPosition = loopTopLeft
e.g.nodes[1].xposition = nodeSpacing
e.g.nodes[1].yposition = nodeSpacing / 4
e.g.nodes[1].loopPosition = loopTopLeft
e.g.nodes[2].xposition = 2 * nodeSpacing
e.g.nodes[2].loopPosition = loopTopRight
e.g.nodes[3].yposition = nodeSpacing
e.g.nodes[3].loopPosition = loopBottomLeft
e.g.nodes[4].xposition = nodeSpacing
e.g.nodes[4].yposition = 3 * nodeSpacing / 4
e.g.nodes[4].loopPosition = loopBottomLeft
e.g.nodes[5].xposition = 2 * nodeSpacing
e.g.nodes[5].yposition = nodeSpacing
e.g.nodes[5].loopPosition = loopBottomRight
// question setup part 2
xshift, yshift := existCycleGraphImage.Size()
e.drawQuestion = func(screen *ebiten.Image) {
options := ebiten.DrawImageOptions{}
options.GeoM.Translate(float64((windowWidth-xshift)/2), float64(e.g.ysize+4*elementSpacing+yTitleShift))
screen.DrawImage(
existCycleGraphImage,
&options,
)
// from label
options.GeoM.Translate(float64(11*spriteSide-spriteSide/4), 0)
xLabel := from % 10
yLabel := from / 10
labelSubimage := image.Rect(
xLabel*spriteSide, (yLabel+1)*spriteSide,
(xLabel+1)*spriteSide, (yLabel+2)*spriteSide,
)
screen.DrawImage(
graphElementsImage.SubImage(labelSubimage).(*ebiten.Image),
&options,
)
}
// answers setup
e.hasAnswerSheet = true
answerSize, _ := ouiImage.Size()
e.answers.init((windowWidth-3*answerSize)/2, e.g.ysize+yshift+4*elementSpacing+20+yTitleShift)
e.answers.addButton(0, 0, ouiImage)
e.answers.addButton(2*answerSize, 0, nonImage)
answer := 1
if e.g.existCycle(from) {
answer = 0
}
if correction {
if answerCode < len(e.answers.clics) && answerCode >= 0 {
e.answers.clics[answerCode] = 1
}
}
e.checkResult = func() (bool, bool) {
return e.answers.clics[answer] >= 1, e.answers.clics[0]+e.answers.clics[1] >= 1
}
e.codeAnswer = func() int {
if e.answers.clics[0] >= 1 {
return 0
}
return 1
}
// return exercise
return e, gCode, qCode
}