#import <Foundation/Foundation.h>
#pragma mark - 子弹
@interface Bullet:NSObject
{
@public
NSString *_model;
int _bulletnum;
}
@end
@implementation Bullet
@end
#pragma mark - 枪
@interface Gun :NSObject
{
@public
NSString *_size;
}
-(void)shoot:(Bullet *)bulletnum;
@end
@implementation Gun
-(void)shoot:(Bullet *)bulletnum
{
if(bulletnum->_bulletnum>0)
{
bulletnum->_bulletnum--;
NSLog(@"子弹剩余数量是%d",bulletnum->_bulletnum);
}
else
{
NSLog(@"没有子弹了");
}
}
@end
#pragma mark - 人
@interface Person : NSObject
{
NSString *_name;
}
-(void)kaiqiang:(Gun *)gun and:(Bullet *)bullet;
@end
@implementation Person
-(void)kaiqiang:(Gun *)gun and:(Bullet *)bullet
{
[gun shoot:bullet];
NSLog(@"队长别开枪");
}
@end
int main()
{
Gun *ak=[Gun new];
Bullet *bullet=[Bullet new];
bullet->_bulletnum=2;
Person *wangcai=[Person new];
[wangcai kaiqiang:ak and:bullet];
[wangcai kaiqiang:ak and:bullet];
[wangcai kaiqiang:ak and:bullet];
[wangcai kaiqiang:ak and:bullet];
} |
|