Markus

Tetris

22 posts in this topic

#1 ·  Posted (edited)

Hi!

I hope you'll have much fun with this. I know that there are already existing a lot of tetris versions, but i thought, it would be nice to have one with AutoIt.

AutoIt owns!!!

Markus

EDIT: Codebox for AutoItKing^^

EDIT: 20/06/2006 (Tetris1.1)

- removed several bugs by changing the hotkeyfunctions (hotkeys now only change vars, that tells the script to move the item at a position in the script, where no bugs can be caused by moving it)

- added zedna's changes

EDIT: 21/06/2006 (Tetris1.11)

- Tetris now pauses automatically if Window is minimized/not activated, it will go on at once if its activated again

- If you press down arrow button for a very short time, the item will fall down "as a brick" --> its moved straight to the ground, if you press the button longer, the item will fall only faster as long as you press it and then will fall as slow as before.

The Script:

#compiler_icon=tetris.ico

#include <GUIConstants.au3>

#include <misc.au3>




_hotkey_enable()

HotKeySet("{PAUSE}","_pause")




Global $reserve_id[8][101]

Global $reserve_anzahl[8]




Global $vorschau_id[8][5]




Global $vorschau_background_id[5][5]




Global $current_id[5]

Global $current_x_pos[5]

Global $current_y_pos[5]




Global $temp_x_pos[5]

Global $temp_y_pos[5]




Global $current_colour

Global $current_lage=1




Global $lieing_id[21][11]

Global $lieing_colour[21][11]




Global $feld_status[21][11]




For $i=1 To 20

For $s=1 To 10

$feld_status[$i][$s]=0

Next

Next




Global $teiler=500




Global $line_info_voll[21]




$line_info_voll[0]=0 ;[0] enthält die Angabe, wie viele voll sind









Global $random




Global $points=0

Global $item=1

Global $level=1




Global $pause=0




Global $move_right=0

Global $move_left=0

Global $move_rotate=0

;Global $move_let_fall=0




Global $pressed=0

Global $pressedtimer=0




Global $started_by_minimize=0




SplashTextOn("Tetris",@crlf & "Loading GUI..." & @crlf & @crlf & "...please be patient!",200,100)




$main_gui=GUICreate("Tetris (by M.Braun)",425,540)

GUISetBkColor(0x000000)

GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",18,18,2,504)

GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",270,18,2,504)

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",20,18,250,2)

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",20,520,250,2)




GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",288,18,2,124)

GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",410,18,2,124)

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,18,120,2)

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,140,120,2)




GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",288,163,2,109) ; 288,163,2,99

GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",410,163,2,109) ; 410,163,2,99

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,163,120,2)

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,270,120,2) ; 290,260,120,2




GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",288,293,2,49)

GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",410,293,2,49)

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,293,120,2)

GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,340,120,2)




$label_points=GUICtrlCreateLabel("Your Points:" & @CRLF & $points,300,175,100,90) ; 300,175,100,75

GUICtrlSetFont(-1,18)

GUICtrlSetColor(-1,0x00FF00)




$label_level=GUICtrlCreateLabel("Level: " & $level ,300,305,100,25)

GUICtrlSetFont(-1,18)

GUICtrlSetColor(-1,0x00FF00)




$label_pause=GUICtrlCreateLabel("PAUSED",300,450,100,25)

GUICtrlSetFont(-1,18)

GUICtrlSetColor(-1,0x00FF00)

GUICtrlSetState(-1,$GUI_HIDE)




$reserve_anzahl[1]=100

$reserve_anzahl[2]=100

$reserve_anzahl[3]=100

$reserve_anzahl[4]=100

$reserve_anzahl[5]=100

$reserve_anzahl[6]=100

$reserve_anzahl[7]=100




For $i=1 To 100

