From 8ce1e6f75a68f5d92fe4bf27263a861c16e71f35 Mon Sep 17 00:00:00 2001 From: piernov Date: Tue, 8 Apr 2014 23:37:14 +0200 Subject: Basic gameplay implementation --- main.lua | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/main.lua b/main.lua index 390e61a..aef7a80 100644 --- a/main.lua +++ b/main.lua @@ -1,9 +1,33 @@ require 'love2d-fakecanvas/fakecanvas' local Window = {} -local colors = { { 0, 0, 255, 255}, {0, 255, 0, 255}, {0, 255, 255, 255}, {255, 0, 0, 255}, {255, 0, 255, 255}, {255, 255, 0, 255} } +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 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) @@ -35,6 +59,7 @@ function love.load() -- 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} }) @@ -45,8 +70,16 @@ function love.load() 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 + 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) @@ -71,6 +104,8 @@ local function drawPolygon(polygon) 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 @@ -78,10 +113,24 @@ function love.mousepressed(x, y, b) x = x/Window.width y = y/Window.height if 0.875 < y and y < 0.915 then - for i = 0,5 do - if 0.50+i*0.075 < x and x < 0.50+i*0.075+0.04 then - table.insert(Keypressed, i) + 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 @@ -93,8 +142,14 @@ function love.draw() drawPolygon(polygon) end - love.graphics.setColor(255, 255, 255, 255) - for id, num in ipairs(Keypressed) do - love.graphics.print(num, (0.1+(id%5)*0.05)*Window.width, (0.6+((id-(id%5))/5)*0.05)*Window.height) + 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 -- cgit v1.2.3-70-g09d2