Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- w,h = term.getSize()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.gray)
- local x = 0;
- local y = 0;
- local x0 = 0;
- local y0 = 1;
- local time1 = os.date("%S")
- local time2 = 0
- function generator()
- term.setCursorPos(1,5)
- for i =1,x do
- term.setCursorPos(i+1,5)
- write"-"
- end
- y0 = math.random(1, y)
- x0 = math.random(1, x)
- for i =1,y do
- for o =1,x do
- term.setCursorPos(o+1,i+5)
- write"O"
- end
- end
- term.setCursorPos(x0+1,y0+5)
- write"0"
- for i =1,x do
- term.setCursorPos(i+1,y+6)
- write"-"
- end
- term.setCursorPos(1, y+8)
- time1 = os.date("%S")
- while true do
- local event, button, xv, yv = os.pullEvent()
- if event == "key" and button == keys.q then
- term.clear()
- term.setCursorPos(1,1)
- error()
- end
- if event == "mouse_click" and button == 1 and x>1 then
- term.setCursorPos(1, h-5)
- yvv = yv-5
- write("x:"..xv)
- print(", y:"..yvv)
- write("x0:"..x0)
- print(", y0:"..y0)
- end
- term.setCursorPos(1, h-4)
- if event == "mouse_click" and button == 1 and x > 1 and xv-1 == x0 and yv-5 == y0 then
- term.setCursorPos(1, y+8)
- print("uspech")
- konec()
- elseif event == "mouse_click" and button == 1 and x > 1 then
- term.setTextColor(colors.red)
- term.setCursorPos(xv,yv)
- write"O"
- term.setTextColor(colors.gray)
- term.setCursorPos(1, y+8)
- print"neuspech"
- konec()
- end
- end
- end
- function konec()
- time2 = os.date("%S")
- cas = time2-time1
- if (cas <0) then cas = 60 + cas end
- term.setCursorPos(1, h-3)
- print("cas: "..cas.."s")
- print("Opakovat? [y/n]")
- term.setTextColor(colors.green)
- term.setCursorPos(x0+1,y0+5)
- write"0"
- term.setTextColor(colors.gray)
- term.setCursorPos(1, h-1)
- while true do
- local event, button, xv, yv = os.pullEvent()
- if event == "key" and (button == keys.enter or button == keys.y or button == keys.numEnter) then
- term.clear()
- sleep(0.5)
- generator()
- elseif event == "key" and button == keys.n then
- error()
- end
- end
- end
- function zadani()
- term.clear()
- term.setCursorPos(2,2)
- write"Pocet sloupcu: "
- x = tonumber(read())
- if x == nil then x = 120 end
- term.setCursorPos(2,3)
- write"Pocet radku: "
- y = tonumber(read())
- if y == nil then y = 40 end
- generator()
- end
- zadani()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement