/* ***************************************************************************************** AUTHOR: Simona Pappalardo MAIL: pacana@libero.it * *****************************************************************************************/ import java.lang.*; import java.awt.*; public class Tetrisgame { static Table[][] griglia; static boolean rigaPiena; int nr_pezzo,maxX,maxY; Base pezzo; int[] color; boolean gameOver = false,fine = false; static boolean primo=true; Tetrisgame(int maxX,int maxY) { this.maxX = maxX; this.maxY = maxY; primo = true; rigaPiena = false; color = new int[3]; // grid initialization: it's all empty griglia = new Table[maxX+1][maxY+1]; for (int i=0; i<=maxY;i++) for(int j=0;j<=maxX;j++) griglia[j][i] = new Table(); return; } public void paint(Graphics g) { if(!primo) // I have not to erase the just painted piece, it this is the first time. { g.setColor(AppletEnglish.color); g.drawPolygon(pezzo.oldCoordX,pezzo.oldCoordY,pezzo.nr_punti); g.fillPolygon(pezzo.oldCoordX,pezzo.oldCoordY,pezzo.nr_punti); } primo=false; if(!AppletEnglish.modifica_livello) { g.setColor(Color.black); g.drawPolygon(pezzo.coordCorrX,pezzo.coordCorrY,pezzo.nr_punti); g.setColor(new Color(pezzo.color[0],pezzo.color[1],pezzo.color[2])); g.fillPolygon(pezzo.coordCorrX,pezzo.coordCorrY,pezzo.nr_punti); } if(Base.aggiorna) // I remove the little square border if it's painted into the grid. { g.setColor(AppletEnglish.color); g.drawPolygon(pezzo.oldCoordX,pezzo.oldCoordY,pezzo.nr_punti); Base.aggiorna = false; } return; } public void makePiece() { nr_pezzo = choosePiece(); for(int i=0;i<3;i++) color[i]=(int)(Math.random()*255); switch (nr_pezzo) { case 0: pezzo = new Piece0(maxX,maxY,color);break; case 1: pezzo = new Piece1(maxX,maxY,color);break; case 2: pezzo = new Piece2(maxX,maxY,color);break; case 3: pezzo = new Piece3(maxX,maxY,color);break; case 4: pezzo = new Piece4(maxX,maxY,color);break; case 5: pezzo = new Piece5(maxX,maxY,color);break; case 6: pezzo = new Piece6(maxX,maxY,color);break; case 7: pezzo = new Piece7(maxX,maxY,color);break; case 8: pezzo = new Piece8(maxX,maxY,color);break; case 9: pezzo = new Piece9(maxX,maxY,color);break; case 10: pezzo = new Piece10(maxX,maxY,color);break; case 11: pezzo = new Piece11(maxX,maxY,color);break; } Tetrisgame.rigaPiena = false; return; } public boolean goDown() { fine = pezzo.ifFallDown(); return fine; } public boolean end() { gameOver = pezzo.end(); return gameOver; } public int choosePiece() { switch (AppletEnglish.livello) { // level1: choose 1 random piece amongst all the existing ones. case 1: return ((int) (Math.random()*12)); // level2: choose 1 random piece amongst all the existing ones that have 4, 3 or 2 little squares case 2: return ((int) (Math.random()*11)); // level3: choose 1 random piece amongst all the existing ones that have 4 or 3 little squares case 3: return ((int) (Math.random()*10)); // level4: choose 1 random piece amongst all the existing ones that have 4 little squares case 4: return ((int) (Math.random()*7)); } return 0; } }