cool01
Member level 2
![Member level 2](/styles/images/ranks/dlevel2.gif)
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import java.util.Vector;
import java.lang.Integer;
public class BrainCanvas extends Canvas implements Runnable{
///////////////////////////////Declaration////////////////////////////////////////
private Main midlet = null;Thread myThread = null;
public int canvasW,canvasH;
private Display display;
public final int UP=-1,DOWN=-2,LEFT=-3,RIGHT=-4,ENTER=-5;
// public static int p=-7,q=-7,newP=-7,newQ=-7,dir;
public int a[][]= {{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},};
public int b[][]= {{20,20,20,20,20,20,20},
{40,40,40,40,40,40,40},
{60,60,60,60,60,60,60},
{80,80,80,80,80,80,80},
{100,100,100,100,100,100,100},
{120,120,120,120,120,120,120},
{140,140,140,140,140,140,140}};
// public int value[][]={{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,2,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1}};
public int value[][]={{0,0,1,1,1,0,0},{0,0,1,1,1,0,0},{1,1,1,1,1,1,1},{1,1,1,2,1,1,1},{1,1,1,1,1,1,1},{0,0,1,1,1,0,0},{0,0,1,1,1,0,0}};
public int width=20;
public int empty=2;
public int select0=3;
public int select=3;
public int select1=4;
boolean flag=true;
int x=60,y=60;
int count=0;
public BrainCanvas(Main midlet){
try{
setFullScreenMode(true);
this.midlet = midlet;
canvasW = getWidth();
canvasH = getHeight();
this.startThread();
}catch(Exception e){}
}
public boolean startThread() {
System.out.println("in start thread");
boolean retVal = false;
try {
myThread = new Thread(this);
myThread.start();
retVal = true;
} catch(Exception e) {
}
return retVal;
}
void initialise() {
a[][]= {{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},};
b[][]= {{20,20,20,20,20,20,20},
{40,40,40,40,40,40,40},
{60,60,60,60,60,60,60},
{80,80,80,80,80,80,80},
{100,100,100,100,100,100,100},
{120,120,120,120,120,120,120},
{140,140,140,140,140,140,140}};
value[][]={{0,0,1,1,1,0,0},{0,0,1,1,1,0,0},{1,1,1,1,1,1,1},{1,1,1,2,1,1,1},{1,1,1,1,1,1,1},{0,0,1,1,1,0,0},{0,0,1,1,1,0,0}};
width=20;
empty=2;
select0=3;
select1=4;
flag=true;
x=60;y=60;
count=0;
}
public void run(){
System.out.println("in run");
try{
while(true){
myThread.sleep(100);
initialise();
repaint();
}
} catch(Exception e){}
}
public void paint(Graphics g) {
drawmyrect(g);
drawGrid(g);
g.setColor(0,0,255);
g.fillRect(x,y,20,20);
g.setColor(0,255,0);
}
public void keyPressed(int keyCode) {
int i=0,j=0;
if(x>1 && y>1) {
j=(x/width)-1;
i=(y/width)-1;
}
switch(keyCode) {
case -1:
{
if(((x>=20 && x<=40) && y>60 || y>20 && (x>=60 && x<=100)|| y>60 && (x>100 && x<=140)))
y-=20;
}
break;
case -2:
{
if(((x>=20 && x<=40) && y<100 || y<140 && (x>=60 && x<=100)|| y<100 && (x>100 && x<=140)))
y+=20;
}
break;
case -3:
{
if((x>20 && (y>=60 && y<=100))|| x>60 && (y>=20 && y<=40)|| x>60 &&(y>100 && y<=140) )
x-=20;
// System.out.println(x+" in 4 "+y);
}
break;
case -4:
{
if(((y>=20 && y<=40) && x<100 || x<140 && (y>=60 && y<=100)|| x<100 && (y>100 && y<=140)))
x+=20;
}
break;
case -5:
{
System.out.println("back frm check");
if(value[j]==1) {
flag=true;
check();
value[j]=select;
flag=false;
System.out.println("in falg false");
}
if(flag==false) {
if(value[j]==empty) {
value[j]=select1;
Game(i,j);
}
}
if(value[j]==select1){
value[j]=empty;
}
}
break;
}
}
int check() {
System.out.println("in check");
for (int i = 0; i < value.length-1; i++){
for (int j= 0; j < value.length-1; j++){
if(value[j]==select) {
System.out.println("in falg true"+i+" j "+j);
value[j]=1;
}
}
}
return 0;
}
public void clearscreen(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
}
public void drawmyrect(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,canvasW,canvasH);
}
public void drawGrid(Graphics g) {
for(int i=0;i<7;i++) {
for(int j=0;j<7;j++) {
g.drawRect(a[j],b[j],19,19);
}
}
for(int i=0;i<7;i++) {
for(int j=0;j<7;j++) {
if(value[j]==1) {
g.setColor(250,50,250);
g.fillRect(a[j],b[j],19,19);
}
if(value[j]==0) {
g.setColor(255,255,255);
g.fillRect(a[j],b[j],19,19);
}
if(value[j]==empty) {
g.setColor(255,250,0);
g.fillRect(a[j],b[j],19,19);
}
if(value[j]==select) {
g.setColor(0,255,0);
g.fillRect(a[j],b[j],19,19);
}
int count=0;
if(value[j]==select)
count++;
if(count>46) {
g.setColor(0,255,0);
g.drawString("player win",20,20,0);
}
}
}
}
public void Game(int i,int j) {
if(value[j]==select1){
if( (i>=0 && i<6 && j+2<6 && j+2>=0) && value[j+1]==1 && value[j+2]==select){
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[j+1]=empty;
value[j+2]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[i+1][j] "+value[j]+" value[i+2][j] "+value[i+2][j]);
} else if( (i+2>=0 && i+2<6 && j<6 && j>=0) && value[i+1][j]==1 && value[i+2][j]==select ) {
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[i+1][j]=empty;
value[i+2][j]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[j+1] "+value[j+1]+" value[j+2] "+value[j+2]);
} else if( (i>=0 && i<6 && j-2<6 && j-2>=0) &&value[j-1]==1 && value[j-2]==select) {
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[j-1]=empty;
value[j-2]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[i-1][j] "+value[i-1][j]+" value[i-2][j] "+value[i-2][j]);
}else if( (i-2>=0 && i-2<6 && j<6 && j>=0) &&value[i-1][j]==1 && value[i-2][j]==select) {
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[i-1][j]=empty;
value[i-2][j]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[j-1] "+value[j-1]+" value[j-2] "+value[j-2]);
}
}
}
}
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import java.util.Vector;
import java.lang.Integer;
public class BrainCanvas extends Canvas implements Runnable{
///////////////////////////////Declaration////////////////////////////////////////
private Main midlet = null;Thread myThread = null;
public int canvasW,canvasH;
private Display display;
public final int UP=-1,DOWN=-2,LEFT=-3,RIGHT=-4,ENTER=-5;
// public static int p=-7,q=-7,newP=-7,newQ=-7,dir;
public int a[][]= {{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},};
public int b[][]= {{20,20,20,20,20,20,20},
{40,40,40,40,40,40,40},
{60,60,60,60,60,60,60},
{80,80,80,80,80,80,80},
{100,100,100,100,100,100,100},
{120,120,120,120,120,120,120},
{140,140,140,140,140,140,140}};
// public int value[][]={{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,2,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1}};
public int value[][]={{0,0,1,1,1,0,0},{0,0,1,1,1,0,0},{1,1,1,1,1,1,1},{1,1,1,2,1,1,1},{1,1,1,1,1,1,1},{0,0,1,1,1,0,0},{0,0,1,1,1,0,0}};
public int width=20;
public int empty=2;
public int select0=3;
public int select=3;
public int select1=4;
boolean flag=true;
int x=60,y=60;
int count=0;
public BrainCanvas(Main midlet){
try{
setFullScreenMode(true);
this.midlet = midlet;
canvasW = getWidth();
canvasH = getHeight();
this.startThread();
}catch(Exception e){}
}
public boolean startThread() {
System.out.println("in start thread");
boolean retVal = false;
try {
myThread = new Thread(this);
myThread.start();
retVal = true;
} catch(Exception e) {
}
return retVal;
}
void initialise() {
a[][]= {{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},
{20,40,60,80,100,120,140},};
b[][]= {{20,20,20,20,20,20,20},
{40,40,40,40,40,40,40},
{60,60,60,60,60,60,60},
{80,80,80,80,80,80,80},
{100,100,100,100,100,100,100},
{120,120,120,120,120,120,120},
{140,140,140,140,140,140,140}};
value[][]={{0,0,1,1,1,0,0},{0,0,1,1,1,0,0},{1,1,1,1,1,1,1},{1,1,1,2,1,1,1},{1,1,1,1,1,1,1},{0,0,1,1,1,0,0},{0,0,1,1,1,0,0}};
width=20;
empty=2;
select0=3;
select1=4;
flag=true;
x=60;y=60;
count=0;
}
public void run(){
System.out.println("in run");
try{
while(true){
myThread.sleep(100);
initialise();
repaint();
}
} catch(Exception e){}
}
public void paint(Graphics g) {
drawmyrect(g);
drawGrid(g);
g.setColor(0,0,255);
g.fillRect(x,y,20,20);
g.setColor(0,255,0);
}
public void keyPressed(int keyCode) {
int i=0,j=0;
if(x>1 && y>1) {
j=(x/width)-1;
i=(y/width)-1;
}
switch(keyCode) {
case -1:
{
if(((x>=20 && x<=40) && y>60 || y>20 && (x>=60 && x<=100)|| y>60 && (x>100 && x<=140)))
y-=20;
}
break;
case -2:
{
if(((x>=20 && x<=40) && y<100 || y<140 && (x>=60 && x<=100)|| y<100 && (x>100 && x<=140)))
y+=20;
}
break;
case -3:
{
if((x>20 && (y>=60 && y<=100))|| x>60 && (y>=20 && y<=40)|| x>60 &&(y>100 && y<=140) )
x-=20;
// System.out.println(x+" in 4 "+y);
}
break;
case -4:
{
if(((y>=20 && y<=40) && x<100 || x<140 && (y>=60 && y<=100)|| x<100 && (y>100 && y<=140)))
x+=20;
}
break;
case -5:
{
System.out.println("back frm check");
if(value[j]==1) {
flag=true;
check();
value[j]=select;
flag=false;
System.out.println("in falg false");
}
if(flag==false) {
if(value[j]==empty) {
value[j]=select1;
Game(i,j);
}
}
if(value[j]==select1){
value[j]=empty;
}
}
break;
}
}
int check() {
System.out.println("in check");
for (int i = 0; i < value.length-1; i++){
for (int j= 0; j < value.length-1; j++){
if(value[j]==select) {
System.out.println("in falg true"+i+" j "+j);
value[j]=1;
}
}
}
return 0;
}
public void clearscreen(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
}
public void drawmyrect(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,canvasW,canvasH);
}
public void drawGrid(Graphics g) {
for(int i=0;i<7;i++) {
for(int j=0;j<7;j++) {
g.drawRect(a[j],b[j],19,19);
}
}
for(int i=0;i<7;i++) {
for(int j=0;j<7;j++) {
if(value[j]==1) {
g.setColor(250,50,250);
g.fillRect(a[j],b[j],19,19);
}
if(value[j]==0) {
g.setColor(255,255,255);
g.fillRect(a[j],b[j],19,19);
}
if(value[j]==empty) {
g.setColor(255,250,0);
g.fillRect(a[j],b[j],19,19);
}
if(value[j]==select) {
g.setColor(0,255,0);
g.fillRect(a[j],b[j],19,19);
}
int count=0;
if(value[j]==select)
count++;
if(count>46) {
g.setColor(0,255,0);
g.drawString("player win",20,20,0);
}
}
}
}
public void Game(int i,int j) {
if(value[j]==select1){
if( (i>=0 && i<6 && j+2<6 && j+2>=0) && value[j+1]==1 && value[j+2]==select){
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[j+1]=empty;
value[j+2]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[i+1][j] "+value[j]+" value[i+2][j] "+value[i+2][j]);
} else if( (i+2>=0 && i+2<6 && j<6 && j>=0) && value[i+1][j]==1 && value[i+2][j]==select ) {
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[i+1][j]=empty;
value[i+2][j]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[j+1] "+value[j+1]+" value[j+2] "+value[j+2]);
} else if( (i>=0 && i<6 && j-2<6 && j-2>=0) &&value[j-1]==1 && value[j-2]==select) {
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[j-1]=empty;
value[j-2]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[i-1][j] "+value[i-1][j]+" value[i-2][j] "+value[i-2][j]);
}else if( (i-2>=0 && i-2<6 && j<6 && j>=0) &&value[i-1][j]==1 && value[i-2][j]==select) {
System.out.println("i "+i+" j "+j+" x "+x+" y "+y);
value[j]=1;
value[i-1][j]=empty;
value[i-2][j]=empty;
// System.out.println("i "+i+" j "+j);
// System.out.println("x "+x+" y "+y);
// System.out.println("value[j] "+value[j]+" value[j-1] "+value[j-1]+" value[j-2] "+value[j-2]);
}
}
}
}