pad.mattdiesel.co.uk

Snippet - Tetris in 100x100 characters

Tetris in 100x100 characters (AutoIt)

Includes music, pause resume and other cool things.
Created 2014-04-08 19:56:56.473720 by Matt.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
Dim $3="script.au3",$f=FileInstall("tetris.au3",$3)&FileRead($3),$l=StringRegExp($f,":(\d)",3),$s[ _
22][10],$n[4][4],$m=StringRegExp($f,"~(-?\d)",3),$o=StringRegExp($f,"@(\d+)",3),$p=StringRegExp($f _
,";(\d)",3),$c=StringRegExp($f,"`(\d+)",3),$t='"Score: "&$u&@LF&"Lines: "&$v&@LF&"Level: "&$w',$r[ _
5]=[0,1,3,5,8],$kc=0,$ka=0,$i=@TAB&"Highscores:",$d="Mat's TetrisĀ²",$j=GUICreate($d,420,464),$k,$1 _
="GUICtrlCreateDummy()",$kk=StringRegExp($f,"%(\w)",3),$a[5][3]=[["w",Execute($1)],["a",Execute($1 _
)],["s",Execute($1)],["d",Execute($1)],["b",Execute($1)]],$2=GUISetAccelerators($a);`11141120~-2~1..
If $CmdLine[0] Or Run('"'&@AutoItExe&'" '&$CmdLineRaw&" m")*0 Then Exit AutoItWinSettitle(@TAB)+m(0)
Func m($3);4;1;2;3;2;1;0;0;2;4;3;2;1;2;3;4;2;0;0;0;1;2;3;5;7;6;5;4;2;4;3;2;1;1;2;3;4;2:2:1:1:2:1:1:2
Return $3<40 And m($3+Beep($o[$p[$3]],210*$l[$3])) Or Run('"'&@AutoItExe&'" '&$CmdLineRaw);0@220:1;0
EndFunc;:1:2:1:1:3:1:2:2:2:2:1:1:1:1:3:1:2:1:1:3:1:2:1:1:2:1:1:2:2:2:2:2@247@262@294@330@349@392@419
Dim $o=1,$p="SndVolSSO.dll",$l='"'&@AutoItExe&'" '&$CmdLineRaw&" m",$d1=$d&GUISetState();`16777215..
For $3=0 To 199 Step GUISetBkColor(0,GUICreate($d1,420,464,0,0,2^30,8,$j))*GUICtrlSetDefColor($c[1])
$s[$3/10+2][Mod($3,10)]=GUICtrlCreateLabel("",Mod($3,10)*22+1,Int($3/10)*23+1,20,21,1);`11141290`170
If $3<16 Then $n[$3/4][Mod($3,4)]=GUICtrlCreateLabel("",Mod($3,4)*22+235,Int($3/4)*23+41,20,21);~-1.
Next;`43520`11162880`43690~1~0~1~1~1~0~-2~0~-1~0~0~0~1~-2~0~-1~0~0~0~1~0~-1~-2~-1~-1~-1~0~-1~1~-1~-1
Dim $q,$_[4]=[GUICtrlCreateLabel("",224,1,1,462,5),GUICtrlCreateLabel(Execute($t),236,160,92,100), _
GUICtrlCreateLabel("Next:",236,22,92),GUICtrlCreateLabel($i&FileRead("hiscore.txt"),236,260,92,200)]
GUISetBkColor(GUICtrlSetDefColor($c[4],GUICreate($d&2,420,464,0,0,2^28*5,8,$j))+GUISetFont(26,400));
Dim $e[9]=[GUICtrlCreateLabel("New Game",80,180,260,40,257),GUICtrlCreateLabel("Restart",80,240, _;.
260,40,257),GUICtrlCreateLabel("Exit",80,360,260,40,257),GUICtrlCreateLabel($d,80,40,260,40,1), _;..
GUICtrlCreateLabel("",80,90,260,40,1),GUICtrlCreateLabel("Instructions",80,300,260,40,257), _;~-1~0.
GUICtrlCreateIcon($p,124,384,428)],$1=GUICtrlSetState($e[1],32),$w=GUICtrlSetImage($e[6],$p,124);~0.
While Assign("3",GUIGetMsg()) And (($3<>-3 And $3<>$e[2]) Or 0*WinClose(@TAB));~0~1~0~1~-1~0~-1~0~0.
if $3=$e[6] And $o Then ContinueLoop Assign("o",0*GUICtrlSetImage($e[6],$p,120)*Winclose(@TAB));~0~1
if $3=$e[6] And Not $o Then ContinueLoop Assign("o",1+0*GUICtrlSetImage($e[6],$p,124)*Run($l));~-1~0
if $3=$e[5] Then MsgBox(8256,$d&" Instructions",StringFormat($d&" is tetris implemented in 100x1"& _
"00 AutoIt code.\n\nW\tSpin\nA/D\tMove left/right\nS\tHard-fall\nESC\tPause (goes to menu)\n\nI "& _
"hope you enjoy playing this game as much as I enjoyed making it!\n\nThanks,\n\tMat",0,$j));~0~0~1~0
if ($3<>$e[0] And $3<>$e[1]) Or 0*ControlHide($j,"",$d&2)*ControlShow($j,"",$d&1) Then ContinueLoop;
$k=((Not $k Or $3=$e[1]) And o())+($ka Or AdlibRegister("f",500/$w));~1~1~0~-1~0~0~0~1~-1~1~-1~0~0~0
While Assign("3",GUIGetMsg()) And ($3<>-3) And 1+($3=$a[2][1] And k(2)) and 1+($3=$a[4][1] And k(4))
ContinueLoop $3=$a[4][1] And 1+0*($ka And d(0,3,1)*Assign("g",Mod($g+1,7))*d(1,3,1));~1~0~1~-1~0~-1.
ContinueLoop $3=$a[2][1] Or ($3=$a[1][1])+($3=$a[3][1])+($3=$a[0][1])=0 And 1+($3=$a[2][1] And f());
$q=0*(AdlibUnRegister("s")+Assign("4",($3=$a[3][1])*2-1)+Assign("x",$x+$4*($3<>$a[0][1])));~0~0~0~1.
ContinueLoop $3<>$a[0][1] And (c($4)*Assign("x",$x-$4) And (d(0)+Assign("x",$x+$4)+d()))*k(2+$4)+1;.
d(1+0*(Assign("z",Mod($z+1,4)+0*d(0))+(c(2) Or (Assign("x",$x-1) And (c(2) Or (Assign("x",$x+2) _;~1
And (c(2) Or (Assign("x",$x-1)+Assign("z",Mod($z+3,4)))))))))*k(0));~1~-1~1~-1~0~0~0~1~0~-1~-1~0~-1.
WEnd;~0~0~0~1~-1~-1~-1~0~0~-1~0~0~-1~-1~-1~0~0~-1~0~0~-1~-1~-1~0~0~-1~0~0~-1~-1~-1~0~0~-1~0~0~-1~0~0
If ControlHide($j,"",$d1)+AdlibUnRegister("f")+AdlibUnRegister("s") And $k Then $1=GUICtrlSetData( _
$e[3],$d)+GUICtrlSetData($e[0],"Resume")+GUICtrlSetData($e[4],"")+GUICtrlSetState($e[1],16);~0~0~-1.
If ControlShow($j,"",$d&2)-$k Then $1=GUICtrlSetData($e[0],"New Game")+GUICtrlSetState($e[1],32);~1.
WEnd;~-1~0~-1~0~0~1~0~1~1~-1~1~0~1~0~0~1~0~-1~-1~-1~0~0~0~0~1~-1~0~0~0~0~-1~1~0~0~-1~0~0~0~1~1~0~-1.
Func c($1,$3=3);~0~0~0~0~1~1~0~-1~0~0~-1~0~0~0~1~-1~-1~0~-1~0~0~1~0~0~1~0~0~1~0~1~-1~-1~0~0~0~0~1~1.
Return $3=-1 Or (Assign("2",g($3))+Assign("5",g($3,1)) And $5>=0 And ($2>=0 And $2<10) And (($5<22 _
And Not $b[$5][$2]) Or ($1=0 And 0*($q or Assign("q",1+AdlibRegister("s",500)))) And c($1,$3-1)));~1
EndFunc;~-1~1~-1~0~0~0~0~-1%0%0%2%2%1%3%1%3%4%1.....................................................
Func d($1=1,$3=3,$5=0,$7="GUICtrlSetBkColor($n[2*($g<>0)+g($3,1,0,$g,0)][2+g($3,0,0,$g,0)],$c[$g]*")
If Not $5 Then Return $3=-1 Or GUICtrlSetBkColor($s[g($3,1)][g($3)],$c[$h]*$1)+d($1,$3-1);..........
Return $3<0 Or Execute($7&"$1)+d($1,$3-1,1)");......................................................
EndFunc;............................................................................................
Func f();...........................................................................................
Return Assign("y",$y+1) And (c(0)+0*Assign("y",$y-1)) And (d(0)+Assign("y",$y+1)+d());..............
EndFunc;............................................................................................
Func g($3,$1=0,$4=1,$5=$h,$2=$z);...................................................................
Return Eval(Chr(120+$1))*$4+$m[$5*32+$2*8+$3*2+$1];.................................................
EndFunc;............................................................................................
Func o($2="g");.....................................................................................
Global $y=2,$u=0,$v=0*(IsDeclared($2) And d(0,3,1)),$h=Random(0,6,1),$b[22][10],$z=0;...............
For $4=199 To 0 Step -Assign("w",1,2)*Assign($2,Random(0,6,1),2)*Assign("x",5,2)+0*d(1,3,1)*d(1);...
ExitLoop GUICtrlSetBkColor($s[$4/10+2][Mod($4,10)],0) And $4=0 And GUICtrlSetData($_[1],Execute($t))
Next;...............................................................................................
EndFunc;............................................................................................
Func e($1="GAME OVER!",$2="Score: ",$3="hiscore.txt",$4=@LF,$5="9");................................
Dim $6=FileRead($3),$7=StringInStr($6,$4,2,-1),$8=AdlibUnRegister("f")*Assign("k",0)+0*k(-1);.......
While Assign($5,FileReadLine($3,$8+Assign("8",$8+1))&StringLeft(Assign("0",@error),0)) And Not $0;..
If $9<>"" And $u>Int($9) Then ExitLoop Assign("7",StringInStr($6,$4,2,$8-1));.......................
WEnd;...............................................................................................
FileWrite($3,FileRead($3,$7-1)&$4&$u&$4&StringMid($6,$7+WinClose($j)*FileClose(FileOpen($3,2))));...
GUICtrlSetData($_[3],$i&FileRead($3),GUICtrlSetData($e[3],$1)-GUICtrlSetData($e[4],$2&$u));.........
EndFunc;............................................................................................
Func k($1,$2="kc",$3="The block no longer falls automatically (hard fall only), and you can change")
Return ($kk[$kc]=$1 Or 0*Assign($2,$1=0)) And Assign($2,$kc+1) And $kc>9 And ka($3)+Assign("kc",0);.
EndFunc;............................................................................................
Func ka($3,$2=" what the next shape will be with the 'B' key.\n\nNo game is complete without havin")
if (Assign("ka",1-$ka) And $ka And 1+AdlibUnRegister("f")) Or AdlibRegister("f",500/$w)*0 Then _;...
MsgBox(0,"Konomi Code activated",StringFormat($3&$2&"g a Konomi Code.\n\nHave Fun!\n\tMat"),0,$j);..
EndFunc;............................................................................................
Func s();...........................................................................................
For $4=7 To 0 Step -Assign("q",0*AdlibUnRegister("s"))*Assign("3",0)*Assign("5",1);.................
If $4>3 Then $b[g($4-4,1)][g($4-4)]=$c[$h];.........................................................
If $4<4 And (l() Or 1-Assign("4",0)) Then $3+=1;....................................................
Next;...............................................................................................
If Mod($v,10)+$3>9 Then Assign("w",$w+($ka or 0*AdlibUnRegister("f")+AdlibRegister("f",500/($w+1))))
d(0,3,Assign("u",$u+$r[$3]*100)*Assign("v",$v+$3)*Assign("y",2)*Assign("x",5)*Assign("h",$g));......
Dim $g=Random(0,6,1),$z=0*($3 And GUICtrlSetData($_[1],Execute($t)))*(c(2) Or e())*d(1)*d(1,3,1);...
EndFunc;............................................................................................
Func l($3=21,$4=9);......................| Features:  ..............................................
If $3=0 Then Return 0;...................|   * Play using the WASD keys (S = Hard-fall)  ...........
If $4=-1 Then Return 1+0*r($3);..........|   * Shows the next shape  ...............................
If Not $b[$3][$4] Then Return l($3-1);...|   * Background looping beep song (Music A theme)  .......
Return l($3,$4-1);.......................|   * Scoring, and has levels (every 10 lines cleared)  ...
EndFunc;.................................|   * Wall bounce and easy spin like in proper tetris  ....
Func r($3,$4=9);.........................|   * Menu/pause screen (ESC to access)  ..................
If $3=-1 Then Return;....................|   * Instructions button, and toggle beep music on/off  ..
If $4=-1 Then Return r($3-1);............|   * Konomi code. It's not a game without one!  ..........
If $3=0 Then $b[$3][$4]=0;...............|   * Works compiled as well  .............................
If $3=0 Then Return r($3,$4-1);.....................................................................
$b[$3][$4]=$b[$3-1][$4]*GUICtrlSetBkColor($s[$3][$4],$b[$3-1][$4]);.................................
r($3,$4-1);.........................................................................................
EndFunc;................Thanks to flutetunes.com for the sheet music for beep song..................