【发布时间】:2014-06-08 18:41:30
【问题描述】:
首先,对不起我的英语,我是法国人。
这是我试图通过用数学符号写出这个问题来解决的问题:
我有几个坐标看起来像这样:(x, y)
An = {(Xn;Yn)}
array[An][(Xn;Yn)] = {{X1;Y1}{X2;Y2}...{Xz;Yz}};
在我的程序中,我需要为多维数组创建一个 getter 和 setter。
这是我的代码:
//Infos for animations of objects
//Sorting
Random random1 = new Random();
int obscMin=0, obscMax=4; //I sort them to know how many obstacles will have to be created. obsc is the obstacle
int nbreObsc = obscMin + random1.nextInt(obscMax - obscMin); //nbreObsc is the number of obstacles
//End of sorting
/*Here's the model of a table:
A couple: An={(Xn;Yn)}
Tableau1[An][(Xn;Yn)]={{X1;Y1}{X2;Y2}...{Xz;Yz}};*/
float posObsc [] []=new float [nbreObsc] [2]; //New table, which will contain the positions of the obstacles
//Obstacle position getter and setter
public float[][] getPosObsc(){//getters
return posObsc;
}
public void setPosObsc(float[][] posObsc){//setters
this.posObsc=posObsc;
}
//End of obstacle position getter and setter
protected boolean detruireObsc=false; //"detruireObsc" means "destroyObstacle"
//Algorithm that defines the movement of obstacles
protected void obscDeplacemt(){
for(int i=1;i<=nbreObsc;i++){
//Sorting to determine the Xs
float ordMin=0,ordMax=width;
float ordObsc = ordMin + (float)Math.random() * (ordMax - ordMin); //ordObsc means obstacleXPosition
setPosObsc( posObsc [i][0]);
//End of sorting
}
}
//End of obstacle movement algorithm
这是我从 eclipse 得到的错误:
The method setPosObsc(float[][]) in the type Activity01Jeux.RenderViewJoueur is not applicable for the arguments (float)
【问题讨论】:
-
你介意我把 cmets 翻译成英文吗? Est-ce-que ça vous dérangerait si je traduirais vos commentaires du code en Anglais?
-
请提供可编译的代码。
-
@Runemoro//Absolumt pas c'est avec grd plaisir! Traduit traduit et traduit encore :p
-
@Runemoro//Je voulais dire absolument tu peux!
-
@Pif Paf Pouf:Je sais 等。 :P
标签: java arrays methods get set