Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factory method #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/org/psnbtech/ITetrisTile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public interface ITetrisTile {
Color getBaseColor();
Color getLightColor();
Color getDarkColor();
int getDimension();
int getSpawnColumn();
int getSpawnRow();
int getLeftInset(int rotation);
int getRightInset(int rotation);
int getTopInset(int rotation);
int getBottomInset(int rotation);
boolean isTile(int x, int y, int rotation);
}
40 changes: 40 additions & 0 deletions src/org/psnbtech/LTile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
public class TileTypeI implements Tile {
public TileTypeI() {
this.baseColor = new Color(BoardPanel.COLOR_MIN, BoardPanel.COLOR_MAX, BoardPanel.COLOR_MAX);
this.lightColor = baseColor.brighter();
this.darkColor = baseColor.darker();
this.dimension = 4;
this.tiles = new boolean[][] {
{
false, false, false, false,
true, true, true, true,
false, false, false, false,
false, false, false, false,
},
{
false, false, true, false,
false, false, true, false,
false, false, true, false,
false, false, true, false,
},
{
false, false, false, false,
false, false, false, false,
true, true, true, true,
false, false, false, false,
},
{
false, true, false, false,
false, true, false, false,
false, true, false, false,
false, true, false, false,
}
};
this.cols = 4;
this.rows = 4;
this.spawnCol = 5 - (dimension >> 1);
this.spawnRow = getTopInset(0);
}


}
6 changes: 6 additions & 0 deletions src/org/psnbtech/LTileFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class TileTypeIFactory implements TileFactory {
@Override
public TetrisTile createTile() {
return new TileTypeI();
}
}
173 changes: 173 additions & 0 deletions src/org/psnbtech/Tile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
public interface class Tile {
protected Color baseColor;
protected Color lightColor;
protected Color darkColor;
protected int spawnCol;
protected int spawnRow;
protected int dimension;
protected int rows;
protected int cols;
protected boolean[][] tiles;

// Aquí van los métodos getBaseColor(), getLightColor(), getDarkColor(), etc.
/**
* Gets the base color of this type.
* @return The base color.
*/
public Color getBaseColor() {
return baseColor;
}

/**
* Gets the light shading color of this type.
* @return The light color.
*/
public Color getLightColor() {
return lightColor;
}

/**
* Gets the dark shading color of this type.
* @return The dark color.
*/
public Color getDarkColor() {
return darkColor;
}

/**
* Gets the dimension of this type.
* @return The dimension.
*/
public int getDimension() {
return dimension;
}

/**
* Gets the spawn column of this type.
* @return The spawn column.
*/
public int getSpawnColumn() {
return spawnCol;
}

/**
* Gets the spawn row of this type.
* @return The spawn row.
*/
public int getSpawnRow() {
return spawnRow;
}

/**
* Gets the number of rows in this piece. (Only valid when rotation is 0 or 2,
* but it's fine since this is only used for the preview which uses rotation 0).
* @return The number of rows.
*/
public int getRows() {
return rows;
}

/**
* Gets the number of columns in this piece. (Only valid when rotation is 0 or 2,
* but it's fine since this is only used for the preview which uses rotation 0).
* @return The number of columns.
*/
public int getCols() {
return cols;
}

/**
* Checks to see if the given coordinates and rotation contain a tile.
* @param x The x coordinate of the tile.
* @param y The y coordinate of the tile.
* @param rotation The rotation to check in.
* @return Whether or not a tile resides there.
*/
public boolean isTile(int x, int y, int rotation) {
return tiles[rotation][y * dimension + x];
}

/**
* The left inset is represented by the number of empty columns on the left
* side of the array for the given rotation.
* @param rotation The rotation.
* @return The left inset.
*/
public int getLeftInset(int rotation) {
/*
* Loop through from left to right until we find a tile then return
* the column.
*/
for(int x = 0; x < dimension; x++) {
for(int y = 0; y < dimension; y++) {
if(isTile(x, y, rotation)) {
return x;
}
}
}
return -1;
}

/**
* The right inset is represented by the number of empty columns on the left
* side of the array for the given rotation.
* @param rotation The rotation.
* @return The right inset.
*/
public int getRightInset(int rotation) {
/*
* Loop through from right to left until we find a tile then return
* the column.
*/
for(int x = dimension - 1; x >= 0; x--) {
for(int y = 0; y < dimension; y++) {
if(isTile(x, y, rotation)) {
return dimension - x;
}
}
}
return -1;
}

/**
* The left inset is represented by the number of empty rows on the top
* side of the array for the given rotation.
* @param rotation The rotation.
* @return The top inset.
*/
public int getTopInset(int rotation) {
/*
* Loop through from top to bottom until we find a tile then return
* the row.
*/
for(int y = 0; y < dimension; y++) {
for(int x = 0; x < dimension; x++) {
if(isTile(x, y, rotation)) {
return y;
}
}
}
return -1;
}

/**
* The botom inset is represented by the number of empty rows on the bottom
* side of the array for the given rotation.
* @param rotation The rotation.
* @return The bottom inset.
*/
public int getBottomInset(int rotation) {
/*
* Loop through from bottom to top until we find a tile then return
* the row.
*/
for(int y = dimension - 1; y >= 0; y--) {
for(int x = 0; x < dimension; x++) {
if(isTile(x, y, rotation)) {
return dimension - y;
}
}
}
return -1;
}
}
3 changes: 3 additions & 0 deletions src/org/psnbtech/TileFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public abstract class TileFactory {
public abstract TetrisTile createTile(String type);
}