This is a simple Russian source code, written in JavaScript. It was an occasionally found it before I found it very valuable, so I collected it. Unfortunately, I don't know what it is. The biggest feature of this script is the data required by array storage, simplifies programming, worth learning. Although there is no comment, it seems that it should not understand the author's ideas.
Body {Margin: 0; Background: Black;
TD {height: 20; width: 20;
#block_div {position: absolute; z-index: 1; width: 80;
#table_div {position: absolute; z-index: 0; width: 320;
#NBLOCK_DIV {Position: absolute; z-index: 2; font: 48 system; color: red;}
#title_div {Position: absolute; Left: 326; Top: 7; Font-size: 9pt; color: white}
#infobar_div {Position: absolute; left: 396; top: 416;
# infobar2_div {position: absolute; left: 396; top: 480; font-size: 9pt; color: white}
# infobar2_div a {color: 99ccff; font: system; text-decoration: none}
style>
IF (Document.all) {
VAR n_width = 800;
VAR n_height = 600;
Var n_left = math.round (screen.width / 2) - n_width / 2;
VAR n_top = math.round (screen.height / 2) - n_height / 2;
VAR n_incstep = 20;
Var Curblcok, NextBlock;
Var arr_curblock = new array (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
Var Curx, Cury;
Var speed = 1;
Var maxSpeed = 9;
VAR CLR_PER_LINE = 18;
Var pause = 0;
Var gameOver = 0;
Var colors = new array ("# 999999", "# 80fff", "# 80ff80", "# fff00", "# ff8000", "#f00ff", "#f0000");
VAR CID;
VAR NCID;
VAR blocks = new array (TT_O1 "," TT_T2 "," TT_Z1 "," TT_S1 "," TT_L1 "," TT_J1 "," TT_I2 "); VAR BID;
Var killedlines = 0;
VAR TT_O1 = New Array (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0);
VAR TT_O2 = New Array (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0);
VAR TT_O3 = New Array (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0);
VAR TT_O4 = New Array (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0);
VAR TT_T1 = New Array (0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0);
VAR TT_T2 = New Array (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0);
VAR TT_T3 = New Array (0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0);
VAR TT_T4 = New Array (0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0);
VAR TT_Z1 = New Array (0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0);
VAR TT_Z2 = New Array (0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0);
VAR TT_Z3 = New Array (0,0,0,0,0,1,1,0,0,0,0);
VAR TT_Z4 = New Array (0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0);
VAR TT_S1 = New Array (0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0);
VAR TT_S2 = New Array (0,0,0,0,0,0,0,0,1,0);
VAR TT_S3 = New Array (0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0);
VAR TT_S4 = New Array (0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0);
VAR TT_L1 = New Array (0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0);
VAR TT_L2 = New Array (0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0);
VAR TT_L3 = New Array (0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0);
VAR TT_L4 = New Array (0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0);
VAR TT_J1 = New Array (0,0,1,0,0,0,0,0,0,0,0,0,10,0,0,0);
VAR TT_J2 = New Array (0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,10,0,0,0);
VAR TT_J3 = New Array (0, 0, 0, 0, 0, 1, 1, 0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0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
}
Else
Alert ("You NEED IE4 To Play Tetris!")
Function Dimension2 (Row, Col, Num) {
VAR i = row * Num col;
Return (THIS [I]);
}
Array.Prototype.getd = Dimension2;
Function Showblock (X, Y, Block_Type, Color) {
For (VAR i = 0; i For (var j = 0; j VAR D2 = i * 4 j; IF (block_type [d2] == 1) { Block_tbl.rows (i) .cells (j) .style.background = color; } Else { Block_tbl.rows (i) .cells (j) .style.background = " } } } Block_div.style.pixelleft = x; Block_div.style.pixeltop = y; } Function Showblock1 (x, y, block_type, color, obj_tabid, obj_divid) { FOR (var i = 0; i For (var j = 0; j IF (block_type [d2] == 1) { Obj_tabid.rows (i) .cells (j) .style.background = color; } Else { Obj_tabid.rows (i) .Cells (j) .style.background = " } } } Obj_divid.style.pixelleft = x; Obj_divid.style.pixeltop = y; } Function change (inc) { Var type = curblock.substr (0,4); VAR Num = curblock.substr (curblock.length-1); Num = parseint (num) inc; IF (NUM> 4 || Num <1) Num - = 4 * Inc; TYPE = Num; EVAL ("arr_tmp =" type ";"); IF (CANMOVE (CURX, Cury, Arr_TMP) { Curblock = Type; EVAL ("arr_curblock =" curblock ";"); Eval ("Showblock (Block_Div.style.pixelleft, block_div.style.pixeltop," curblock ", colors [" CID "]);"); } } Function Canmove (X, Y, Block) { For (i = 0; i <4; i ) { For (j = 0; j <4; j ) { IF (Block.getd (i, J, 4) & Table.getd (Y / N_INCSTEP I, X / N_INCSTEP J, 16)) RETURN FALSE; } } Return True; } Function newblock () { Curblock = nextblock; CID = NCID; Bid = math.round (math.random () * (blocks.length-1); NCID = Math.Round (Math.random () * (Colors.length-1)); NextBlock = blocks [bid]; EVAL ("arr_curblock =" curblock ";"); EVAL ("Showblock (120, 0," Curblock ", Colors [" CID "]);"); EVAL ("arr_curblock =" curblock ";"); EVAL ("Showblock1 (466, 116," NextBlock ", Colors [" NCID "], NBLOCK_TBL, NBLOCK_DIV);"); } Function saveblock () { For (i = 0; i <4; i ) {for (j = 0; j <4; j ) { Table [(CURY / N_INCSTEP I) * 16 CURX / N_INCSTEP J] | = arr_curblock [i * 4 j]; IF (arr_curblock [i * 4 j] == 1) IF ((Cury / N_INCSTEP I <21) && (CURX / N_INCSTEP J> 1) && (CURX / N_INCSTEP J <14))) Table_TBL.Rows (Cury / n_incstep i) .Cells (CURX / N_INCSTEP J) .Style.Background = Colors [CID]; IF (Table / N_INCSTEP I) * 16 CURX / N_INCSTEP J]! = 1) Table_TBL.ROWS (CURY / N_INCSTEP I) .Cells (CURX / N_INCSTEP J) .Style.Background = "Black"; } } } Function Delline (LINE) { For (i = line; i> 0; i -) { For (j = 2; j <14; j ) { Table [i * 16 j] = Table [(i-1) * 16 j]; } } Table_TBl.deleterow (LINE); Table_tbl.insertrow (0); For (i = 0; i <16; i ) { Table_TBL.ROWS (0) .insertcell (); IF (i <2 || i> 13) Table_TBL.ROWS (0) .Cells (i) .Style.Background = "Navy"; } KilledLines ; Cll.innertext = PARSEINT (CLL.INNERTEXT) 1; } Function Dellines () { Var C, D, I, J; D = 0; Cury = block_div.style.pixeltop; For (i = (CURY / 20 3); I> Cury / 20-1; I -) { C = 0; For (j = 2; j <14; j ) { IF (ISNAN (Table [i * 16 j]) || i == 21) Break; C = Table [i * 16 j]; } IF (c == 12) { Delline (i); i ; D ; } } IF (D> 0) Sco.innertext = PARSEINT (SCO.INNERTEXT) D * D * 36; } Function lucifer () { FOR (var i = 2; i <14; i ) { IF (Table [16 I] == 1) Return True; } Return False; } Function gameOver () { GameOver = 1; ClearInterval (GameInterVal); Block_div.innerhtml = ""; For (i = 0; i <21; i ) { For (j = 2; j <14; j ) { SetTimeout ("Table_TBL.Rows (" i ") .Cells (" J ") .Style.Background = Colors [Math.Round (Math.Radom () * 7)];", 16 * i * j } } nblock_div.innerhtml = "Game over"; } Function Document_onkeyDown () { IF (GameOver == 1) Return; With (block_div.style) { CURX = Pixelleft; Cury = pixeltop; Switch (Event.Keycode) { Case 37: IF (curx-n_incstep, cury, arr_curblock) Pixelleft- = n_incstep; Break; Case 38: Change (1); Break; Case 39: IF (curx n_incstep, cury, arr_curblock) Pixelleft = n_incstep; Break; Case 40: IF (CANMOVE (Curx, Cury N_INCSTEP, ARR_CURBLOCK) { Pixeltop = n_incstep; } Else { Saveblock (); Dellines (); IF (lucifer ()) { GameOver (); Return; } Sco.innertext = PARSEINT (SCo.innertext) 2; NEWBLOCK (); } Break; Case 32: IF (pause == 0) { ClearInterval (GameInterVal); Pause = 1; } Else { GameInterval = Window.setInterval ("Handle_Interval ()", (MaxSpeed-Speed 1) * 60); Pause = 0; } Break; Case 90: Change (1); Break; Case 88: Change (-1); Break; DEFAULT: } } } Function Handle_Interval () { Curx = block_div.style.pixelleft; Cury = block_div.style.pixeltop; IF (CANMOVE (Curx, Cury N_INCSTEP, ARR_CURBLOCK) { Block_div.style.pixeltop = n_incstep; } Else { Saveblock (); Dellines (); IF (lucifer ()) { GameOver (); Return; } Sco.innertext = PARSEINT (SCO.INNERTEXT) 2 NEWBLOCK (); } IF (killedlines> = CLR_PER_LINE) { KilledLines- = CLR_PER_LINE; SPEED SPEED ; Else Speed = MaxSpeed; SPD.INNNERTEXT = Speed; ClearInterval (GameInterVal); GameInterval = WINDOW.SETINTERVAL ("Handle_Interval ()", (MaxSpeed-Speed 1) * 60); } Script> IF (Document.all) Document_onkeydown () Script> HEAD>