這真是一個愚蠢的問題,但我已經在這個問題的方式一直盯着太久,我只是無法弄清楚的問題是什麼:幫助有簡單的方法,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