$reserve_id[1][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_red.bmp",-99,-99,25,25)

$reserve_id[2][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_green.bmp",-99,-99,25,25)

$reserve_id[3][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_yellow.bmp",-99,-99,25,25)

$reserve_id[4][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_blue.bmp",-99,-99,25,25)

$reserve_id[5][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_orange.bmp",-99,-99,25,25)

$reserve_id[6][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_pink.bmp",-99,-99,25,25)

$reserve_id[7][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_teal.bmp",-99,-99,25,25)

Next




For $i=1 To 4

$vorschau_id[1][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_red.bmp",-99,-99,25,25)

$vorschau_id[2][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_green.bmp",-99,-99,25,25)

$vorschau_id[3][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_yellow.bmp",-99,-99,25,25)

$vorschau_id[4][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_blue.bmp",-99,-99,25,25)

$vorschau_id[5][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_orange.bmp",-99,-99,25,25)

$vorschau_id[6][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_pink.bmp",-99,-99,25,25)

$vorschau_id[7][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_teal.bmp",-99,-99,25,25)

Next




For $i=1 To 4

For $s=1 To 4

$vorschau_background_id[$i][$s]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_grey.bmp",($i-1)*25+300,($s-1)*25+30,25,25)

Next

Next

$random=Random(1,7,1)

_new_item()

SplashOff()




GUISetState()




$timer=TimerInit()







While 1

_msg()




If $move_right=1 Then

_move_right()

$move_right=0

EndIf



If $move_left=1 Then

_move_left()

$move_left=0

EndIf



If $move_rotate=1 Then

_rotate()

$move_rotate=0

EndIf



#cs



If $move_let_fall=1 Then

_let_it_fall_to_ground()

$move_let_fall=0

EndIf



#ce



If $pressed=1 Then

If _IsPressed(28)=0 Then

$pressed=0

;MsgBox(0,TimerDiff($pressedtimer),"")

If TimerDiff($pressedtimer)<150 Then _let_it_fall_to_ground()

EndIf



EndIf















$timer_dif=TimerDiff($timer)

If _IsPressed(28) Then

If $pressed=0 Then

$pressedtimer=TimerInit()

$pressed=1

EndIf



If $timer_dif/30>1 Then

_let_it_fall()

$timer=TimerInit()

EndIf



ElseIf $timer_dif/$teiler>1 Then

_let_it_fall()

$timer=TimerInit()

EndIf



WEnd



Func _pause()

If $pause=0 Then

_hotkey_disable()

GUICtrlSetState($label_pause,$GUI_SHOW)

$pause=1

While 1

If $started_by_minimize=1 Then

If WinActive($main_gui)=1 Then _pause()

EndIf



If $pause=0 Then ExitLoop





_msg()

WEnd

Else

_hotkey_enable()

GUICtrlSetState($label_pause,$GUI_HIDE)

$started_by_minimize=0

$pause=0

EndIf

EndFunc

Func _msg()

$msg=GUIGetMsg()

If $msg=$GUI_EVENT_CLOSE Then Exit

EndFunc

Func _hotkey_enable()

HotKeySet("{RIGHT}","_move_right_var")

HotKeySet("{LEFT}","_move_left_var")

HotKeySet("{UP}","_rotate_var")

;HotKeySet("{DOWN}","_let_it_fall_to_ground_var")

EndFunc

Func _hotkey_disable()

HotKeySet("{RIGHT}")

HotKeySet("{LEFT}")

HotKeySet("{UP}")

;HotKeySet("{DOWN}")

EndFunc

Func _move_right_var()

$move_right=1

EndFunc

Func _move_left_var()

$move_left=1

EndFunc

Func _rotate_var()

$move_rotate=1

EndFunc

#cs

Func _let_it_fall_to_ground_var()

$move_let_fall=1

EndFunc

#ce







Func _move_right()

If _check_free_space_to_right_side()=0 Then Return 0

For $i=1 To 4

$current_x_pos[$i]=$current_x_pos[$i]+1

Next

_move_current_item()

EndFunc

Func _check_free_space_to_right_side()

For $i=1 To 4

If $current_x_pos[$i]=10 Then

Return 0

ElseIf $feld_status[$current_y_pos[$i]][$current_x_pos[$i]+1]=1 Then

Return 0

EndIf

Next

Return 1

EndFunc

Func _move_left()

If _check_free_space_to_left_side()=0 Then Return 0

For $i=1 To 4

$current_x_pos[$i]=$current_x_pos[$i]-1

Next

_move_current_item()

EndFunc

Func _check_free_space_to_left_side()

For $i=1 To 4

If $current_x_pos[$i]=1 Then

Return 0

ElseIf $feld_status[$current_y_pos[$i]][$current_x_pos[$i]-1]=1 Then

Return 0

EndIf

Next

Return 1

EndFunc

Func _rotate()




$rotate_point_x_cord=$current_x_pos[2]

$rotate_point_y_cord=$current_y_pos[2]




For $i=1 To 4

$temp_x_pos[$i]=$rotate_point_x_cord-($current_y_pos[$i]-$rotate_point_y_cord)

$temp_y_pos[$i]=$rotate_point_y_cord+($current_x_pos[$i]-$rotate_point_x_cord)

If $temp_x_pos[$i]<1 Or $temp_x_pos[$i]>10 Or $temp_y_pos[$i]<1 Or $temp_y_pos[$i]>20 Then Return 0

If $feld_status[$temp_y_pos[$i]][$temp_x_pos[$i]]=1 Then Return 0

Next

For $i= 1 To 4

$current_x_pos[$i]=$temp_x_pos[$i]

$current_y_pos[$i]=$temp_y_pos[$i]

Next

_move_current_item()

EndFunc

Func _let_it_fall()

_check_free_space()

For $i=1 To 4

$current_y_pos[$i]=$current_y_pos[$i]+1

Next

_move_current_item()

If WinActive($main_gui)=0 Then

$started_by_minimize=1

_pause()

EndIf

EndFunc

Func _let_it_fall_to_ground()

While 1

If _check_free_space()=1 Then ExitLoop

For $i=1 To 4

$current_y_pos[$i]=$current_y_pos[$i]+1

Next

WEnd

EndFunc

Func _move_current_item()

For $i=1 To 4

$x_pos=($current_x_pos[$i]-1)*25+20

$y_pos=($current_y_pos[$i]-1)*25+20

GUICtrlSetPos($current_id[$i],$x_pos,$y_pos)

Next

EndFunc

#cs

Func _check_free_space_without_stop()

For $i=1 To 4

If $current_y_pos[$i]=20 Then

_move_current_item()

$timer=TimerInit()

Return 1

ElseIf $feld_status[$current_y_pos[$i]+1][$current_x_pos[$i]]=1 Then

_move_current_item()

$timer=TimerInit()

Return 1

EndIf

Next

EndFunc

#ce

Func _check_free_space()

For $i=1 To 4

If $current_y_pos[$i]=20 Then

_stop_fall()

Return 1

ElseIf $feld_status[$current_y_pos[$i]+1][$current_x_pos[$i]]=1 Then

_stop_fall()

Return 1

EndIf

Next

EndFunc

Func _stop_fall()

_hotkey_disable()

_move_current_item()

For $i=1 To 4

If $current_y_pos[$i]<3 Then

_game_over()

Return 0

EndIf

Next

$item=$item+1

If $level<15 Then

If $item/10=$level Then

$level=$level+1

GUICtrlSetData($label_level,"Level: " & $level)

If $level=2 Then $teiler=500

If $level=3 Then $teiler=450

If $level=4 Then $teiler=400

If $level=5 Then $teiler=350

If $level=6 Then $teiler=330

If $level=7 Then $teiler=300

If $level=8 Then $teiler=270

If $level=9 Then $teiler=240

If $level=10 Then $teiler=210

If $level=10 Then $teiler=190

If $level=11 Then $teiler=170

If $level=12 Then $teiler=150

If $level=13 Then $teiler=130

If $level=14 Then $teiler=120

If $level=15 Then $teiler=110

EndIf

EndIf

For $i=1 To 4

$feld_status[$current_y_pos[$i]][$current_x_pos[$i]]=1

$lieing_id[$current_y_pos[$i]][$current_x_pos[$i]]=$current_id[$i]

$lieing_colour[$current_y_pos[$i]][$current_x_pos[$i]]=$current_colour

Next

_line_check()

_new_item()

_hotkey_enable()

EndFunc

Func _line_check()

$line_info_voll[0]=0

For $i=1 To 20

$line_voll=1

For $s=1 To 10

If $feld_status[$i][$s]=0 Then

$line_voll=0

ExitLoop

EndIf

Next

If $line_voll=1 Then

$line_info_voll[0]=$line_info_voll[0]+1

$line_info_voll[$line_info_voll[0]]=$i

EndIf

Next

If $line_info_voll[0]>0 Then

If $line_info_voll[0]=1 Then $points=$points+25

If $line_info_voll[0]=2 Then $points=$points+50

If $line_info_voll[0]=3 Then $points=$points+100

If $line_info_voll[0]=4 Then $points=$points+200

GUICtrlSetData($label_points,"Your Points:" & @CRLF & $points)

For $i=1 To $line_info_voll[0]

For $s=1 To 10

GUICtrlSetPos($lieing_id[$line_info_voll[$i]][$s],-99,-99)

$feld_status[$line_info_voll[$i]][$s]=0

$colour=$lieing_colour[$line_info_voll[$i]][$s]

$reserve_anzahl[$colour]=$reserve_anzahl[$colour]+1

$reserve_id[$colour][$reserve_anzahl[$colour]]=$lieing_id[$line_info_voll[$i]][$s]

Next

_lines_nach_rutschen($line_info_voll[$i])

Next

Endif







EndFunc

Func _lines_nach_rutschen($ab_line)

For $i=$ab_line-1 To 1 Step -1

For $s=1 To 10

If $feld_status[$i][$s]=1 Then

;MsgBox(0,$i & $s,"")

$feld_status[$i][$s]=0

$feld_status[$i+1][$s]=1

GUICtrlSetPos($lieing_id[$i][$s],($s-1)*25+20,($i)*25+20)

$lieing_id[$i+1][$s]=$lieing_id[$i][$s]

$lieing_colour[$i+1][$s]=$lieing_colour[$i][$s]

EndIf

Next

Next

EndFunc

Func _new_item()

If $random=1 Then

$current_colour=1

$current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]]

$current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1]

$current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2]

$current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3]

$current_x_pos[1]=5

$current_x_pos[2]=6

$current_x_pos[3]=5

$current_x_pos[4]=6

$current_y_pos[1]=2

$current_y_pos[2]=2

$current_y_pos[3]=1

$current_y_pos[4]=1

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4

EndIf

If $random=2 Then

$current_colour=2

$current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]]

$current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1]

$current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2]

$current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3]

$current_x_pos[1]=5

$current_x_pos[2]=5

$current_x_pos[3]=5

$current_x_pos[4]=5

$current_y_pos[1]=1

$current_y_pos[2]=2

$current_y_pos[3]=3

$current_y_pos[4]=4

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4

EndIf

If $random=3 Then

$current_colour=3

$current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]]

$current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1]

$current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2]

