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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
require 'love2d-fakecanvas/fakecanvas'
local Window = {}
local colors = { {255, 0, 0, 255}, {255, 128, 0, 255}, {255, 255, 0, 255}, {0, 255, 0, 255}, {128, 128, 128, 255}, {255, 255, 255, 255} }
local Polygons = {}
local Keypressed = {{}}
local Answer = {}
local Hints = {}
local function checkKeys()
local ansfound = true
local tmpans = {}
for k,v in ipairs(Answer) do table.insert(tmpans, v) end
local goodnum = 0
for id, num in ipairs(Keypressed[#Keypressed]) do
for j, answer in ipairs(tmpans) do
if num == answer and id == j then
goodnum = 2
tmpans[j] = -1
elseif num == answer and goodnum < 1 then
goodnum = 1
tmpans[j] = -1
end
end
if goodnum < 2 then ansfound = false end
table.insert(Hints, { Type = "print", Text = goodnum, Position = { x = 0.1 + id*0.05, y = 0.1+#Keypressed*0.05 }, Colors = { 255, 255, 255, 255}})
goodnum = 0
end
return ansfound
end
function love.load()
love.graphics.setBackgroundColor(0, 0, 0)
-- Inner window border
table.insert(Polygons, { Type = "rectangle", DrawMode = "line", LineWidth = 0.005, Position = { x = 0.005, y = 0.005}, Dimension = {width = 0.99, height = 0.99}, Colors = {0, 0, 171, 255} })
-- Background
for i = 0, 5 do
table.insert(Polygons, { Type = "polygon", DrawMode = "fill", Position = { x1 = 0.01, y1 = 0.02+0.02*i, x2 = 0.02+0.02*i, y2 = 0.01, x3 = 0.03+0.02*i, y3 = 0.01, x4 = 0.01, y4 = 0.03+0.02*i}, Colors = {0, 0, 171, 255} })
table.insert(Polygons, { Type = "polygon", DrawMode = "fill", Position = { x1 = 0.99, y1 = 0.98-0.02*i, x2 = 0.98-0.02*i, y2 = 0.99, x3 = 0.97-0.02*i, y3 = 0.99, x4 = 0.99, y4 = 0.97-0.02*i}, Colors = {0, 0, 171, 255} })
end
-- Left box
table.insert(Polygons, { Type = "rectangle", DrawMode = "fill", Position = { x = 0.05, y = 0.05}, Dimension = {width = 0.35, height = 0.90}, Colors = {0, 0, 0, 255} })
table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.05, y = 0.05}, Dimension = {width = 0.35, height = 0.90}, Colors = {0, 0, 171, 255} })
table.insert(Polygons, { Type = "line", Position = { x1 = 0.05, y1 = 0.1, x2 = 0.4, y2 = 0.1}, Colors = {0, 0, 171, 255} })
-- Left box buttons
table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.075, y = 0.875}, Dimension = {width = 0.125, height = 0.05}, Colors = {0, 0, 171, 255} })
table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.25, y = 0.875}, Dimension = {width = 0.125, height = 0.05}, Colors = {0, 0, 171, 255} })
-- Left box content
table.insert(Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.375, y1 = 0.15, x2 = 0.375, y2 = 0.75}, Colors = {0, 0, 171, 255} })
-- Right top box
table.insert(Polygons, { Type = "rectangle", LineWidth = 0.005, DrawMode = "line", Position = { x = 0.45, y = 0.05}, Dimension = {width = 0.50, height = 0.75}, Colors = {0, 0, 171, 255} })
table.insert(Polygons, { Type = "line", Position = { x1 = 0.45, y1 = 0.1, x2 = 0.95, y2 = 0.1}, Colors = {0, 0, 171, 255} })
-- Right top box content
table.insert(Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.375-0.005, y1 = 0.75, x2 = 0.52+5*0.075+0.005, y2 = 0.75}, Colors = {0, 0, 171, 255} })
table.insert(Polygons, { Type = "line", LineWidth = 0.01, Position = { x1 = 0.48, y1 = 0.75, x2 = 0.48, y2 = 0.15}, Colors = {0, 0, 171, 255} })
-- Right bottom box
table.insert(Polygons, { Type = "rectangle", LineWidth = 0.005, DrawMode = "fill", Position = { x = 0.45, y = 0.85}, Dimension = {width = 0.50, height = 0.10}, Colors = {0, 0, 0, 255} })
table.insert(Polygons, { Type = "rectangle", DrawMode = "line", Position = { x = 0.45, y = 0.85}, Dimension = {width = 0.50, height = 0.10}, Colors = {0, 0, 171, 255} })
-- Right bottom box buttons
for i = 0, 5 do
table.insert(Polygons, { Type = "rectangle", DrawMode = "fill", Position = { x = 0.50+i*0.075, y = 0.875}, Dimension = {width = 0.04, height = 0.04}, Colors = colors[i+1] })
table.insert(Polygons, { Type = "rectangle", DrawMode = "line", LineWidth = 0.01, Position = { x = 0.50+i*0.075, y = 0.875}, Dimension = {width = 0.04, height = 0.04}, Colors = {0, 0, 171, 255} })
table.insert(Polygons, { Type = "line", Position = { x1 = 0.52+i*0.075, y1 = 0.75, x2 = 0.52+i*0.075, y2 = 0.875}, Colors = {0, 0, 171, 255} })
if i < 5 then
table.insert(Polygons, { Type = "line", Position = { x1 = 0.5+i*0.075+0.04, y1 = 0.895, x2 = 0.52+(i+1)*0.075, y2 = 0.895}, Colors = {0, 0, 171, 255} })
end
end
for i = 1, 4 do
local n = love.math.random(1, 6)
table.insert(Answer, n)
end
for k,v in ipairs(Answer) do print(k,v) end
end
local function drawPolygon(polygon)
if polygon.Colors then
love.graphics.setColor(unpack(polygon.Colors))
end
if polygon.LineWidth then
love.graphics.setLineWidth(polygon.LineWidth*(Window.width+Window.height)/2)
end
if polygon.Type == "rectangle" then
love.graphics.rectangle(polygon.DrawMode, polygon.Position.x*Window.width, polygon.Position.y*Window.height,
polygon.Dimension.width*Window.width, polygon.Dimension.height*Window.height)
elseif polygon.Type == "polygon" then
love.graphics.polygon(polygon.DrawMode, polygon.Position.x1*Window.width, polygon.Position.y1*Window.height,
polygon.Position.x2*Window.width, polygon.Position.y2*Window.height,
polygon.Position.x3*Window.width, polygon.Position.y3*Window.height,
polygon.Position.x4*Window.width, polygon.Position.y4*Window.height)
elseif polygon.Type == "line" then
love.graphics.line(polygon.Position.x1*Window.width, polygon.Position.y1*Window.height,
polygon.Position.x2*Window.width, polygon.Position.y2*Window.height)
elseif polygon.Type == "print" then
love.graphics.print(polygon.Text, polygon.Position.x*Window.width, polygon.Position.y*Window.height)
end
end
function love.mousepressed(x, y, b)
x = x/Window.width
y = y/Window.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 #Keypressed[#Keypressed] >= 4 then
return
else
table.insert(Keypressed[#Keypressed], i+1)
end
end
end
elseif 0.25 < x and x < 0.375 and #Keypressed < 7 and #Keypressed[#Keypressed] == 4 then
if checkKeys() then
table.insert(Polygons, { Type = "print", Text = "FOUND !", Position = {x = 0.5, y = 0.5}, Colors = {255, 255, 255, 255}})
else
Keypressed[#Keypressed+1] = {}
end
elseif 0.075 < x and x < 0.200 and #Keypressed[#Keypressed] > 0 then
Keypressed[#Keypressed] = {}
end
end
end
function love.draw()
Window.width, Window.height = love.window.getDimensions()
for id, polygon in ipairs(Polygons) do
drawPolygon(polygon)
end
for id, hint in ipairs(Hints) do
drawPolygon(hint)
end
for line, keys in ipairs(Keypressed) do
for id, num in ipairs(keys) do
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 = colors[num] })
love.graphics.print(num, (0.1+(id%5)*0.05)*Window.width, (0.6+((id-(id%5))/5)*0.05)*Window.height)
end
end
end
|