Skip to content

Commit

Permalink
- Constants made truly constants.
Browse files Browse the repository at this point in the history
- Further logic implementing.
  • Loading branch information
graninas committed Jul 19, 2014
1 parent 3f2b635 commit 12c9eb1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 35 deletions.
1 change: 0 additions & 1 deletion Tetris.pde
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ void drawTestRect()
rect(1*windowScale, 1*windowScale, windowScale, windowScale);
}


void setup() {

game = new Game(w, h);
Expand Down
51 changes: 51 additions & 0 deletions TetrisBlock.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Classic Tetris only blocks
int blockPartsCount = 4;

int I = 0;
int O = 1;
int T = 2;
int S = 3;
int Z = 4;
int J = 5;
int L = 6;

int North = 0;
int East = 1;
int South = 2;
int West = 3;

class Block {
int type;
int xPos;
int yPos;
int direction;

Block (int blockType, int blockXPos, int blockYPos, int blockDirection) {
type = blockType;
xPos = blockXPos;
yPos = blockYPos;
direction = blockDirection;
}
};

point[] getBlockParts(Block block) {
point[] parts = new point[blockPartsCount];

switch(block.type) {
case I: parts[0] = point(0,0);
parts[1] = point(1,0);
parts[2] = point(2,0);
parts[3] = point(3,0);
break;
// TODO: implement other blocks

// Debug only
default:
parts[0] = point(0,0);
parts[1] = point(1,0);
parts[2] = point(2,0);
parts[3] = point(3,0);
}
return parts;
}

56 changes: 22 additions & 34 deletions TetrisGameState.pde
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
int I = 0;
int O = 1;
int T = 2;
int S = 3;
int Z = 4;
int J = 5;
int L = 6;

int North = 0;
int East = 1;
int South = 2;
int West = 3;

class Block {
int type;
int xPos;
int yPos;
int direction;

Block (int blockType, int blockXPos, int blockYPos, int blockDirection) {
type = blockType;
xPos = blockXPos;
yPos = blockYPos;
direction = blockDirection;
}
};

class Game {
int wellWidth;
Expand All @@ -32,7 +7,7 @@ class Game {
Game (int w, int h) {
wellWidth = w;
wellHeight = h;
currentBlock = null;
fallingBlock = null;

blocks = new boolean[w][h];
for (int x = 0; x < w; x++)
Expand All @@ -41,36 +16,49 @@ class Game {
}

boolean[][] blocks;
Block currentBlock;
Block fallingBlock;
};


boolean isBlockStuck(Game game)
{
Block block = game.currentBlock;
Block block = game.fallingBlock;
boolean[][] blocks = game.blocks;

// TODO: check all block parts
return (block.yPos + 1 >= game.wellHeight)
|| (blocks[block.xPos][block.yPos + 1]);
}

boolean validateCurrentBlockPos(Game game) {
boolean validateFallingBlockPos(Game game) {
return true;
}

void fixateBlock(Game game) {
// Not implemented yet
}

void generateNextBlock(Game game) {
// Not implemented yet
}

Game updateGameState(Game game) {
Game updatedGame = game;
Game currentGame = game;

if (game.currentBlock != null) {
if (currentGame.fallingBlock != null) {

// Debug only
if (!validateCurrentBlockPos(game)) {
if (!validateFallingBlockPos(currentGame)) {
println("invalid block pos.");
}

boolean moved = isBlockStuck(game);
if (isBlockStuck(currentGame)) {
fixateBlock(currentGame);
generateNextBlock(currentGame);
}
}

return updatedGame;
return currentGame;
}

boolean isGameOver(Game currentGame) {
Expand Down

0 comments on commit 12c9eb1

Please sign in to comment.