MRC Implementation Scissors Game (attached: @property Understanding deviation correction)

Source: Internet
Author: User
Tags rewind

1 /*Scissors Games2 Object 1: Person, attribute: Enter the punch to show, score, name3 object 2:bot, Attributes ibid., inheritance. Automatic generation of Punch, enumeration method. Show the punch, compare the punch with the person passing it, judge the result and output the score. 4 Other: Each time a comparison prompts whether to continue. 5  6 Note: mrc! 7  */8 9 #import<Foundation/Foundation.h>Ten #import "Bot.h" One intMainintargcConst Char*argv[]) A { -person* P1 =[[Person alloc]init]; -P1.name =@"Jack"; theP1.score =0; -      -bot* B1 =[[Bot alloc]init]; -B1.score =0; +     CharFlag =0; -      +      Do A     { at [P1 fistsltandshow]; - [B1 FISTSLTANDSHOW:P1]; -NSLog (@"Press y to continue, press N to end. "); - Rewind (stdin); -scanf"%c",&flag); -} while(Flag! ='N'&& Flag! ='N'); in      - [B1 release]; to [P1 release]; +     return 0; - } the //Person.h * #import<Foundation/Foundation.h> $typedefenumPanax Notoginseng { -Kjiandao =1, the Kshitou, + KBu A }fist; the  + @interfacePerson:nsobject -@property (nonatomic, retain) nsstring*name; $@property (nonatomic, assign)intscore; $ @property (nonatomic, assign) Fist Fist; -- (void) fistsltandshow; - @end the // - //person.mWuyi  the #import "Person.h" -  Wu @implementation Person -- (void) Dealloc About { $NSLog (@"man hung Up"); - [_name release]; - [Super Dealloc]; - } A- (void) Fistsltandshow + { the      Do -     { $NSLog (@"Please choose the punch: 1-scissors, 2-stone, 3-cloth"); the_fist =-1; the Rewind (stdin); thescanf"%d",&_fist); the} while(_fist <1|| _fist >3); -NSLog (@"%@ Punch for:%@", _name, (_fist = =1)?@"Scissors":(_fist = =2?@"Stone":@"cloth")); in } the @end the //Bot.h About #import "Person.h" the  the @interfaceBot:person the- (void) Fistsltandshow: (person*) person; + @end - // the //BOT.MBayi #import "Bot.h" the #import<stdlib.h> the @implementationBot -- (void) Fistsltandshow: (person*) Person - { theSelf.fist = Arc4random_uniform (3) +1; theNSLog (@"bot out fist:%@", (self.fist = =1)?@"Scissors":(Self.fist = =2?@"Stone":@"cloth")); the     if(Self.fist-person.fist = =1)|| (-2= = Self.fist-person.fist))//1-3 2-1 3-2 the     { -self.score++; theNSLog (@"bot wins."); the}Else if(0= = Self.fist-person.fist) the     {94NSLog (@"Draw"); the}Else the     { theperson.score++;98NSLog (@"%@ won.", person.name); About     } -NSLog (@"%@:%d-----bot:%d", Person.name, Person.score, self.score);101 }102- (void) Dealloc103 {104NSLog (@"bot hung up"); the [Super Dealloc];106 }107 @end

Fellow Warwick PPT photo sharing:

MRC Implementation Scissors Game (attached: @property Understanding deviation correction)

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.