Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This Program is made by Xelostar.
- When showing it, please give credit.
- Link to my channel:
- https://www.youtube.com/channel/UCDE2STpSWJrIUyKtiYGeWxw
- ]]--
- code = {}
- tries = {}
- points = {}
- function randomColor()
- local color = math.random(1, 8)
- if (color == 1) then
- color = colors.red
- elseif (color == 2) then
- color = colors.orange
- elseif (color == 3) then
- color = colors.yellow
- elseif (color == 4) then
- color = colors.lime
- elseif (color == 5) then
- color = colors.green
- elseif (color == 6) then
- color = colors.lightBlue
- elseif (color == 7) then
- color = colors.blue
- elseif (color == 8) then
- color = colors.purple
- end
- return color
- end
- function generateRandomCode()
- while table.getn(code) < 4 do
- local color = randomColor()
- local newColor = true
- for k, v in pairs(code) do
- if (v == color) then
- newColor = false
- end
- end
- if (newColor == true) then
- table.insert(code, color)
- end
- end
- end
- function drawScreen()
- for tryNr, try in pairs(tries) do
- for k, v in pairs(try) do
- paintutils.drawFilledBox(k * 4, tryNr * 2, k * 4 + 3, tryNr * 2 + 1, v)
- end
- end
- for k, v in pairs(points) do
- for k2, v2 in pairs(v) do
- paintutils.drawFilledBox(k2 * 4 + 20, k * 2, k2 * 4 + 3 + 20, k * 2 + 1, v2)
- end
- end
- paintutils.drawFilledBox(44, 2, 48, 3, colors.red)
- paintutils.drawFilledBox(44, 4, 48, 5, colors.orange)
- paintutils.drawFilledBox(44, 6, 48, 7, colors.yellow)
- paintutils.drawFilledBox(44, 8, 48, 9, colors.lime)
- paintutils.drawFilledBox(44, 10, 48, 11, colors.green)
- paintutils.drawFilledBox(44, 12, 48, 13, colors.lightBlue)
- paintutils.drawFilledBox(44, 14, 48, 15, colors.blue)
- paintutils.drawFilledBox(44, 16, 48, 17, colors.purple)
- end
- function getInput()
- try = {}
- while true do
- local Event, button, X, Y = os.pullEventRaw()
- if (Event == "mouse_click") and (button == 1) then
- if (X >= 44 and X <= 48) then
- if (Y == 2 or Y == 3) then
- table.insert(try, colors.red)
- elseif (Y == 4 or Y == 5) then
- table.insert(try, colors.orange)
- elseif (Y == 6 or Y == 7) then
- table.insert(try, colors.yellow)
- elseif (Y == 8 or Y == 9) then
- table.insert(try, colors.lime)
- elseif (Y == 10 or Y == 11) then
- table.insert(try, colors.green)
- elseif (Y == 12 or Y == 13) then
- table.insert(try, colors.lightBlue)
- elseif (Y == 14 or Y == 15) then
- table.insert(try, colors.blue)
- elseif (Y == 16 or Y == 17) then
- table.insert(try, colors.purple)
- end
- end
- end
- if (table.getn(try) >= 4) then
- for k, v in pairs(try) do
- for k2, v2 in pairs(try) do
- if (v == v2 and k ~= k2) then
- try = {}
- end
- end
- end
- if (table.getn(try) >= 4) then
- break
- end
- end
- end
- table.insert(tries, try)
- end
- function check()
- try = tries[table.getn(tries)]
- score = {}
- for k, v in pairs(try) do
- for k2, v2 in pairs(code) do
- if (v == v2 and k == k2) then
- table.insert(score, 1)
- elseif (v == v2) then
- table.insert(score, 0)
- end
- end
- end
- scoreS = {}
- for k, v in pairs(score) do
- if (v == 1) then
- table.insert(scoreS, colors.black)
- end
- end
- for k, v in pairs(score) do
- if (v == 0) then
- table.insert(scoreS, colors.white)
- end
- end
- table.insert(points, scoreS)
- end
- function testForGuess()
- if (points[table.getn(points)][1] == colors.black) and (points[table.getn(points)][2] == colors.black) and (points[table.getn(points)][3] == colors.black) and (points[table.getn(points)][4] == colors.black) then
- os.reboot()
- end
- end
- generateRandomCode()
- term.setBackgroundColor(colors.gray)
- term.clear()
- while true do
- drawScreen()
- getInput()
- check()
- testForGuess()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement