You are on page 1of 2

push = require 'push'

WINDOW_WIDTH = 1280
WINDOW_HEIGHT = 720

VIRTUAL_WIDTH = 512
VIRTUAL_HEIGHT = 288

largeFont = love.graphics.newFont('font.ttf', 24)


smallFont = love.graphics.newFont('font.ttf', 16)
invalidEntry = false
selectedNumber = 0
gameState = 'menu'

function love.load( )
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
vysnc = true,
resizable = true,
fullscren = false
})

randOne = love.math.random(1,50)
randTwo = love.math.random(1,50)
randThree = love.math.random(1,50)
randFour = love.math.random(1,50)
end

function love.keypressed(key)
if gameState == 'menu' then
if key == "1" then
selectedNumber = tonumber(randOne)
invalidEntry = false
gameState = "list"

elseif key == "2" then


selectedNumber = tonumber(randTwo)
invalidEntry = false
gameState = "list"

elseif key == "3" then


selectedNumber = tonumber(randThree)
invalidEntry = false
gameState = "list"

elseif key == "4" then


selectedNumber = tonumber(randFour)
invalidEntry = false
gameState = "list"

else
invalidEntry = true
end
else
gameState = 'menu'
end
end
function fibonacci(n)
a = 0
b = 1

for i = 1, n do
a, b = b, a + b
end
return a
end

function love.draw( )
push:start()
if gameState == 'menu' then
love.graphics.setFont(largeFont)
love.graphics.print('SELECT ITEM', 20, 20)
love.graphics.print('1. ' .. randOne, 20, 44)
love.graphics.print('2. ' .. randTwo, 20, 68)
love.graphics.print('3. ' .. randThree, 20, 92)
love.graphics.print('4. ' .. randFour, 20, 116)
if invalidEntry then
love.graphics.print('Invalid Selection.', 20, 140)
end
else
love.graphics.setFont(smallFont)
love.graphics.print('The Fibonacci number for memeber number ' ..
selectedNumber .. ' is ' .. fibonacci(selectedNumber) , 20, 140)

love.graphics.print('Press any key..', 20, 200)


end
push:finish()
end

You might also like