Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Seq = {}
- local score = 0
- local function getColourOf(hex)
- local value = tonumber(hex, 16)
- if not value then return nil end
- value = math.pow(2,value)
- return value
- end
- local function drawPictureTable(image, xinit, yinit)
- for y=1,#image do
- for x=1,#image[y] do
- term.setCursorPos(xinit + x-1, yinit + y-1)
- local col = getColourOf(string.sub(image[y], x, x))
- if col ~= nil then
- term.setBackgroundColour(col)
- term.write(" ")
- end
- end
- end
- end
- local function drawGreen() drawPictureTable({"ffffffffffffffffffffffffff","f555555555555555555555555f","f555555555555555555555555f","f555555555555555555555555f","f555555555555555555555555f","f555555555555555555555ffff","f55555555555555555555ff","f5555555555555555555ff","f5555555555555555555f","fffffffffffffffffffff"},1,1) end
- local function drawGreen2() drawPictureTable({"ffffffffffffffffffffffffff","f888888888888588558888888f","f555555555555585588555555f","f888888888888885885588888f","f555555555555555855885555f","f888888888888888858855ffff","f55555555555555555855ff","f8888888888888888885ff","f5555555555555555555f","fffffffffffffffffffff"},1,1) end
- local function drawRed() drawPictureTable({"ffffffffffffffffffffffff","eeeeeeeeeeeeeeeeeeeeeeeef","eeeeeeeeeeeeeeeeeeeeeeeef","eeeeeeeeeeeeeeeeeeeeeeeef","eeeeeeeeeeeeeeeeeeeeeeeef","fffeeeeeeeeeeeeeeeeeeeeef"," ffeeeeeeeeeeeeeeeeeeeef"," ffeeeeeeeeeeeeeeeeeeef"," feeeeeeeeeeeeeeeeeeef"," fffffffffffffffffffff"},27,1) end
- local function drawRed2() drawPictureTable({"ffffffffffffffffffffffff","8888888ee88e888888888888f","eeeeee88ee8eeeeeeeeeeeeef","88888ee88e88888888888888f","eeee88ee8eeeeeeeeeeeeeeef","fffee88e8888888888888888f"," ffee8eeeeeeeeeeeeeeeeef"," ffe888888888888888888f"," feeeeeeeeeeeeeeeeeeef"," fffffffffffffffffffff"},27,1) end
- local function drawYellow() drawPictureTable({"f4444444444444444444f","f4444444444444444444ff","f44444444444444444444ff","f444444444444444444444ffff","f444444444444444444444444f","f444444444444444444444444f","f444444444444444444444444f","f444444444444444444444444f","ffffffffffffffffffffffffff"},1,11) end
- local function drawYellow2() drawPictureTable({"f4444444444444444444f","f8888888888888888884ff","f44444444444444444844ff","f888888888888888848844ffff","f444444444444444844884444f","f888888888888884884488888f","f444444444444484488444444f","f888888888888488448888888f","ffffffffffffffffffffffffff"},1,11) end
- local function drawBlue() drawPictureTable({" f3333333333333333333f"," ff3333333333333333333f"," ff33333333333333333333f","fff333333333333333333333f","333333333333333333333333f","333333333333333333333333f","333333333333333333333333f","333333333333333333333333f","fffffffffffffffffffffffff"},27,11) end
- local function drawBlue2() drawPictureTable({" f3333333333333333333f"," ff3888888888888888888f"," ff33833333333333333333f","fff338838888888888888888f","333388338333333333333333f","888883388388888888888888f","333333883383333333333333f","888888833883888888888888f","fffffffffffffffffffffffff"},27,11) end
- local function drawCenter() drawPictureTable({" 00000"," 0000000"," 000000000"," 000000000"," 000000000"," 0000000"," 00000"},19,7) end
- function getSelectedColor(x,y)
- if (x >= 2 and x <= 20 and y <= 9 and y >= 2) or (x == 21 and y <= 7 and y >= 2) or (x == 22 and y <= 6 and y >= 2) or (x >= 23 and x <= 25 and y <= 5 and y >= 2) then return 1 -- Green Section
- elseif (x >= 27 and x <= 29 and y <= 5 and y >= 2) or (x == 30 and y <= 6 and y >= 2) or (x == 31 and y <= 7 and y >= 2) or (x >= 32 and x <= 50 and y <= 9 and y >= 2) then return 2 -- Red Sections
- elseif (x >= 2 and x <= 20 and y <= 18 and y >= 11) or (x == 21 and y <= 18 and y >= 13) or (x == 22 and y <= 18 and y >= 14) or (x >= 23 and x <= 25 and y <= 18 and y >= 15) then return 3 -- Yellow Section
- elseif (x >= 27 and x <= 29 and y <= 18 and y >= 15) or (x == 30 and y <= 18 and y >= 14) or (x == 31 and y <= 18 and y >= 13) or (x >= 32 and x <= 50 and y <= 18 and y >= 11) then return 4 -- Blue Section
- elseif x == 51 and y == 1 then return 5
- else return 0 end
- end
- function LightColor(num)
- if num == 1 then
- sleep(.5)
- drawGreen2()
- sleep(.5)
- drawGreen()
- elseif num == 2 then
- sleep(.5)
- drawRed2()
- sleep(.5)
- drawRed()
- elseif num == 3 then
- sleep(.5)
- drawYellow2()
- sleep(.5)
- drawYellow()
- elseif num == 4 then
- sleep(.5)
- drawBlue2()
- sleep(.5)
- drawBlue()
- end
- end
- function playThrough()
- for i=1,#Seq do
- local num = Seq[i]
- LightColor(num)
- end
- end
- local function quit()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.yellow)
- term.clear()
- term.setCursorPos(1,1)
- error()
- end
- function PlayGame()
- while GameOver ~=true do
- x=1
- table.insert(Seq,math.random(1,4))
- score = #Seq-1
- drawCenter()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(27-(string.len("Wynik:")/2),9)
- print("Wynik:")
- term.setCursorPos(26,11)
- print(tostring(score))
- playThrough()
- while x <=#Seq do
- local event,p1,p2,p3 = os.pullEvent()
- if event == "mouse_click" then
- local result = getSelectedColor(p2,p3)
- if result == Seq[x] then x=x+1
- elseif result == 0 then
- elseif result == 5 then quit()
- else GameOver = true;break end
- end
- end
- end
- drawCenter()
- term.setCursorPos(27-(string.len("Wynik:")/2),12)
- print("Wynik:")
- term.setCursorPos(26,13)
- print(tostring(score))
- GameOver= false
- Seq = {}
- end
- drawGreen();drawRed();drawYellow();drawBlue();drawCenter()
- term.setCursorPos(51,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write("X")
- while true do
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.black)
- local w,h = term.getSize()
- term.setCursorPos((w/2)-2,h/2+1)
- print(" Graj! ")
- while true do
- local event,p1,p2,p3 = os.pullEvent()
- if event == "mouse_click" and p1 == 1 then
- if p2 >= (w/2)-2 and p2 <= (w/2)+4 and p3 == 10 then
- PlayGame()
- break
- elseif p2 == 51 and p3 == 1 then
- quit()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement