-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
127 lines (123 loc) · 3.42 KB
/
main.lua
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
--[[
Make a score that counts how many moves were made.
Make message that congratulates to player for winning
]]
function love.load()
--seed for the RNG
math.randomseed(os.time())
--map container
map = {}
undos = {0}
count = 1
--solution container
pr_count = 0
pr = {0, 0, 0, 0, 0}
width = 320
height = 448
--sets the window
love.window.setMode(width, height, {resizable=true, vsync=false, minwidth=width, minheight=width})
light_on = love.graphics.newImage("gfx/light_on.png")
light_off = love.graphics.newImage("gfx/light_off.png")
bottom = love.graphics.newImage("gfx/bottom.png")
--sets all the toggles to false
clear = function()
for i = 0,49 do
map[i] = false
i = i + 1
end
count = 1
end
clear()
--creates the function toggle. this is the main game logic
rand = function(m)
m = math.random(4,7)
end
toggle = function(m)
if m < 25 then
if m ~= 5 then
if m ~= 10 then
if m ~= 15 then
if m ~= 20 then
map[m-1] = not map[m-1]
end
end
end
end
if m ~= 4 then
if m ~= 9 then
if m ~= 14 then
if m ~= 19 then
map[m+1] = not map[m+1]
end
end
end
end
map[m] = not map[m]
map[m+5] = not map[m+5]
map[m-5] = not map[m-5]
end
end
--this useful function measures the length of tables so the loops know how many times to count
function tablelength(T)
local counter = 0
for _ in pairs(T) do
counter = counter + 1
end
return counter
end
c = tablelength(undos)
end
function love.draw()
--draws the boxes
for a = 0, 4 do
for i = 0, 4 do
if map[i+(5*a)] == true then
love.graphics.draw(light_on, i*64, a*64)
else
love.graphics.draw(light_off, i*64, a*64)
end
end
end
love.graphics.draw(bottom, 0, 320)
end
--mouse presses to toggle the lights and button controls
function love.mousepressed(x, y, button, istouch)
if button == 1 then
xmap = math.floor(x/64)
ymap = math.floor(y/64)
m = xmap + (ymap * 5)
--the area below lights
if m < 25 then
count = count + 1
undos[count] = m
--new game button, clears tables and the board, then makes random toggles for the puzzle
elseif m == 25 or m == 26 or m == 27 or m == 28 then
counter = {}
pr = {}
clear()
for i = 1, 10 do
b = math.random(2, 24)
toggle(b)
pr[i] = (b+1)
i = i + 1
end
pr_count = 10
--undo button
elseif m == 30 or m == 31 then
if count > 1 then
toggle(undos[count])
count = count - 1
end
--hint button
elseif m == 33 or m == 34 then
if count > 1 then
toggle(undos[count])
count = count - 1
elseif pr_count > 0 then
toggle(pr[pr_count]-1)
pr_count = pr_count - 1
end
end
toggle(m)
end
end