
09-12-2008, 09:30
|
 |
|
|
חבר מתאריך: 10.06.06
הודעות: 452
|
|
|
בעיה בתוכנית בJAVA
בתוכנית יש לי שגיאת קוד הבא
Cannot make a static reference to the non-static field v.board.a
במחלקה :
public class pawn extends pice{
בשורה:
if (v.board.a[x][y].empty==0) return false;
הקוד המלא הוא:
קוד:
/*vitaly menchikovsky
* this program is
*
*
*
*
*
*
*/
import javax.swing.JOptionPane;
public class v {
int picename;
boolean isempty(){return true;}//need a body of the function
public class board extends pice {
pice a[][]=new pice[8][8];//the board 8*8
String player,player2;
boolean get(){return true;};//need a body of the function
board(){
int i,j;
for(i=0;i<8;i++)
for(j=0;j<8;j++){
//0 white ,1 black
this.a[i][j].i=i;
this.a[i][j].j=j;
if ((i%2==0) && (j%2==0)) this.a[i][j].color=1;
if ((i%2==0) && (j%2==1)) this.a[i][j].color=0;
if ((i%2==1) && (j%2==0)) this.a[i][j].color=0;
if ((i%2==1) && (j%2==1)) this.a[i][j].color=1;
if ((i==0) | (i==1) | (i==6) | (i==7)) this.a[i][j].empty=1;
this.a[i][j].empty=0;
}
}
}
public class pice{
int color; //color of pice
int empty;
int i,j;
/*void cheikpice(String color,String name){
if ((color.equals("black") && (color.equals("white"))== false))
JOptionPane.showMessageDialog(null,"error color, only white or black ");
if (color.equals("black")) this.isblack=1;
if (color.equals("white")) this.isblack=0;
switch(name){
case 'pawn':
break;
case 'knight':
break;
case 'rook':
break;
case 'queen':
break;
case 'king':
break;
case 'null':
break;
default:JOptionPane.showMessageDialog(null,"error");
}
boolean move( ){return true;};//need a body of the function
boolean chekColor(){return true;};
*/
}
public class pawn extends pice{
boolean move(int x,int y){
if ((x<0) | (x>7)) return false;
if (v.board.a[x][y].empty==0) return false;
}
}
public class knight extends pice {
boolean move(){return true;};
}
public class bichop extends pice {
boolean move(){return true;};
}
public class rook extends pice {
boolean move(){return true;};
}
public class queen extends pice {
boolean move(){return true;};
}
public class king extends pice {
boolean move(){return true;};
}
// TODO Auto-generated constructor stub
/**
* @param args
*/
public static void main(String[] args) {
JOptionPane.showMessageDialog(null,"vitaly menchikovsky 312044662");
}}
_____________________________________

לגלריה
|