这真是一个愚蠢的问题,但我已经在这个问题的方式一直盯着太久,我只是无法弄清楚的问题是什么:帮助有简单的方法,Java的
/**
* public boolean overlap(int targetX, int targetY) {
* Returns true if the target position is sufficient close to this ghost
* If target position is 16 pixels or less in the x direction
* and similarly in y direction, return true. Otherwise return false
*
* @param targetX
* @param targetY
* @return
*/
public boolean overlap(int targetX, int targetY){
double x=this.getX();
double y=this.getY();
double deltaX=targetX-x;
double deltaY=targetY-y;
if(deltaX<=16 && deltaX>=0 && deltaY<=16 && deltaY>=0)
return true;
else
return false;
}
这应该工作对?但它没有。如果我运行这个测试,它会失败assertTrue。 (g1.x = 100和g1.y = 1000)
double theta = 2 * Math.PI * Math.random();
int x = 100 + (int) (16 * Math.cos(theta));
int y = 1000 + (int) (16 * Math.sin(theta));
assertTrue(g1.overlap(x, y));
有人看到我不喜欢的东西吗?
在这个测试用例中,g1.getX()和g1.getY()的值是什么? – marcosbeirigo 2010-10-16 02:23:40
哦对不起,他们x = 100和y = 1000 – Snowman 2010-10-16 02:26:08