$current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3]

$current_x_pos[1]=5

$current_x_pos[2]=5

$current_x_pos[3]=5

$current_x_pos[4]=4

$current_y_pos[1]=1

$current_y_pos[2]=2

$current_y_pos[3]=3

$current_y_pos[4]=3

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4

EndIf

If $random=4 Then

$current_colour=4

$current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]]

$current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1]

$current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2]

$current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3]

$current_x_pos[1]=5

$current_x_pos[2]=5

$current_x_pos[3]=5

$current_x_pos[4]=4

$current_y_pos[1]=1

$current_y_pos[2]=2

$current_y_pos[3]=3

$current_y_pos[4]=1

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4

EndIf

If $random=5 Then

$current_colour=5

$current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]]

$current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1]

$current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2]

$current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3]

$current_x_pos[1]=5

$current_x_pos[2]=5

$current_x_pos[3]=5

$current_x_pos[4]=4

$current_y_pos[1]=1

$current_y_pos[2]=2

$current_y_pos[3]=3

$current_y_pos[4]=2

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4

EndIf

If $random=6 Then

$current_colour=6

$current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]]

$current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1]

$current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2]

$current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3]

$current_x_pos[1]=5

$current_x_pos[2]=5

$current_x_pos[3]=6

$current_x_pos[4]=6

