JavaScript
var COLS = 10, ROWS = 20;
var board = new Array(ROWS);
for ( i = 0; i < board.length; i++ ) {
board[i] = new Array(COLS);
}
///////////////////////////////////////////////////////////////////
var falling,fallingPiece,nextPiece,fallingPiecePos;
var colors = [
'blue', 'orange', 'brown', 'yellow', 'red', 'green', 'purple'
];
var shapes = [
[{y:0,x:4},{y:0,x:5},{y:0,x:6},{y:0,x:7}],
[{y:0,x:4},{y:0,x:5},{y:0,x:6},{y:1,x:4}],
[{y:0,x:4},{y:0,x:5},{y:0,x:6},{y:1,x:5}],
[{y:0,x:4},{y:0,x:5},{y:0,x:6},{y:1,x:6}],
[{y:0,x:4},{y:0,x:5},{y:1,x:4},{y:1,x:5}],
[{y:0,x:4},{y:0,x:5},{y:1,x:3},{y:1,x:4}],
[{y:0,x:4},{y:0,x:5},{y:1,x:5},{y:1,x:6}]
];
//make the next piece start falling
function newPiece(){
//replace "fallingPiece"
fallingPiece = nextPiece;
//the piece will now start falling
falling = true;
//find a new piece to appear as "nextPiece"
nextPiece = newRandomPiece();
}
function start(){
nextPiece = newRandomPiece();
newPiece();
writePiece();
}
function newRandomPiece(){
//find a random value 1-7 (7 types of pieces)
return Math.ceil(Math.random() * 7);
}
function nextFrame(){
//console.log(falling+"-"+fallingPiece);
if( falling ){
dropByOne();
finishedFalling();
} else {
findFullLines( makeList() );
newPiece();
writePiece();
}
}
function writePiece(){
var shapeCopy = JSON.parse(JSON.stringify(shapes));
fallingPiecePos = shapeCopy[fallingPiece - 1];
for ( i = 0; i < 4; i++ ) {
board[ fallingPiecePos[i].y ][ fallingPiecePos[i].x ] = fallingPiece;
}
}
function finishedFalling(){
//check if piece has finished falling
if ( !nothingIsBelow() ) {
//if yes, tell the program so
falling = false;
}
}
//drop the falling piece by one space
function dropByOne(){
//loop through the four squares that make up the piece
for ( i = 3; i > -1; i-- ) {
//empty old spot of piece
board[ fallingPiecePos[i].y ][ fallingPiecePos[i].x ] = false;
//drop position place-holder by one row
...