import processing.net.*; Server myServer = new Server( this, 6666 ); int unitSize = 8; int ux; int uy; int [][] unit; void setup() { size( 800, 800 ); ux = width / unitSize; uy = height / unitSize; unit = new int [ux][uy]; for ( int i=0; i 0 ) { if ( unit[x][y] == 1 ) { fill( 255, 0, 0 ); } else if ( unit[x][y] == 2 ) { fill( 0, 0, 255 ); } } else { fill( 255 ); } rect( x*unitSize, y*unitSize, unitSize, unitSize ); } } } void mousePressed() { int x = mouseX / unitSize; int y = mouseY / unitSize; int id = 1; if ( mouseButton == LEFT ) { id = 1; } else if ( mouseButton == RIGHT ) { id = 2; } unit[x][y] = id; for ( int i=-1; i<=1; i++ ) { for ( int j=-1; j<=1; j++ ) { if ( i==0 && j==0 ) { } else { isHit( id, x, y, i, j ); } } } } boolean isHit( int id, int x, int y, int dx, int dy ) { x += dx; y += dy; if ( x < 0 || x >= ux || y < 0 || y >= uy ) { return false; } if ( unit[x][y] == 0 ) { return false; } if ( unit[x][y] == id ) { return true; } boolean bRet = isHit( id, x, y, dx, dy ); if ( bRet == true ) { unit[x][y] = id; } return bRet; } int getR(int i) { int ret = 0; if (i < 128) { ret = 0; } else if (i > 127 && i < 191) { ret = (i-127)*4; } else if (i > 190) { ret = 255; } return ret; } int getG(int i) { int ret = 0; if (i >= 64 && i <= 191) { ret = 255; } else if (i < 64) { ret = i * 4; } else { ret = 256-(i-191)*4; } return ret; } int getB(int i) { int ret = 0; if (i <= 64) { ret = 255; } else if (i > 64 && i < 127) { ret = 255-(i-64)*4; } else if (i >= 127) { ret = 0; } return ret; }