Advertisement
pepeknamornik

postreh

Jun 16th, 2022 (edited)
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. w,h = term.getSize()
  2. term.setBackgroundColor(colors.black)
  3. term.setTextColor(colors.gray)
  4.  
  5.  
  6. local x = 0;
  7. local y = 0;
  8. local x0 = 0;
  9. local y0 = 1;
  10. local time1 = os.date("%S")
  11. local time2 = 0
  12.  
  13.  
  14. function generator()
  15. term.setCursorPos(1,5)
  16.  
  17. for i =1,x do
  18. term.setCursorPos(i+1,5)
  19. write"-"
  20. end
  21.  
  22. y0 = math.random(1, y)
  23. x0 = math.random(1, x)
  24.  
  25. for i =1,y do
  26.     for o =1,x do
  27.     term.setCursorPos(o+1,i+5)
  28.     write"O"
  29.     end
  30. end
  31.  
  32. term.setCursorPos(x0+1,y0+5)
  33. write"0"
  34.  
  35. for i =1,x do
  36. term.setCursorPos(i+1,y+6)
  37. write"-"
  38. end
  39.  
  40.  
  41. term.setCursorPos(1, y+8)
  42. time1 = os.date("%S")
  43.  
  44.      while true do
  45.    
  46.         local event, button, xv, yv = os.pullEvent()
  47.        
  48.         if event == "key" and button == keys.q then
  49.         term.clear()
  50.         term.setCursorPos(1,1)
  51.         error()
  52.         end
  53.        
  54.         if event == "mouse_click" and button == 1 and x>1 then
  55.         term.setCursorPos(1, h-5)
  56.         yvv = yv-5
  57.         write("x:"..xv)
  58.         print(", y:"..yvv)
  59.         write("x0:"..x0)
  60.         print(", y0:"..y0)
  61.        
  62.         end
  63.        
  64. term.setCursorPos(1, h-4)
  65.        
  66.         if event == "mouse_click" and button == 1 and x > 1 and xv-1 == x0 and yv-5 == y0 then
  67.         term.setCursorPos(1, y+8)
  68.             print("uspech")
  69.             konec()
  70.         elseif event == "mouse_click" and button == 1 and x > 1 then
  71.             term.setTextColor(colors.red)
  72.             term.setCursorPos(xv,yv)
  73.             write"O"
  74.             term.setTextColor(colors.gray)
  75.             term.setCursorPos(1, y+8)
  76.             print"neuspech"
  77.             konec()
  78.         end
  79.     end
  80.  
  81. end
  82.  
  83. function konec()
  84. time2 = os.date("%S")
  85. cas = time2-time1
  86. if (cas <0) then cas = 60 + cas end
  87. term.setCursorPos(1, h-3)
  88. print("cas: "..cas.."s")
  89. print("Opakovat? [y/n]")
  90.  
  91. term.setTextColor(colors.green)
  92. term.setCursorPos(x0+1,y0+5)
  93. write"0"
  94. term.setTextColor(colors.gray)
  95.  
  96. term.setCursorPos(1, h-1)
  97.      while true do
  98.             local event, button, xv, yv = os.pullEvent()
  99.  
  100.             if event == "key" and (button == keys.enter or button == keys.y or button == keys.numEnter) then
  101.                 term.clear()
  102.                 sleep(0.5)
  103.                 generator()
  104.             elseif event == "key" and button == keys.n then
  105.                 error()
  106.         end
  107.     end
  108. end
  109.  
  110.  
  111. function zadani()
  112. term.clear()
  113. term.setCursorPos(2,2)
  114. write"Pocet sloupcu: "
  115. x = tonumber(read())
  116. if x == nil then x = 120 end
  117. term.setCursorPos(2,3)
  118. write"Pocet radku: "
  119. y = tonumber(read())
  120. if y == nil then y = 40 end
  121. generator()
  122. end
  123.  
  124. zadani()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement