-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex-existarcmatr.go
125 lines (108 loc) · 2.88 KB
/
ex-existarcmatr.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
package main
import (
"image"
"math/rand"
"github.com/hajimehoshi/ebiten/v2"
)
func initExistArcMatr(correction bool, graphCode, questionCode, answerCode int) (e exo, gCode, qCode int) {
e.BasicSetup()
e.id = existArcMatr
e.successRequired = 5
numNodes := 4
elementSpacing := 100
// title setup
e.titleImage = title2Image
xTitleShift, yTitleShift := e.titleImage.Size()
e.titleXPosition = (windowWidth - xTitleShift) / 2
e.titleYPosition = elementSpacing
e.successCounterY = elementSpacing + yTitleShift
yTitleShift += spriteSide
// graph setup
e.modifiableGraph = false
e.modifiableAdjMatr = false
e.displayGraph = false
e.displayAdjMatr = true
if correction {
e.g.decode(graphCode, numNodes)
gCode = graphCode
} else {
e.g.genConnectedGraph(numNodes, 4, 12, -1, -1)
gCode = e.g.encode()
}
e.g.linkMatrGraph = false
matrixSize := 5 * matrixCellSize
e.g.xmatrposition = (windowWidth - matrixSize) / 2
e.g.ymatrposition = 2*elementSpacing + yTitleShift
// question setup
var from, to int
if correction {
from, to = decodeFromToQuestion(questionCode, numNodes)
qCode = questionCode
} else {
from = rand.Intn(numNodes)
to = rand.Intn(numNodes-1)
if to == from {
to = numNodes-1
}
qCode = encodeFromToQuestion(from, to, numNodes)
}
xshift, yshift := ex2Image.Size()
e.drawQuestion = func(screen *ebiten.Image) {
options := ebiten.DrawImageOptions{}
options.GeoM.Translate(float64((windowWidth-xshift)/2), float64(matrixSize+3*elementSpacing+yTitleShift))
screen.DrawImage(
ex2Image,
&options,
)
// from label
options.GeoM.Translate(float64(3*spriteSide), 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,
)
// to label
options.GeoM.Translate(float64(spriteSide), 0)
xLabel = to % 10
yLabel = to / 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, matrixSize+yshift+3*elementSpacing+20+yTitleShift)
e.answers.addButton(0, 0, ouiImage)
e.answers.addButton(2*answerSize, 0, nonImage)
answer := 1
if e.g.edges[from][to] > 0 {
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
}