import java.lang.*; import java.awt.*; import nathanw.*; class TetrisGame implements PosPaintable { Grid playfield; TetrisPiece piece; int curScore; int px,py; intNonZero testNonZero; intOr putDown; public TetrisGame(int xs,int ys,boolean randomCrap) { playfield=new Grid(xs,ys,1); clear(); piece = new TetrisPiece(); py=0; px=(xs-piece.sizex())/2; testNonZero = new intNonZero(); putDown = new intOr(); curScore=0; } void clear() { playfield.fill(0,0,playfield.sizex(),playfield.sizey(),0); } public void paint(Graphics g, int x,int y) { g.drawRect(x,y,2+playfield.sizex()*10,2+playfield.sizey()*10); for(int j=0;j=px) && (i=py) && (j=0;j--) while(testFullLine(j)==true) { deleteLine(j); // Simple scoring function curScore+=10; } // Put on a new piece piece = new TetrisPiece(); py=0; px=(playfield.sizex()-piece.sizex())/2; if(playfield.compare(piece,px,py,testNonZero)) return true; } py++; return false; } private boolean testFullLine(int y) { for(int i=0;i0;j--) for(int i=0;i