A Russian square written earlier, I don't know if there is a bug.
/ * * Russian square (basic function implementation only 400 lines of code) * Program main frame is: Gameinit () * Run () -----> Paint () & update () * | * | new curblock < | NEED new block? * | | * Klistener (), Moveright (), * Movedown (), Moverotate () * * Display the game interface Paint (), update () * Initializer parameters, create a game thread into the game Cycle {* Response User Operation Klistener * / Import Java.awt. *; Import Java.awt.Event. *; Import Javax.swing. *; Public Class Tetrics {JFrame Mainf; Tetricscanvas Tcanvas = New Tetricscanvas (); Public TETRICS ) {mainf = new jframe (); mainf.getContentPane (). add (tcanvas); showframe ();} private void showframe () {mainf.settitle ("TETRICS"); mainf.setsize (320, 550); mainf.setResizable (5); mainf.setlocation (300, 100); mainf.setvisible (TRUE); public static void main (string [] args) {new tetrics ();}} ------------- -------------------------------------------------- ----------------- Import java.awt. *; import java.awt.event. *; import javax.swing. *; public class tetricscanvas extends canvas imports runnable {Boolean BGameover = false; int Unitsize = 15, ROWS = 32, C Olumns = 18; int [] gameboard = new int [ROWS 1] [Column]; int [] [] blockboard = new int [】 [] ] [columns]; block [] curblock = new block [4] ; boolean bnewBlock = true; Image bgImage; Graphics bg; public TetricsCanvas () {setBackground (Color.white); addKeyListener (new KListener ()); gameInit ();} public void gameInit () {for (int i = 0; I G. Draw3DRECT (20 J * Unitsize, 20 i * Unitsize, Unitsize, Unitsize, False); IF (Gameboard [i] [j] == 1 || blockboard [i] [j] == 1) {IF (Gameboard [i] [j] == 1) g.setColor (color.blue); Else IF (blockboard [i] [j] == 1) g.setcolor (color.green); g.Fill3DRect (20 J * Unitsize, 20 i * unitsize, unitsize, unitsize, false;} else {g.setcolor (color.black); g.fill3dRect (20 J * Unitsize, 20 i * Unitsize, Unitsize, Unitsize, False );}}} {for (int i = 0; i } public void checkgameOver () {for (int i = 0; i <4; gameboard [curblock [i] .row] [curblock [i] .COLUMN] == 1) {bgameOver = true; system. Out.println (BGameOver);}} class block {int Row, Column; PUBLIC Block (Int row, int column) {this.row = row; this.column = column;}} public void newblock () {int urow = 0; int UCOLUMN = Column / 2; math.random () * 6)) {case 0: / * @@@@@ / curblock [0] = new block (urow, ucolumn - 1) Curblock [1] = new block (urow, ucolumn - 2); curblock [2] = new block (urow, ucolumn); curblock [3] = new block (urow, ucolumn 1); Break; Case 1: / * @@@ * / curblock [0] = new block (urow 1, ucolumn); curblock [1] = new block (urow, ucolumn); curblock [2] = new block (urow 1, ucolumn - 1 ); curblock [3] = new block (urow 1, ucolumn 1); break; casp 2: / * @@ @@ * / curblock [0] = new block (urow 1, ucolumn); curblock [1 ] = new block (urow, ucolumn - 1); curblock [2] = new block (urow, ucolumn); curblock [3] = new block (urow 1, ucolumn 1); Break; Case 3: / * @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ * / curblock [0] = new block (urow 1, ucolumn); curblock [1] = new block (urow, ucolumn 1); curblock [2] = new block (urow, ucolumn); Curblock [3] = New Block (UROW 1, UColumn - 1); Break; Case 4: / * @@ @@ * / curblock [0] = new block (urow, ucolumn - 1); curblock [1] = new block (urow , ucolumn); curblock [2] = new block (urow 1, ucolumn - 1); curblock [3] = new block (urow 1, ucolumn); break; case 5: / * @@@ @ / curblock [0] = New block (urow, ucolumn); curblock [1] = New Block (urow, ucolumn - 1); curblock [2] = new block (urow, ucolumn 1); curblock [3] = new block (urow 1, ucolumn 1); Break; Case 6: / * @ @@ @ * / curblock [0] = new block (urow, ucolumn); curblock [1] = new block (urow, ucolumn 1); curblock [2] = new block (urow, ucolumn - 1); Curblock [ 3] = New Block (urow 1, ucolumn - 1); Break;}} public void fort () {for (int i = 0; i <4; i ) {ix (curblock [i] .column - 1 < 0 || Gameboard [curblock [i] .row] [curblock [i] .COLUMN - 1] == 1) Return;} for (int i = 0; i <4; i ) {blockboard [curblock [i]. Row] [curblock [i] .column] = 0;} for (int i = 0; i <4; i ) {blockboard [curblock [i ].ROW] [curblock [i] .column - 1] = 1; } for (int i = 0; i <4; i ) {curblock [i] = new block (curblock [i] .row, curblock [i] .column - 1);}} public void Moveright ()}} INT i = 0; i <4; i ) {if (Curblock [i] .COLUMN 1> Column - 1 || Gameboard [curblock [i] .row] [curblock [i] .column 1] == 1 ) return;} for (int i = 0; i <4; i ) {blockboard [curblock [i] .row] [Curblock [i] .col UMN] = 0;} for (int i = 0; i <4; i ) {blockboard [curblock [i] .ROW] [Curblock [i] .COLUMN 1] = 1;} for (int i = 0; I <4; i ) {curblock [i] = new block (curblock [i] .row, curblock [i] .column 1);}} public boolean MoveDown ()} public boolean MoveDown ()}} public boolean Movedown ()} i ) {if (curblock [i] .row == Rows - 1 || Gameboard [curblock [i] .row 1] [Curblock [i] .column] == 1) {copyData (); return false; }} for (int i = 0; i <4; i ) {Blockboard [curblock [i] .ROW] [curblock [i] .column] = 0;} for (int i = 0; i <4; i ) {blockboard [curblock [i] .row 1] [Curblock [i] .column] = 1;} for (int i = 0; i <4; i ) {curblock [i] = new block (curblock [i] .row 1, curblock [i] .column);} Return true;} public void copydata () {for (int i = 0; i <4; i ) {gameboard [curblock [i] .row] [curblock [i] .column] = 1;} checkfullrow ();} Public void checkfullrow () {int Num = 0; for (int i = rows - 1; i> = 0; I -) {for (int J = columns - 1; j> = 0; J-) {IF (GameBoard [i] [j] == 1) Num ;} if (num == color) {for (int R = i; r> 0; r -) for (int C = columns - 1; c> = 0; C -) {Gameboard [R] [C] = Gameboard [R - 1] [C]; blockboard [r] [c] = blockboard [r - 1] [c];} for (int top = columns - 1; TOP> = 0; TOP - {Gameboard [0] [TOP] = 0; blockboard [0] [TOP] = 0;} i ;} Num = 0;}} public boolean brotate (block [] Tempblock, int i) {if (Tempblock [i] .row <0 || Tempblock [i] .row> Rows - 1 || Tempblock [i] .column <0 || Tempblock [i] .column> Column - 1 ) Return False; if (Gameboard [Tempblock [i] .row] [Tempblock [i] .COLUMN] == 1) Return False; Return True;} public void motate () {int [] [] Offset = new int [4] [2]; for (int i = 0; i <4; i ) {offset [i] [0] = curblock [i] .Column - curblock [0] .column; offset [i] [1] = curblock [ I] .row - curblock [0] .row;} block [] tempblock = new block [4]; for (int i = 0; i <4; i ) {tempblock [i] = new block (curblock [i] .Row, Curblock [i] .column);} int Tempx, Tempy; for (int i = 0; i <4; i ) {if (Offset [i] [0]> 0 && Offset [I] [1] == 0) {TEMPX = Offset [I] [0]; Tempy = Offset [i] [1]; TempBlock [i] .COLUMN = 0 Tempblock [0] .COLUMN; Tempblock [i] .row = Tempx Tempblock [0] .row; if (! Brotate (Tempblock, i)) {return;}} else if (Offset [i] [0]> 0 && offset [i] [1 ]> 0) {TEMPX = Offset [I] [0]; Tempy = Offset [i] [1]; TempBlock [i] .COLUMN = -Tempx Tempblock [0] .COLUMN; TEMPBLOCK [i] .row = TEMPY Tempblock [0 ].Row; if (! Brotate (Tempblock, I)) {return;}} else if (Offset [i] [0] == 0 && Offset [i] [1]> 0) {TEMPX = Offset [I] [0]; Tempy = Offset [i] [1]; Tempblock [i] .COLUMN = -Tempy Tempblock [0] .COLUMN; Tempblock [i] .row = 0 Tempblock [0] .row ; if (! brotate (Tempblock, i)) {return;}} else if (Offset [i] [0] <0 && offset [i] [1]> 0) {TEMPX = Offset [i] [0]; Tempy = offset [i] [1]; Tempblock [i] .COLUMN = Tempx Tempblock [0] .COLUMN; TEMPBLOCK [i] .row = -TemPy Tempblock [0] .row; if (! brotate (Tempblock, I))) {return;}} else if (Offset [i] [0] <0 && offet [i] [1] == 0) {TEMPX = Offset [i] [0]; TEMPY = Offset [i] [ 1]; TEMPBLOCK [I ] .COLUMN = 0 Tempblock [0] .COLUMN; Tempblock [i] .row = Tempx Tempblock [0] .row; if (! brotate (temblock, i)) {Return;}} else if (Offset [i ] [0] <0 && Offset [I] [1] <0) {TEMPX = Offset [I] [0]; Tempy = Offset [I] [1]; Tempblock [i] .COLUMN = -Tempx Tempblock [ 0] .Column; Tempblock [i] .row = Tempy Tempblock [0] .row; if (! Brotate (tempblock, i)) {return;}} else if (offset [i] [0] == 0 && Offset [i] [1] <0) {TEMPX = Offset [I] [0]; Tempy = Offset [i] [1]; Tempblock [i] .COLUMN =