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
|
local GUI = { InGame = require("GUI/InGame")}
local Solo = {}
Solo.Keypressed = {{}}
Solo.Answer = {}
Solo.Hints = {}
function Solo:checkKeys()
local found = true
Solo.Hints[#Solo.Hints+1] = {}
for id, num in ipairs(Solo.Keypressed[#Solo.Keypressed]) do
if num == Solo.Answer[id] then -- Right
table.insert(Solo.Hints[#Solo.Hints], { Type = "rectangle", LineWidth = 0.0025, DrawMode = "fill",
Position = { x = 0.795+((#Solo.Hints[#Solo.Hints]-1)%2)*0.0325, y = 0.12+math.floor(#Solo.Hints[#Solo.Hints]/2)*0.0325+(#Solo.Keypressed-1)*0.075},
Dimension = {width = 0.0225, height = 0.025}, Colors = {0, 0, 171, 255} })
else -- Misplaced or Wrong
found = false
for k,v in ipairs(Solo.Answer) do
if num == v then -- Misplaced
table.insert(Solo.Hints[#Solo.Hints], { Type = "rectangle", LineWidth = 0.0025, DrawMode = "fill",
Position = { x = 0.795+((#Solo.Hints[#Solo.Hints]-1)%2)*0.0325, y = 0.12+math.floor(#Solo.Hints[#Solo.Hints]/2)*0.0325+(#Solo.Keypressed-1)*0.075},
Dimension = {width = 0.0225, height = 0.025}, Colors = {171, 171, 171, 255} })
end
end
end
end
return found
end
function Solo:init()
GUI.InGame.loadInterface()
tmpanswer = { 1, 2, 3, 4, 5, 6 }
if not love.getVersion then -- Check if LÖVE is older than 0.9.1, getVersion() introduced in version 0.9.1
love.math.random() -- Throw first value since it's not random in LÖVE 0.9.0
end
while #Solo.Answer < 4 do
local n = love.math.random(#tmpanswer)
table.insert(Solo.Answer, tmpanswer[n])
table.remove(tmpanswer, n) -- table.insert(GUI.InGame.Polygons, { Type = "print", Text = n, Position = {x = 0.1+i*0.01, y = 0.5}, Colors = {255, 255, 255, 255}})
end
-- Debug
for k,v in ipairs(Solo.Answer) do
print(k,v)
table.insert(GUI.InGame.Polygons, { Type = "print", Text = v, Position = {x = 0.1+k*0.01, y = 0.5}, Colors = {255, 255, 255, 255}})
end
end
function Solo:draw()
for id, polygon in ipairs(GUI.InGame.Polygons) do
GUI.InGame.drawPolygon(polygon)
end
for num, line in ipairs(Solo.Hints) do
for k, poly in ipairs(line) do
GUI.InGame.drawPolygon(poly)
end
end
for line, keys in ipairs(Solo.Keypressed) do
for id, num in ipairs(keys) do
GUI.InGame.drawPolygon({ Type = "rectangle", DrawMode = "fill", Position = { x = 0.50+(id-1)*0.075, y = 0.15+(line-1)*0.075-0.025}, Dimension = {width = 0.04, height = 0.04}, Colors = GUI.InGame.Colors[num] })
end
end
end
function Solo:mousepressed(x, y, b)
x = x/Screen.width
y = y/Screen.height
if 0.875 < y and y < 0.915 then
if x > 0.45 then
for i = 0,5 do
if 0.50+i*0.075 < x and x < 0.50+i*0.075+0.04 then
if #Solo.Keypressed > 7 or #Solo.Keypressed[#Solo.Keypressed] >= 4 then
return
else
for k,v in pairs(Solo.Keypressed[#Solo.Keypressed]) do
if v == i+1 then
return -- Disallow multiple identical colors in same line
end
end
table.insert(Solo.Keypressed[#Solo.Keypressed], i+1)
end
end
end
elseif 0.25 < x and x < 0.375 and #Solo.Keypressed <= 7 and #Solo.Keypressed[#Solo.Keypressed] == 4 then
if Solo.checkKeys() then
table.insert(GUI.InGame.Polygons, { Type = "print", Text = "FOUND !", Position = {x = 0.5, y = 0.5}, Colors = {255, 255, 255, 255}})
else
Solo.Keypressed[#Solo.Keypressed+1] = {}
end
elseif #Solo.Keypressed <= 7 and 0.075 < x and x < 0.200 and #Solo.Keypressed[#Solo.Keypressed] > 0 then
Solo.Keypressed[#Solo.Keypressed] = {}
end
end
end
return Solo
|