java problem 3

2012-11-07 9:17 am
I wrote the following code.But there is some errors.
private void randomShuffleChessPieces() {
for (int y1=0; y1< 7 ;y1++) {
for (int x1=0; x1<7;x1++) {
int rn = GWorld.random(0,31);
int yn = GWorld.random(0,31);
int x2=rn;
int y2=yn;
shuffleTwoChessPieces(x1,y1,x2,y2);
}
}

}
private void shuffleTwoChessPieces(int x1, int y1, int x2, int y2) {
Chess c1 = (Chess) GWorld.getOneObjectAt(x1,y1,"Chess");
Chess c2 = (Chess) GWorld.getOneObjectAt(x2,y2,"Chess");
setLocation(x1,y1);
setLocation(x2,y2);
//It told me that it cannot find the method setLocation.However,I do not understand what is wrong with it
}

回答 (1)

2012-11-07 7:47 pm
✔ 最佳答案
Did you write the Chess class??
Did you write the method setLocation(x,y); in the Chess class?

If you already wrote the code of above, you may call the method:

c1. setLocation(x1,y1);
c2. setLocation(x2,y2);
參考: myself


收錄日期: 2021-04-29 18:26:59
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20121107000051KK00032

檢視 Wayback Machine 備份