// Play.java // Part of Tetris.java, V1.0 // Sunday, Oct. 1, 2000, by Yamin Li, yamin@k.hosei.ac.jp // Free to use, modify, and distribute. import java.awt.*; class Play extends Canvas { private static final int rows=20; private static final int cols=10; private static final int size=20; private static final Color empty=Color.darkGray; private static final Color shapeColor[]={ Color.cyan, Color.pink, Color.green, Color.orange, Color.red, new Color(127,127,255), Color.magenta}; private boolean leftOutSide=false, rightOutSide=false, upOutSide=false; private boolean noPlace=false, drop=false, gameOver=false; private int score=0, level=0, lines=0, delay=300; private int shapeType=0, currentDirection=0, tryDirection=0; private int tryPositionX=5, tryPositionY=1; private int tryX[], tryY[]; private int currentPositionX=5, currentPositionY=0; private int currentX[], currentY[]; private Image displayBuffer; private Graphics drawingBuffer; private Color playArea[][]; private Color myColor; public void initialize(){ setSize(cols*size+100, rows*size); displayBuffer=createImage(cols*size+100, rows*size); drawingBuffer=displayBuffer.getGraphics(); playArea=new Color[rows+2][cols]; tryX=new int[Shape.pieces]; tryY=new int[Shape.pieces]; currentX=new int[Shape.pieces]; currentY=new int[Shape.pieces]; drop=false; score=0; level=0; lines=0; clearPlayArea(); myColor=new Color(0x1f, 0xbf, 0xaf); generateNewBlock(); } public void paint(Graphics g){ int i, j; for(i=0; id) d=-tryX[i]; } if (leftOutSide){ for(i=0; i(cols-1)){ rightOutSide=true; if ((tryX[i]-(cols-1))>d) d=tryX[i]-(cols-1); } if (rightOutSide){ for(i=0; id) d=-tryY[i]; } if (upOutSide){ for(i=0; i0; i--){ boolean removeThisLine=true; for(j=0; j0; k--) for(j=0; j>4; return(removed); } public void clearPlayArea(){ int i, j; for(i=0; i