iOS shooting games simple code shooter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.