check solutions

This commit is contained in:
Kartik K. Agaram 2023-11-16 20:23:47 -08:00
parent 60dce24988
commit 0f501a770f
6 changed files with 53 additions and 10 deletions

View File

@ -1,15 +1,7 @@
on.draw = function()
Buttons.button_handlers = {}
local w = App.width('next')
button(Buttons, 'next', {x=Safe_width-w-20, y=50, w=w+10, h=love.graphics.getFont():getHeight()+10, bg={r=0.6, g=0.8, b=0.6},
icon = function(p)
App.color{r=0, g=0, b=0}
love.graphics.print('next', p.x+5, p.y+5)
end,
onpress1 = function()
animate(new)
end,
})
draw_next_button()
draw_status()
if Draw == 'problem' then
draw_sum_grid(Problem)
else

View File

@ -1,4 +1,5 @@
new = function()
generate()
create_problem()
Status = ''
end

2
0037-Status Normal file
View File

@ -0,0 +1,2 @@
-- Is the answer correct?
Status = '' -- incomplete. Can also be 'yes' or 'no'

12
0038-draw_next_button Normal file
View File

@ -0,0 +1,12 @@
draw_next_button = function()
local w = App.width('next')
button(Buttons, 'next', {x=Safe_width-w-20, y=50, w=w+10, h=love.graphics.getFont():getHeight()+10, bg={r=0.6, g=0.8, b=0.6},
icon = function(p)
App.color{r=0, g=0, b=0}
love.graphics.print('next', p.x+5, p.y+5)
end,
onpress1 = function()
animate(new)
end,
})
end

24
0039-draw_status Normal file
View File

@ -0,0 +1,24 @@
draw_status = function()
local w = App.width('check')
local x = Safe_width-w-20
local y = 50+love.graphics.getFont():getHeight()+150
button(Buttons, 'check', {x=x, y=y, w=w+10, h=love.graphics.getFont():getHeight()+10, bg={r=0.6, g=0.8, b=0.6},
icon = function(p)
App.color{r=0, g=0, b=0}
love.graphics.print('check', p.x+5, p.y+5)
end,
onpress1 = function()
Status = check_status()
end,
})
x = Safe_width-260
y = y+120
love.graphics.rectangle('line', x,y, 250,love.graphics.getFont():getHeight()+20)
if Status == 'yes' then
App.color{r=0, g=0.6, b=0}
love.graphics.print('yes!', x+10, y+10)
elseif Status == 'no' then
App.color{r=1, g=0, b=0}
love.graphics.print('sorry', x+10, y+10)
end
end

12
0040-check_status Normal file
View File

@ -0,0 +1,12 @@
check_status = function()
for y=1,2 do
for x=1,2 do
if Problem.data[y][x] == '' then
return ''
elseif Problem.data[y][x] ~= Solution.data[y][x] then
return 'no'
end
end
end
return 'yes'
end