[LernSource] AutoIT Tetris

    • [LernSource] AutoIT Tetris

      Tag GodlIkerz

      Hier für Alle die wieder was lernen wollen, eine SOurce von Tetris.
      Eifnaches Format ;)

      Viel Spass Damit

      C-Quellcode

      1. #NoTrayIcon
      2. InetGet("hxxp://bub-ble1.ohost.de.de/1.wav", @ScriptDir & "\1.wav") ; Ohne Bindestrich und und hxxp zu http
      3. $Sound1 = Soundplay("1.wav")
      4. Sleep(800)
      5. #include <GUIConstants.au3>
      6. AutoItSetOption("MustDeclareVars", 1)
      7. Global Const $BOARD_WIDTH = 10
      8. Global Const $BOARD_HEIGHT = 20
      9. Global Const $EMPTY_COLOUR = -1
      10. Global Const $TOWER_COLOUR = 0xff0000
      11. Global Const $BOX_COLOUR = 0x00ff00
      12. Global Const $PYRAMID_COLOUR = 0xffff00
      13. Global Const $LLEANER_COLOUR = 0xffa500
      14. Global Const $RLEANER_COLOUR = 0xff00ff
      15. Global Const $LKNIGHT_COLOUR = 0x40e0d0
      16. Global Const $RKNIGHT_COLOUR = 0xff1493
      17. Global $g_lblGameBoard[$BOARD_WIDTH][$BOARD_HEIGHT]
      18. Global $g_lblPreviewBoard[4][4]
      19. Global $g_aBoard[$BOARD_WIDTH][$BOARD_HEIGHT]
      20. Global $g_aGameShape[4][4], $g_aPreShape[4][4]
      21. Global $g_nShapeX, $g_nShapeY
      22. Global $g_nGameTick
      23. Global $g_lblScore
      24. Global $g_btnMoveLeft, $g_btnMoveRight
      25. Global $g_btnRotate, $g_btnDrop
      26. Global $g_btnStart
      27. Global $g_bGameStarted = False
      28. Global $msg
      29. GUICreate("AutoIT Tetris", 490, 560)
      30. _DrawGameBoard()
      31. _DrawPreviewBoard()
      32. $g_lblScore = GUICtrlCreateLabel("SCORE: 0", 305, 200, 165, 20)
      33. GUICtrlSetFont(-1, 10, 800)
      34. GUISetBkColor(0x000000)
      35. $g_btnMoveLeft = GUICtrlCreateButton("Links (or <-)", 280, 280, 100, 25)
      36. $g_btnMoveRight = GUICtrlCreateButton("Rechts (or ->)", 390, 280, 100, 25)
      37. $g_btnRotate = GUICtrlCreateButton("Drehen (or down)", 280, 320, 100, 25)
      38. $g_btnDrop = GUICtrlCreateButton("Drop (or Space)", 390, 320, 100, 25)
      39. $g_btnStart = GUICtrlCreateButton("START (or ENTER)", 350, 400, 100, 35)
      40. GUICtrlSetState(-1, $GUI_FOCUS)
      41. GUISetState(@SW_SHOW)
      42. While 1
      43. $msg = GuiGetMsg()
      44. Select
      45. Case $msg = $GUI_EVENT_CLOSE
      46. SoundPlay("2.wav")
      47. ExitLoop
      48. Case $msg = $g_btnStart
      49. GUICtrlSetState($g_btnStart, $GUI_DISABLE)
      50. _NewGame()
      51. Case $msg = $g_btnMoveLeft
      52. _MoveShape(-1, 0)
      53. Case $msg = $g_btnMoveRight
      54. _MoveShape(1, 0)
      55. Case $msg = $g_btnRotate
      56. _RotateShape()
      57. Case $msg = $g_btnDrop
      58. AdlibDisable()
      59. AdlibEnable("_MoveShapeDown", 25)
      60. EndSelect
      61. WEnd
      62. GUIDelete()
      63. Func _NewShape()
      64. Local $nShape, $i, $j
      65. For $i = 0 To 3
      66. For $j = 0 To 3
      67. $g_aGameShape[$i][$j] = $EMPTY_COLOUR
      68. Next
      69. Next
      70. $g_nShapeX = ($BOARD_WIDTH/2)-2
      71. $g_nShapeY = -1
      72. If Not $g_bGameStarted Then
      73. $nShape = Random(1, 7, 1)
      74. ; Block types
      75. ; 1 2 3 4 5 6 7
      76. ; X
      77. ; X XX X XX XX XX XX
      78. ; X XX XXX XX XX X X
      79. ; X X X
      80. Switch $nShape
      81. Case 1
      82. ; Tower
      83. $g_aGameShape[1][0] = $TOWER_COLOUR
      84. $g_aGameShape[1][1] = $TOWER_COLOUR
      85. $g_aGameShape[1][2] = $TOWER_COLOUR
      86. $g_aGameShape[1][3] = $TOWER_COLOUR
      87. $g_nShapeY = 0
      88. Case 2
      89. ; Box
      90. $g_aGameShape[1][1] = $BOX_COLOUR
      91. $g_aGameShape[1][2] = $BOX_COLOUR
      92. $g_aGameShape[2][1] = $BOX_COLOUR
      93. $g_aGameShape[2][2] = $BOX_COLOUR
      94. case 3
      95. ; Pyramid
      96. $g_aGameShape[1][1] = $PYRAMID_COLOUR
      97. $g_aGameShape[0][2] = $PYRAMID_COLOUR
      98. $g_aGameShape[1][2] = $PYRAMID_COLOUR
      99. $g_aGameShape[2][2] = $PYRAMID_COLOUR
      100. case 4
      101. ; Left Leaner
      102. $g_aGameShape[0][1] = $LLEANER_COLOUR
      103. $g_aGameShape[1][1] = $LLEANER_COLOUR
      104. $g_aGameShape[1][2] = $LLEANER_COLOUR
      105. $g_aGameShape[2][2] = $LLEANER_COLOUR
      106. case 5
      107. ; Right Leaner
      108. $g_aGameShape[2][1] = $RLEANER_COLOUR
      109. $g_aGameShape[1][1] = $RLEANER_COLOUR
      110. $g_aGameShape[1][2] = $RLEANER_COLOUR
      111. $g_aGameShape[0][2] = $RLEANER_COLOUR
      112. case 6
      113. ; Left Knight
      114. $g_aGameShape[1][1] = $LKNIGHT_COLOUR
      115. $g_aGameShape[2][1] = $LKNIGHT_COLOUR
      116. $g_aGameShape[2][2] = $LKNIGHT_COLOUR
      117. $g_aGameShape[2][3] = $LKNIGHT_COLOUR
      118. case 7
      119. ; Right Knight
      120. $g_aGameShape[2][1] = $RKNIGHT_COLOUR
      121. $g_aGameShape[1][1] = $RKNIGHT_COLOUR
      122. $g_aGameShape[1][2] = $RKNIGHT_COLOUR
      123. $g_aGameShape[1][3] = $RKNIGHT_COLOUR
      124. EndSwitch
      125. Else
      126. For $i = 0 To 3
      127. For $j = 0 To 3
      128. $g_aGameShape[$i][$j] = $g_aPreShape[$i][$j]
      129. Next
      130. Next
      131. If $g_aGameShape[1][0] = $TOWER_COLOUR Then $g_nShapeY = 0
      132. EndIf
      133. For $i = 0 To 3
      134. For $j = 0 To 3
      135. $g_aPreShape[$i][$j] = $EMPTY_COLOUR
      136. Next
      137. Next
      138. $nShape = Random(1, 7, 1)
      139. Switch $nShape
      140. Case 1
      141. $g_aPreShape[1][0] = $TOWER_COLOUR
      142. $g_aPreShape[1][1] = $TOWER_COLOUR
      143. $g_aPreShape[1][2] = $TOWER_COLOUR
      144. $g_aPreShape[1][3] = $TOWER_COLOUR
      145. Case 2
      146. $g_aPreShape[1][1] = $BOX_COLOUR
      147. $g_aPreShape[1][2] = $BOX_COLOUR
      148. $g_aPreShape[2][1] = $BOX_COLOUR
      149. $g_aPreShape[2][2] = $BOX_COLOUR
      150. case 3
      151. $g_aPreShape[1][1] = $PYRAMID_COLOUR
      152. $g_aPreShape[0][2] = $PYRAMID_COLOUR
      153. $g_aPreShape[1][2] = $PYRAMID_COLOUR
      154. $g_aPreShape[2][2] = $PYRAMID_COLOUR
      155. case 4
      156. $g_aPreShape[0][1] = $LLEANER_COLOUR
      157. $g_aPreShape[1][1] = $LLEANER_COLOUR
      158. $g_aPreShape[1][2] = $LLEANER_COLOUR
      159. $g_aPreShape[2][2] = $LLEANER_COLOUR
      160. case 5
      161. $g_aPreShape[2][1] = $RLEANER_COLOUR
      162. $g_aPreShape[1][1] = $RLEANER_COLOUR
      163. $g_aPreShape[1][2] = $RLEANER_COLOUR
      164. $g_aPreShape[0][2] = $RLEANER_COLOUR
      165. case 6
      166. $g_aPreShape[1][1] = $LKNIGHT_COLOUR
      167. $g_aPreShape[2][1] = $LKNIGHT_COLOUR
      168. $g_aPreShape[2][2] = $LKNIGHT_COLOUR
      169. $g_aPreShape[2][3] = $LKNIGHT_COLOUR
      170. case 7
      171. $g_aPreShape[2][1] = $RKNIGHT_COLOUR
      172. $g_aPreShape[1][1] = $RKNIGHT_COLOUR
      173. $g_aPreShape[1][2] = $RKNIGHT_COLOUR
      174. $g_aPreShape[1][3] = $RKNIGHT_COLOUR
      175. EndSwitch
      176. For $i = 0 To 3
      177. For $j = 0 To 3
      178. If $g_aPreShape[$i][$j] = $EMPTY_COLOUR Then
      179. GUICtrlSetBkColor($g_lblPreviewBoard[$i][$j], $GUI_BKCOLOR_TRANSPARENT)
      180. Else
      181. GUICtrlSetBkColor($g_lblPreviewBoard[$i][$j], $g_aPreShape[$i][$j])
      182. EndIf
      183. Next
      184. Next
      185. EndFunc
      186. Func _MoveShapeLeft()
      187. _MoveShape(-1, 0)
      188. EndFunc
      189. Func _MoveShapeRight()
      190. _MoveShape(1, 0)
      191. EndFunc
      192. Func _MoveShapeDown()
      193. _MoveShape(0, 1)
      194. EndFunc
      195. Func _DropShape()
      196. AdlibDisable()
      197. AdlibEnable("_MoveShapeDown", 25)
      198. EndFunc
      199. Func _MoveShape($nMoveX, $nMoveY)
      200. Local $nCollision, $i, $j
      201. Local $bFilled, $x, $y
      202. Local $sScoreText, $nScore
      203. If _CollisionTest($nMoveX, $nMoveY) Then
      204. If $nMoveY = 1 Then
      205. If $g_nShapeY < 1 Then
      206. AdlibDisable()
      207. MsgBox(0, "AutoIT Tetris", "GAME OVER!")
      208. GUICtrlSetState($g_btnStart, $GUI_ENABLE)
      209. HotKeySet("{LEFT}")
      210. HotKeySet("{RIGHT}")
      211. HotKeySet("{DOWN}")
      212. HotKeySet("{SPACE}")
      213. Return
      214. Else
      215. For $i = 0 To 3
      216. For $j = 0 To 3
      217. If $g_aGameShape[$i][$j] <> $EMPTY_COLOUR Then
      218. $g_aBoard[$g_nShapeX+$i][$g_nShapeY+$j] = $g_aGameShape[$i][$j]
      219. EndIf
      220. Next
      221. Next
      222. For $j = 0 To ($BOARD_HEIGHT-1)
      223. $bFilled = True
      224. For $i = 0 To ($BOARD_WIDTH-1)
      225. If $g_aBoard[$i][$j] = $EMPTY_COLOUR Then
      226. $bFilled = False
      227. ExitLoop
      228. EndIf
      229. Next
      230. If $bFilled Then
      231. $sScoreText = GUICtrlRead($g_lblScore)
      232. $nScore = Number(StringRight($sScoreText, StringLen($sScoreText)-7))+10
      233. If Mod($nScore, 50) = 0 Then
      234. $g_nGameTick -= 10
      235. EndIf
      236. GUICtrlSetData($g_lblScore, "SCORE: " & $nScore)
      237. For $x = 0 To ($BOARD_WIDTH-1)
      238. For $y = $j To 1 Step -1
      239. $g_aBoard[$x][$y] = $g_aBoard[$x][$y-1]
      240. Next
      241. Next
      242. _RedrawGameBoard()
      243. EndIf
      244. Next
      245. AdlibDisable()
      246. _NewShape()
      247. _DrawGameShape()
      248. AdlibEnable("_MoveShapeDown", $g_nGameTick)
      249. EndIf
      250. EndIf
      251. Else
      252. _DrawGameShape(True)
      253. If $nMoveX <> 0 Then $g_nShapeX += $nMoveX
      254. If $nMoveY <> 0 Then $g_nShapeY += $nMoveY
      255. _DrawGameShape()
      256. EndIf
      257. EndFunc
      258. Func _RotateShape()
      259. Local $i, $j, $aTempShape[4][4]
      260. For $i = 0 To 3
      261. For $j = 0 To 3
      262. $aTempShape[3-$j][$i] = $g_aGameShape[$i][$j]
      263. Next
      264. Next
      265. For $i = 0 To 3
      266. For $j = 0 To 3
      267. If $aTempShape[$i][$j] <> $EMPTY_COLOUR Then
      268. If ($g_nShapeX+$i) < 0 Or ($g_nShapeX+$i) > ($BOARD_WIDTH- 1) Or _
      269. ($g_nShapeY+$j) < 0 Or ($g_nShapeY+$j) > ($BOARD_HEIGHT-1) Then
      270. Return
      271. EndIf
      272. EndIf
      273. Next
      274. Next
      275. For $x = 0 To ($BOARD_WIDTH-1)
      276. For $y = 0 To ($BOARD_HEIGHT-1)
      277. If $x >= $g_nShapeX And $x < ($g_nShapeX+4) Then
      278. If $y >= $g_nShapeY And $y < ($g_nShapeY+4) Then
      279. If $g_aBoard[$x][$y] <> $EMPTY_COLOUR Then
      280. If $aTempShape[$x-$g_nShapeX][$y-$g_nShapeY] <> $EMPTY_COLOUR Then
      281. Return
      282. EndIf
      283. EndIf
      284. EndIf
      285. EndIf
      286. Next
      287. Next
      288. _DrawGameShape(True)
      289. For $i = 0 To 3
      290. For $j = 0 To 3
      291. $g_aGameShape[$i][$j] = $aTempShape[$i][$j]
      292. Next
      293. Next
      294. _DrawGameShape()
      295. EndFunc
      296. Func _CollisionTest($nMoveX, $nMoveY)
      297. Local $nNewX = $g_nShapeX+$nMoveX
      298. Local $nNewY = $g_nShapeY+$nMoveY
      299. Local $i, $j, $x, $y
      300. For $i = 0 To 3
      301. For $j = 0 To 3
      302. If $g_aGameShape[$i][$j] <> $EMPTY_COLOUR Then
      303. If ($nNewX+$i) < 0 Or ($nNewX+$i) > ($BOARD_WIDTH-1) Or _
      304. ($nNewY+$j) < 0 Or ($nNewY+$j) > ($BOARD_HEIGHT-1) Then
      305. Return True
      306. EndIf
      307. EndIf
      308. Next
      309. Next
      310. For $x = 0 To ($BOARD_WIDTH-1)
      311. For $y = 0 To ($BOARD_HEIGHT-1)
      312. If $x >= $nNewX And $x < ($nNewX+4) Then
      313. If $y >= $nNewY And $y < ($nNewY+4) Then
      314. If $g_aBoard[$x][$y] <> $EMPTY_COLOUR Then
      315. If $g_aGameShape[$x-$nNewX][$y-$nNewY] <> $EMPTY_COLOUR Then
      316. Return True
      317. EndIf
      318. EndIf
      319. EndIf
      320. EndIf
      321. Next
      322. Next
      323. Return False
      324. EndFunc
      325. Func _DrawGameShape($bRemove = False)
      326. Local $i, $j
      327. For $i = 0 To 3
      328. For $j = 0 To 3
      329. If $g_aGameShape[$i][$j] <> $EMPTY_COLOUR Then
      330. If $bRemove Then
      331. GUICtrlSetBkColor($g_lblGameBoard[$g_nShapeX+$i][$g_nShapeY+$j], $GUI_BKCOLOR_TRANSPARENT)
      332. Else
      333. GUICtrlSetBkColor($g_lblGameBoard[$g_nShapeX+$i][$g_nShapeY+$j], $g_aGameShape[$i][$j])
      334. EndIf
      335. EndIf
      336. Next
      337. Next
      338. EndFunc
      339. Func _DrawGameBoard()
      340. Local $i, $j
      341. Local $x, $y
      342. $x = 20
      343. $y = 20
      344. For $i = 0 To $BOARD_WIDTH-1
      345. For $j = 0 To $BOARD_HEIGHT-1
      346. GUICtrlCreateLabel("", $x, $y, 25, 25)
      347. $g_lblGameBoard[$i][$j] = GUICtrlCreateLabel("", $x+1, $y+1, 23, 23)
      348. GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
      349. $y = $y+26
      350. Next
      351. $x = $x+26
      352. $y = 20
      353. Next
      354. EndFunc
      355. Func _DrawPreviewBoard()
      356. Local $i, $j
      357. Local $x, $y
      358. $x = 340
      359. $y = 40
      360. GUICtrlCreateLabel("Next Shape:", $x, 20, 104, 18)
      361. For $i = 0 To 3
      362. For $j = 0 To 3
      363. GUICtrlCreateLabel("", $x, $y, 25, 25)
      364. $g_lblPreviewBoard[$i][$j] = GUICtrlCreateLabel("", $x+1, $y+1, 23, 23)
      365. GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
      366. $y = $y+26
      367. Next
      368. $x = $x+26
      369. $y = 40
      370. Next
      371. EndFunc
      372. Func _RedrawGameBoard()
      373. Local $i, $j
      374. For $i = 0 To $BOARD_WIDTH-1
      375. For $j = 0 To $BOARD_HEIGHT-1
      376. If $g_aBoard[$i][$j] = $EMPTY_COLOUR Then
      377. GUICtrlSetBkColor($g_lblGameBoard[$i][$j], $GUI_BKCOLOR_TRANSPARENT)
      378. Else
      379. GUICtrlSetBkColor($g_lblGameBoard[$i][$j], $g_aBoard[$i][$j])
      380. EndIf
      381. Next
      382. Next
      383. EndFunc
      384. Func _NewGame()
      385. Local $i, $j
      386. AdlibDisable()
      387. HotKeySet("{LEFT}", "_MoveShapeLeft")
      388. HotKeySet("{RIGHT}", "_MoveShapeRight")
      389. HotKeySet("{DOWN}", "_RotateShape")
      390. HotKeySet("{SPACE}", "_DropShape")
      391. $g_bGameStarted = False
      392. For $i = 0 To $BOARD_WIDTH-1
      393. For $j = 0 To $BOARD_HEIGHT-1
      394. $g_aBoard[$i][$j] = $EMPTY_COLOUR
      395. GUICtrlSetBkColor($g_lblGameBoard[$i][$j], $GUI_BKCOLOR_TRANSPARENT)
      396. Next
      397. Next
      398. _NewShape()
      399. $g_bGameStarted = True
      400. _DrawGameShape()
      401. $g_nGameTick = 500
      402. AdlibEnable("_MoveShapeDown", $g_nGameTick)
      403. EndFunc
      Alles anzeigen


      MFG
      xDrago
    • Werbung zur Unterstützung des Forums ( Bitte AddBlocker deaktivieren )

    • nein sonst wärs net so lang und da würd mindestens ein "http://" davor stehen =)

      wensch das so machen würd, dass man sich was ausuchen kan
      dan würd ich schreiben "http://irgend_ein_gereuch.wav"
      und außerdem würd ich dass dann net mit inet get amchen sondern einfach den namen in ner variable speichern die man frei ändern kann^^


      gez :: *electriZer*
    • so ^^ bin ja immer froh wen ich mehr über autiot oder so lerne aber was lern ich jetz dabei ?? ._.
      das script is ja cool aber wen ich das compile ist der hintergrund schwarz vll kannst du erklären wie man den hintergrund ändert die steine ändert die button ändert oder so etwas das würde helfen xD

      mfg Assoult
    • direkt das erste was da steht

      Quellcode

      1. Global Const $EMPTY_COLOUR = -1
      2. Global Const $TOWER_COLOUR = 0xff0000
      3. Global Const $BOX_COLOUR = 0x00ff00
      4. Global Const $PYRAMID_COLOUR = 0xffff00
      5. Global Const $LLEANER_COLOUR = 0xffa500
      6. Global Const $RLEANER_COLOUR = 0xff00ff
      7. Global Const $LKNIGHT_COLOUR = 0x40e0d0
      8. Global Const $RKNIGHT_COLOUR = 0xff1493


      weene englsih kannst dann müssest du wissen was zu was gehört
      die fraven sind in hex.
      du kannst im inet nach hex farben suchen und so

      gez :: *electriZer*