Canvas Demo 3

Aus ProgrammingWiki
Archivierte Version vom 2009-04-30T06:06:39+00:00. Aktuelle Version

<eval> int[][] Spielfeld = new int[20][10]; Spielfeld[0][0] = 0; Spielfeld[1][1] = 1; Spielfeld[2][2] = 1;</eval>

void drawCell(int x, int y, boolean black){

 if(black) canvas.setColor(0,0,0); else 
           canvas.setColor(255,255,255);
 canvas.fillRect(x*25,y*25,25,25);           

}

void drawCells(){

 for(int x=0; x<20; x++)
  for(int y=0; y<10; y++)
   drawCell(x,y,Spielfeld[x][y] == 1);

}

void flipCells(){

 for(int x=0; x<20; x++)
  for(int y=0; y<10; y++)
   if (Spielfeld[x][y] == 1){
    Spielfeld[x][y] = 0;
    if(x>0) Spielfeld[x-1][y] = 1; 
    if(x<20) Spielfeld[x+1][y] = 1; 
    if(y>0) Spielfeld[x][y-1] = 1; 
    if(y<20) Spielfeld[x][y+1] = 1; 
   }

}


canvas.clear();

drawCells(); flipCells(); drawCells();

Ihr Browser unterstützt Canvas nicht.