$current_y_pos[1]=1

$current_y_pos[2]=2

$current_y_pos[3]=2

$current_y_pos[4]=3

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4

EndIf

If $random=7 Then

$current_colour=7

$current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]]

$current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1]

$current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2]

$current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3]

$current_x_pos[1]=6

$current_x_pos[2]=6

$current_x_pos[3]=5

$current_x_pos[4]=5

$current_y_pos[1]=1

$current_y_pos[2]=2

$current_y_pos[3]=2

$current_y_pos[4]=3

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4

EndIf




$current_lage=1

_move_current_item()

_vorschau()

$timer=TimerInit()

EndFunc

Func _vorschau()

For $i=1 To 4

GUICtrlSetPos($vorschau_id[$current_colour][$i],-99,-99)

Next

For $i=1 To 4

For $s=1 To 4

GUICtrlSetPos($vorschau_background_id[$i][$s],($i-1)*25+300,($s-1)*25+30,25,25)

Next

Next




$random=Random(1,7,1)

If $random=1 Then

GUICtrlSetPos($vorschau_background_id[2][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][3],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][3],-99,-99)




GUICtrlSetPos($vorschau_id[1][1],1*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[1][2],2*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[1][3],1*25+300,2*25+30)

GUICtrlSetPos($vorschau_id[1][4],2*25+300,2*25+30)

