Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function love.load()
- love.resize(love.graphics.getDimensions())
- gGuesses, gCurrentGuess = {}, 1
- for i = 1, 10 do
- gGuesses[i] = { digits = {} }
- end
- end
- function love.resize(w, h)
- gWidth, gHeight = w, h
- end
- function drawDigit(digit, x, y)
- love.graphics.line(x, y, x + 10, y)
- if digit then
- love.graphics.print(digit, x + 1, y - 15)
- end
- end
- function drawSingleGuess(guess, x, y)
- for i = 0, 3 do
- drawDigit(guess.digits[i + 1], x + i * (10 + 6), y)
- end
- if guess.dots then
- for i = 1, 4 do
- if guess.dots[i] == 0 then
- love.graphics.circle("fill", x + 70 + i * 14, y - 4, 4)
- elseif guess.dots[i] == 1 then
- love.graphics.circle("line", x + 70 + i * 14, y - 4, 6)
- else
- love.graphics.circle("fill", x + 70 + i * 14, y - 4, 6)
- end
- end
- end
- end
- function love.draw()
- for i = 0, 9 do
- drawSingleGuess(
- gGuesses[gCurrentGuess],
- (gWidth - (10 * 4 + 6 * 3)) / 2,
- (gHeight - (10 * 20)) / 2 + i * 20
- )
- end
- end
- function love.keypressed(key)
- if key == "escape" then
- love.event.quit()
- elseif key == "backspace" then
- gGuesses[gCurrentGuess].digits = {}
- elseif key == "return" then
- if #gCurrentDigits ~= 4 then
- return
- end
- gCurrentGuess = gCurrentGuess + 1
- elseif string.match("123456789", key) then
- if #gCurrentDigits == 4 then
- return
- end
- for i = 1, #gCurrentDigits do
- if gCurrentDigits[i] == key then
- return
- end
- end
- table.insert(gCurrentDigits, key)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement