iOS shooting games simple code shooter
After that will continue to update, learning students please pay attention to study together
Main.c
#import <Foundation/Foundation.h> #import "Soldier.h" int main (int argc, const char * argv[]) { Soldier *s1 = [[So Ldier Alloc]init]; S1->_life = +; S1->_name = @ "007"; Gun * gun = [[Gun alloc]init]; [S1 Firebygun:gun]; NSLog (@ "%@", S1); NSLog (@ "%d%@", s1->_life,s1->_name); return 0;}
Gun.m
#import "Gun.h" @implementation gun-(void) shoot{ _bulletcount--; NSLog (@ "Number of remaining bullets%d", _bulletcount);} @end
Gun,h
#import <Foundation/Foundation.h> @interface gun:nsobject{ @public number of/** bullets */ int _bulletcount;} Emission-(void) shoot; @end
Soldier.m
#import "Soldier.h" @implementation soldier//shooting-(void) Firebygun: (gun *) Gun; { [gun shoot];//[nil shoot];nil = 0 OC sends a message to nil does not produce an exception} @end
Soldier.h
#import <Foundation/Foundation.h> #import "Gun.h" @interface soldier:nsobject{ @public /** name * / NSString * _name; /** Health Value */ int _life; /** instance variable used to store gun objects */// gun * _gun;} Shot-(void) Firebygun: (Gun *) gun; @end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS shooting games simple code shooter