EndIf

If $random=2 Then

GUICtrlSetPos($vorschau_background_id[2][1],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][3],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][4],-99,-99)




GUICtrlSetPos($vorschau_id[2][1],1*25+300,0*25+30)

GUICtrlSetPos($vorschau_id[2][2],1*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[2][3],1*25+300,2*25+30)

GUICtrlSetPos($vorschau_id[2][4],1*25+300,3*25+30)

EndIf

If $random=3 Then

GUICtrlSetPos($vorschau_background_id[3][1],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][3],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][3],-99,-99)




GUICtrlSetPos($vorschau_id[3][1],2*25+300,0*25+30)

GUICtrlSetPos($vorschau_id[3][2],2*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[3][3],2*25+300,2*25+30)

GUICtrlSetPos($vorschau_id[3][4],1*25+300,2*25+30)

EndIf

If $random=4 Then

GUICtrlSetPos($vorschau_background_id[3][1],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][3],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][1],-99,-99)




GUICtrlSetPos($vorschau_id[4][1],2*25+300,0*25+30)

GUICtrlSetPos($vorschau_id[4][2],2*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[4][3],2*25+300,2*25+30)

GUICtrlSetPos($vorschau_id[4][4],1*25+300,0*25+30)

EndIf

If $random=5 Then

GUICtrlSetPos($vorschau_background_id[3][1],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][3],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][2],-99,-99)




GUICtrlSetPos($vorschau_id[5][1],2*25+300,0*25+30)

GUICtrlSetPos($vorschau_id[5][2],2*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[5][3],2*25+300,2*25+30)

GUICtrlSetPos($vorschau_id[5][4],1*25+300,1*25+30)

EndIf

If $random=6 Then

GUICtrlSetPos($vorschau_background_id[2][1],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][3],-99,-99)




GUICtrlSetPos($vorschau_id[6][1],1*25+300,0*25+30)

GUICtrlSetPos($vorschau_id[6][2],1*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[6][3],2*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[6][4],2*25+300,2*25+30)

EndIf

If $random=7 Then

GUICtrlSetPos($vorschau_background_id[3][1],-99,-99)

GUICtrlSetPos($vorschau_background_id[3][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][2],-99,-99)

GUICtrlSetPos($vorschau_background_id[2][3],-99,-99)




GUICtrlSetPos($vorschau_id[7][1],2*25+300,0*25+30)

GUICtrlSetPos($vorschau_id[7][2],2*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[7][3],1*25+300,1*25+30)

GUICtrlSetPos($vorschau_id[7][4],1*25+300,2*25+30)

EndIf

EndFunc

Func _restart()

For $i=1 To 4

GUICtrlSetPos($current_id[$i],-99,-99)

$reserve_id[$current_colour][$reserve_anzahl[$current_colour]+$i]=$current_id[$i]




Next

$reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]+4




For $i=1 To 20

For $s=1 To 10

If $feld_status[$i][$s]=1 Then

GUICtrlSetPos($lieing_id[$i][$s],-99,-99)

$reserve_anzahl[$lieing_colour[$i][$s]]=$reserve_anzahl[$lieing_colour[$i][$s]]+1

$reserve_id[$lieing_colour[$i][$s]][$reserve_anzahl[$lieing_colour[$i][$s]]]=$lieing_id[$i][$s]

$feld_status[$i][$s]=0

EndIf

Next

Next

$points=0

$item=1

$level=1

$teiler=500




GUICtrlSetData($label_level,"Level: " & $level)

GUICtrlSetData($label_points,"Your Points:" & @CRLF & $points)

_new_item()

_hotkey_enable()

EndFunc

Func _game_over()

If MsgBox(4,"Game over","Do you want to restart?")=6 Then

_restart()

Else

Exit

EndIf

EndFunc

 Tetris.zip.8d0c5479a29d485ddcfc25ebf99034b4

 Tetris1.1.zip.7ea30ae74d32fb7e704881655b7e43fa

 Tetris1.11.zip.327332ac5fee9bde192ff811c0ca4338

Edited by Melba23
Reformatted code
1 person likes this

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites



i really love your scripts :D

(auch wenn ich Tetris machen wollte du sau :D )

