Legebatterie

Apps--Tetris

Jan 9th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.98 KB | None | 0 0
  1. ---------------------------------------------------------FUNKTIONEN-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2.  
  3. StoneI=function(x,y,spin,s)
  4. if s==true then c="lightBlue" else c="black" end
  5. if spin==1 or spin==3 then
  6. paintutils.drawBox(x,y-1,x,y+2,colors[c])
  7. end
  8. if spin==2 or spin==4 then
  9. paintutils.drawBox(x-2,y,x+1,y,colors[c])
  10. end
  11. end
  12.  
  13. StoneO=function(x,y,spin,s)
  14. if s==true then c="yellow" else c="black" end
  15. paintutils.drawBox(x,y,x+1,y+1,colors[c])
  16.  
  17. end
  18.  
  19. StoneT=function(x,y,spin,s)
  20. if s==true then c="purple" else c="black" end
  21. if spin==1 then
  22. paintutils.drawBox(x,y-1,x,y+1,colors[c])
  23. paintutils.drawPixel(x-1,y,colors[c])
  24. end
  25. if spin==2 then
  26. paintutils.drawBox(x-1,y,x+1,y,colors[c])
  27. paintutils.drawPixel(x,y-1,colors[c])
  28. end
  29. if spin==3 then
  30. paintutils.drawBox(x,y-1,x,y+1,colors[c])
  31. paintutils.drawPixel(x+1,y,colors[c])
  32. end
  33. if spin==4 then
  34. paintutils.drawBox(x-1,y,x+1,y,colors[c])
  35. paintutils.drawPixel(x,y+1,colors[c])
  36. end
  37. end
  38.  
  39. StoneL=function(x,y,spin,s)
  40. if s==true then c="orange" else c="black" end
  41. if spin==1 then
  42. paintutils.drawBox(x,y-1,x,y+1,colors[c])
  43. paintutils.drawPixel(x+1,y+1,colors[c])
  44. end
  45. if spin==2 then
  46. paintutils.drawBox(x,y-1,x,y+1,colors[c])
  47. paintutils.drawPixel(x-1,y-1,colors[c])
  48. end
  49. if spin==3 then
  50. paintutils.drawBox(x,y-1,x,y+1,colors[c])
  51. paintutils.drawPixel(x-1,y-1,colors[c])
  52. end
  53. if spin==4 then
  54. paintutils.drawBox(x-1,y,x+1,y,colors[c])
  55. paintutils.drawPixel(x+1,y-1,colors[c])
  56. end
  57. end
  58.  
  59. StoneJ=function(x,y,spin,s)
  60. if s==true then c="blue" else c="black" end
  61. if spin==1 then
  62. paintutils.drawBox(x,y-1,x,y+1,colors[c])
  63. paintutils.drawPixel(x-1,y+1,colors[c])
  64. end
  65. if spin==2 then
  66. paintutils.drawBox(x-1,y,x+1,y,colors[c])
  67. paintutils.drawPixel(x-1,y-1,colors[c])
  68. end
  69. if spin==3 then
  70. paintutils.drawBox(x,y-1,x,y+1,colors[c])
  71. paintutils.drawPixel(x+1,y-1,colors[c])
  72. end
  73. if spin==4 then
  74. paintutils.drawBox(x-1,y,x+1,y,colors[c])
  75. paintutils.drawPixel(x+1,y+1,colors[c])
  76. end
  77. end
  78.  
  79. StoneZ=function(x,y,spin,s)
  80. if s==true then c="red" else c="black" end
  81. if spin==1 or spin==3 then
  82. paintutils.drawBox(x-1,y,x,y,colors[c])
  83. paintutils.drawBox(x,y+1,x+1,y+1,colors[c])
  84. end
  85. if spin==2 or spin==4 then
  86. paintutils.drawBox(x,y-1,x,y,colors[c])
  87. paitnutils.drawBox(x-1,y,x-1,y+1,colors[c])
  88. end
  89. end
  90.  
  91. StoneS=function(x,y,spin,s)
  92. if s==true then c="lime" else c="black" end
  93. if spin==1 or spin==3 then
  94. paintutils.drawBox(x,y,x+1,y,colors[c])
  95. paintutils.drawBox(x-1,y+1,x,y+1,colors[c])
  96. end
  97. if spin==2 or spin==4 then
  98. paintutils.drawBox(x,y-1,x,y,colors[c])
  99. paintutils.drawBox(x+1,y,x+1,y+1,colors[c])
  100. end
  101. end
  102.  
  103.  
  104.  
  105.  
  106.  
  107. SpawnNewBlock=function()
  108. x=math.random(1,7)
  109. spin=math.random(1,4)
  110.  
  111. if x==1 then StoneI(43,5,spin,true) predictedBlock=StoneI end
  112. if x==2 then StoneO(43,5,spin,true) predictedBlock=StoneO end
  113. if x==3 then StoneT(43,5,spin,true) predictedBlock=StoneT end
  114. if x==4 then StoneL(43,5,spin,true) predictedBlock=StoneL end
  115. if x==5 then StoneJ(43,5,spin,true) predictedBlock=StoneJ end
  116. if x==6 then StoneZ(43,5,spin,true) predictedBlock=StoneZ end
  117. if x==7 then StoneS(43,5,spin,true) predictedBlock=StoneS end
  118. sleep(Diff)
  119. end
  120.  
  121. waitForInput=function()
  122. e,a=os.pullEvent("key")
  123. if e=="key" and a==16 then error() end --Q
  124. if e=="key" and a==19 then error() end --R
  125. if e=="key" and a==42 then end --SHIFT
  126. if e=="key" and a==58 then end --CAPSLOCK
  127. if e=="key" and a==31 then if not(spin==4) then spin=spin+1 else spin=1 end end --Spin
  128. if e=="key" and a==203 then x=x-1 end --LINKS
  129. if e=="key" and a==205 then x=x+1 end --RECHTS
  130. if e=="key" and a==2 then Diff=1.5 DiffCol="green" end --Diff1
  131. if e=="key" and a==3 then Diff=1 DiffCol="orange" end --Diff2
  132. if e=="key" and a==4 then Diff=0.8 DiffCol="red" end
  133.  
  134. end
  135.  
  136. waitForNoInput=function()
  137. while true do
  138. sleep(diff)
  139. y=y+1
  140. end
  141.  
  142.  
  143.  
  144. ---------------------------------------------------------FUNKTIONEN-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  145.  
  146. ----------------------------------------------------------VARIABLE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  147. DiffCol="orange"
  148. Diff=1
  149.  
  150. FixedBlocks={} O={} I={} L={} J={} T={} Z={} S={}
  151. -----------------------------------------------------------DESIGN-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  152.  
  153. term.setBackgroundColor(colors.lightGray)
  154. term.clear()
  155. paintutils.drawFilledBox(10,1,30,19,colors.black)
  156. paintutils.drawBox(10,1,30,19,colors.gray)
  157. paintutils.drawBox(11,1,29,19,colors.gray)
  158.  
  159.  
  160.  
  161. term.setBackgroundColor(colors.lightGray)
  162. term.setTextColor(colors.black)
  163. term.setCursorPos(33,15)
  164. write("Move: ARROWS")
  165. term.setCursorPos(33,17)
  166. write("Hold: CAPS LOCK")
  167. term.setCursorPos(33,18)
  168. write("Release: SHIFT")
  169. term.setCursorPos(33,16)
  170. write("Spin: S")
  171.  
  172. term.setTextColor(colors.blue)
  173. term.setCursorPos(32,1)
  174. write("Tetris by Maxintosh")
  175.  
  176. term.setTextColor(colors.black)
  177. term.setCursorPos(34,3)
  178. write("next: ")
  179. paintutils.drawFilledBox(40,3,46,8,colors.black)
  180.  
  181. term.setCursorPos(33,11)
  182. term.setTextColor(colors[DiffCol])
  183. term.setBackgroundColor(colors.lightGray)
  184. write("Difficulty:")
  185. paintutils.drawBox(46,11,47,11,colors.green)
  186. paintutils.drawBox(48,11,49,11,colors.orange)
  187. paintutils.drawBox(50,11,51,11,colors.red)
  188.  
  189. term.setTextColor(colors.black)
  190. term.setBackgroundColor(colors.lightGray)
  191. term.setCursorPos(3,4)
  192. write("hold")
  193. paintutils.drawFilledBox(2,6,7,11,colors.black)
  194.  
  195. term.setTextColor(colors.red)
  196. term.setBackgroundColor(colors.lightGray)
  197. term.setCursorPos(2,16)
  198. write("Quit:Q")
  199. term.setCursorPos(2,18)
  200. write("Redo:R")
  201.  
  202. SpawnNewBlock()
  203. -----------------------------------------------------------DESIGN-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  204. while true do
  205.  
  206. predictedBlock(19,2,spin,true)
  207. x=19
  208. y=2
  209. xOld=x
  210. yOld=y
  211. spinOld=spin
  212. ----------------------------------------------------------BLOCK FÄLLT---------------------------------------------------------------------
  213.  
  214. while y<17 do
  215.  
  216.  
  217. term.setCursorPos(33,11)
  218. term.setTextColor(colors[DiffCol])
  219. term.setBackgroundColor(colors.lightGray)
  220. write("Difficulty:")
  221.  
  222. predictedBlock(xOld,yOld,spinOld,false)
  223. xOld=x
  224. yOld=y
  225. spinOld=spin
  226. predictedBlock(x,y,spin,true)
  227.  
  228. parallel.waitForAny(waitForInput,waitForNoInput)
  229.  
  230. end
  231. paintutils.drawFilledBox(40,3,46,8,colors.black)
  232. SpawnNewBlock()
  233. end
Add Comment
Please, Sign In to add comment