From 701f21908f1c910b39539d333308c490657bd5f5 Mon Sep 17 00:00:00 2001 From: gumartinm Date: Sun, 6 Nov 2011 03:58:17 +0100 Subject: [PATCH] First steps drawing pieces and using enum classes. It works!! --- .../src/de/android/androidtetris/DrawView.java | 45 +++++++++++++--------- .../src/de/android/androidtetris/Piece.java | 17 ++++++-- .../src/de/android/androidtetris/Tile.java | 6 +++ 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/AndroidTetris/src/de/android/androidtetris/DrawView.java b/AndroidTetris/src/de/android/androidtetris/DrawView.java index 26829e1..b4b4e79 100644 --- a/AndroidTetris/src/de/android/androidtetris/DrawView.java +++ b/AndroidTetris/src/de/android/androidtetris/DrawView.java @@ -21,19 +21,13 @@ public class DrawView extends SurfaceView { int position = 150; private SurfaceHolder holder; private AndroidTetrisThread gameLoopThread; - private int x = 0; + private int y = 0; private static final int TILESIZE=16; //now for the map... private static final int MAPWIDTH=10; private static final int MAPHEIGHT=30; private static final int GREY=8; - - private enum TileColor - { - TILENODRAW,TILEBLACK,TILEGREY,TILEBLUE,TILERED, - TILEGREEN,TILEYELLOW,TILEWHITE,TILESTEEL,TILEPURPLE; - } /** Indicate whether the surface has been created & is ready to draw */ private boolean mRun = false; @@ -77,7 +71,7 @@ public class DrawView extends SurfaceView { } } - /** + /** * Fetches the animation thread corresponding to this LunarView. * * @return the animation thread @@ -90,7 +84,7 @@ public class DrawView extends SurfaceView { public DrawView(Context context) { super(context); - this.resetTiles(8); + this.resetTiles(9); for (Tile color : Tile.values() ) { this.loadTile(color.getColor(), color.getColorRGBA()); @@ -150,18 +144,31 @@ public class DrawView extends SurfaceView { @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.BLACK); - int aux = 10; + int aux = 0; - for (Bitmap bitmap : tileArray) + //for (Bitmap bitmap : tileArray) + //{ + // if (y < this.getHeight() - bitmap.getHeight()) + // { + // y++; + // } + // else + // y = 0; + // canvas.drawBitmap(bitmap, aux, y, null); + // aux = aux + 20; + //} + + //draw moving block + for (Piece piece : Piece.values()) { - if (x < this.getHeight() - bitmap.getHeight()) - { - x++; - } - else - x = 0; - canvas.drawBitmap(bitmap, aux, x, null); - aux = aux + 20; + for(int xmy=0; xmy<4; xmy++) + for(int ymx=0; ymx<4; ymx++) + if(piece.size[xmy][ymx] != Tile.NOCOLOR) + canvas.drawBitmap(tileArray[piece.size[xmy][ymx].getColor()], + piece.x+(xmy*TILESIZE), piece.y+aux+(ymx*TILESIZE), null); + aux = aux + 64; } + + } } \ No newline at end of file diff --git a/AndroidTetris/src/de/android/androidtetris/Piece.java b/AndroidTetris/src/de/android/androidtetris/Piece.java index 8ecb1bd..c5b28b9 100644 --- a/AndroidTetris/src/de/android/androidtetris/Piece.java +++ b/AndroidTetris/src/de/android/androidtetris/Piece.java @@ -82,11 +82,13 @@ public enum Piece { } }; - private static Tile[][] size = new Tile[4][4]; + private static final int WIDTH = 4; + private static final int HEIGHT = 4; + public Tile[][] size = new Tile[WIDTH][HEIGHT]; //Store the x coordinate (the position of this piece on the grid) - private int x; + public int x; //Store the y coordinate (the position of this piece on the grid) - private int y; + public int y; private final int pieceNumber; private static final Map pieceMap = new HashMap(); @@ -100,6 +102,15 @@ public enum Piece { private Piece (int pieceNumber) { this.pieceNumber = pieceNumber; + this.y = 10; + this.x = 10; + + //Pre-Initialization of size matrix + for (int i=0; i< WIDTH; i++) + for (int j=0; j< WIDTH; j++) + size[i][j]= Tile.NOCOLOR; + + this.refill(); } public Piece getPiece (int pieceNumber) diff --git a/AndroidTetris/src/de/android/androidtetris/Tile.java b/AndroidTetris/src/de/android/androidtetris/Tile.java index a0e2b3e..4cf309d 100644 --- a/AndroidTetris/src/de/android/androidtetris/Tile.java +++ b/AndroidTetris/src/de/android/androidtetris/Tile.java @@ -54,6 +54,12 @@ public enum Tile { int getColorRGBA() { return Color.GRAY; } + }, + NOCOLOR(8) { + @Override + int getColorRGBA() { + return Color.TRANSPARENT; + } }; private int color; -- 2.1.4