【发布时间】:2012-03-09 20:16:19
【问题描述】:
根据斯坦福大学 Objective-C 课程 Fall 2010/2011,第 3 讲:
typedef struct {
float x;
float y;
} Point;
@interface Bomb
@property Point position;
@end
@interface Ship : Vehicle {
float width, height;
Point center;
}
@property float width;
@property float height;
@property Point center;
- (BOOL)getsHitByBomb:(Bomb *)bomb;
@end
@implementation Ship
@synthesize width, height, center;
- (BOOL)getsHitByBomb:(Bomb *)bomb
{
float leftEdge = self.center.x - self.width/2;
float rightEdge = ...;
return ((bomb.position.x >= leftEdge) &&
(bomb.position.x <= rightEdge) &&
(bomb.position.y >= topEdge) &&
(bomb.position.y <= bottomEdge));
}
@end
为什么界面上没有float leftEdge和float rightEdge?
还有,返回的情况,这意味着如果所有这些情况都正确,则返回YES,否则返回NO(如果情况为真,则返回1,如果为假,则返回0)。对吧?
【问题讨论】:
-
您在退货时是正确的。如果所有的 '&&' 都替换为 '||'如果任何条件为真,它将返回真。 '&&' 确保只有在所有条件都为真时才返回真(在这种情况下,这意味着炸弹击中了船)。
标签: objective-c