Share this post


Link to post
Share on other sites

Well done! It works well.


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

Yes, real nice job, only 1 major problem... your game proved what I have always known ... I SUCK AT TETRIS! :D But my wife will enjoy thoroughly!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

When I press down it drops like a brick.

That's not how it was on the Gameboy. A bit too fast for my liking.

With that aside, it is a great script.

Share this post


Link to post
Share on other sites

Thank you for your great feedback so far!

When I press down it drops like a brick.

Hm, I'll make a settings menu for the next version, that both is possible.

(auch wenn ich Tetris machen wollte du sau)

*sorry* :D:D Aber nachdem ich 4gewinnt als online game geschrieben hatte, im deutschen forum gepostet hab und eine woche später im englischen forum gemerkt habe, dass ich auf einmal nicht mehr der erste damit auf autoitscript.com bin, hab ich gedacht, dass ichs diesmal sofort auch im englischen poste.


"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites

Very nice script I like it. :D

I corrected some little problems:

1) label "Your points" was cropped (I have WIN98SE, maybe this is reason)

2) in Pause state did't disabled hotkeys for Up,Down,Left,Right

3) in Pause state was CPU usage 100% (tight loop without sleep)

And I added some little improvement:

4) added application icon

5) in Pause state shown label PAUSED

6) now application can be closed also in Pause state

7) little optimizing: _hotkey_enable() at begining of script

One error I didn't corrected:

8) yellow object lies "in air"

In this screenshot are visible two problems:

1) label "Your points" is cropped

8) yellow object lies "in air"

Here is Zipped my corrected source also with icon:

Tetris.zip

Share this post


Link to post
Share on other sites

I found another serious problem :D :

- it's consuming huge amount of Windows resources - in WIN98 it's critical

So maybe some optimization:

must be $reserve_id array alocated by GUICtrlCreatePic at begin of script?

Some GUICtrlDelete should be used ...

Share this post


Link to post
Share on other sites

what bout making it for the Desktop...ehm...

German: :D

Mach das mal so, dass man quasi au dem Desktop spielt :D so wollte ich das nämlich machen ^^

Share this post


Link to post
Share on other sites

Niiiice script. This thing is very slick.


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

@zedna

Here is Zipped my corrected source also with icon:

It's nice if you want to help me and i see u tested well. But if you might imagine i prefer to improve my scripts on my own. If you post some lines of the code, that have to be improved, that's good and can help me much.

I watched your changes and those weren't even many, only updates in the pause function and changes in the height of the controls by 10 (Icon). So it would have been enough to post the pause_function code or to say that the pause funtion has to be improved instead of posting your wonderful own zip.

Cya

Markus


"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites

I found another serious problem :

- it's consuming huge amount of Windows resources - in WIN98 it's critical

So maybe some optimization:

must be $reserve_id array alocated by GUICtrlCreatePic at begin of script?

Some GUICtrlDelete should be used ...

Hm seems to be a WIN98 Problem, i haven't noticed such things with XP.

While scripting Tetris, i wondered if it would be better to delete the controls and create them new, or to create all at the start. I decided (as you can see) to create all at the start. I don't know if that's the better way, but so i never have to create new controls all the time, if a line is full the pics are added to the reserve_id instead of removing them.


"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites

It's nice good job! I don't have much to say on improvments except how about making it automatically pause when the GUI is not activated?

Hallman

Share this post


Link to post
Share on other sites

I watched your changes and those weren't even many, only updates in the pause function and changes in the height of the controls by 10 (Icon). So it would have been enough to post the pause_function code or to say that the pause funtion has to be improved instead of posting your wonderful own zip.

Of course I would post only changes, if it will be in only one function, but my changes were at 4 diferrent places of your code so I decided to post whole script.

I you are angry for it, then sorry :D

Share this post


Link to post
Share on other sites

8) yellow object lies "in air"

This error occured only twice and always at level 13 or 14 (high speed)

so I think somewhere in code is not catched this high speed correctly.

Share this post


Link to post
Share on other sites

I you are angry for it, then sorry

It's ok :D

8) yellow object lies "in air"

I thought about that and i think it's a problem of the rotate and move hotkey_functions. You can start that functions nearly everywhere. But there are some positions in the script, where those functions lead to bugs i think. There aren't much of those positions and it's hard to press the hotkey just there. But it can happen.

I'll change that.


"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now