CodeSnippet:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import javax.microedition.lcdui.*; /** * * @author mirrakor */ public GCanvas() { super(); } int height = getHeight(); int width = getWidth(); int sidepanelwidth=0; int cellwidth=0; int cellheight=0; final int NUM_OF_ROWS = 20; final int NUM_OF_COLS = 10; int field[][] = new int[][] { {1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1} }; // [X][Y] [10][20] // For Regular phones, this works :) sidepanelwidth = width - (height/2); cellwidth = (width-sidepanelwidth)/NUM_OF_COLS; cellheight = height/NUM_OF_ROWS; g.setColor(0xFFFFFF); // WHITE g.fillRect(0, 0, width, height); // clear the screen with WHITE // for the start we only color the pieces in one color (later we can simply change this behaviour by assinging different numbers in the array, IMPORTANT IS, that 0 is NO BLOCK! g.setColor(255, 0, 0); // testdraw our array for(int i=0; i<NUM_OF_COLS; i++){ // for better readability we leave the 10, although it only goes from 0-9! for(int j=0; j<NUM_OF_ROWS; j++){ if(field[i][j]==1){ g.fillRect(i*cellwidth, j*cellheight, cellwidth, cellheight); } } } // grey bottom block g.setColor(0x8D8D8D); g.fillRect(0, NUM_OF_ROWS*cellheight, NUM_OF_COLS*cellwidth, height-(NUM_OF_ROWS*cellheight)); g.setColor(0x000000); // BLACK // draw vertical lines (Senkrecht :D) for(int i=1; i<=NUM_OF_COLS; i++){ g.drawLine(i*cellwidth, 0, i*cellwidth, height); } // draw horizontal lines for(int i=1; i<=NUM_OF_ROWS; i++){ g.drawLine(0, i*cellheight, NUM_OF_COLS*cellwidth, i*cellheight); } g.drawString(\"Height: \"+height+\" Width: \"+width, 50, 50, 0); } }
|