Página en revisión Código en Processing, tomado de: http://www.danepieri.com/tetris_play.html {{{ // Controls: // Arrow keys for left, right, down, rotate // Spacebar to drop piece //import processing.opengl.*; PFont Hira; Board myBoard; Board.BoardBlock[][] myBoardBlock; fallingPiece myPiece; int numRows = 15; int numCol = 10; int brickSize = 25; int offset = 20; int numRowsCleared; boolean gameIsOver = false; void setup(){ size(440,415); stroke(100); Hira = loadFont("Ziggurat.vlw"); myBoard = new Board(); myBoardBlock = new Board.BoardBlock[10][15]; for (int i=0; i numCol-1 || x < -1 || y > numRows-1 || myBoardBlock[x][y].isTaken() == true ){ return false; } return true; } void freezeBlock(){ for (int i=0; i0; k--){ myBoardBlock[j][k].taken = myBoardBlock[j][k-1].taken; myBoardBlock[j][k].col = myBoardBlock[j][k-1].col; } } } } if (numFullRows == 4){ score += 800; // Tetris!! } else if(numFullRows > 0){ score = score + (numFullRows * 100); numRowsCleared += numFullRows; } numFullRows = 0; } void renderBoard(){ for (int i=0; i<10; i++){ for (int j=0; j<15; j++){ myBoardBlock[i][j].render(); } } noFill(); strokeWeight(1); rect(offset,offset, brickSize*numCol, brickSize*numRows); } void gameOver(){ gameIsOver = true; // println("Game Over"); } void newGame(){ score = 0; gameIsOver = false; for (int i=0; i bX && mouseX < bX + bWidth && mouseY > bY && mouseX < bY + bHeight){ if(mousePressed){ myBoard.newGame(); } } } } // ============ Board Block sub class =============== public class BoardBlock extends Board{ color col; int x; int y; boolean taken; // Constructor BoardBlock(int x, int y){ col = color(150,150,230); this.x = offset+ x*25; this.y = offset+ y*25; this.taken = false; } // Accessor boolean isTaken(){ return taken; } // Setter void take(){ this.taken = true; } void render(){ fill(col); if(taken){ strokeWeight(1); } else{ strokeWeight(1); } rect(x,y, brickSize,brickSize); } } } }}}