Play rock and scissors with your computer

Source: Internet
Author: User

#import <Foundation/Foundation.h>

#import "Judge.h"

int main (int argc, const char * argv[]) {

@autoreleasepool {

Judge * Ju=[judge new];

[Ju Caijue];

}

return 0;

}

#import <Foundation/Foundation.h>

@interface Person:nsobject

@property (assign,nonatomic) int ren;

/**

* Declaration with return value

*

* @return string (scissors, stone, cloth)

*/

-(nsstring*) Personuse;

@end

@implementation person

/**

* Achieve

*

* @return NSString Type

*/

-(nsstring*) Personuse

{

NSString *st=[[nsstring Alloc]init];

Switch (Self.ren) {

Case 1:

St=[nsstring stringwithformat:@ "Stone"];

Break

Case 2:

St=[nsstring stringwithformat:@ "Scissors"];

Break

Case 3:

st=[nsstring stringwithformat:@ "cloth"];

Break

Default

Break

}

Return St;

}

@end

#import <Foundation/Foundation.h>

@interface Comepute:nsobject

@property (assign,nonatomic) int ji; Colleagues

-(nsstring*) jisuse;//doujinshi

@end

#import "Comepute.h"

@implementation Comepute

Colleagues

-(NSString *) jisuse

{

NSString *st=[[nsstring Alloc]init];

Switch (Self.ji) {

Case 1:

St=[nsstring stringwithformat:@ "Stone"];

Break

Case 2:

St=[nsstring stringwithformat:@ "Scissors"];

Break

Case 3:

st=[nsstring stringwithformat:@ "cloth"];

Break

Default

Break

}

Return St;

}

@end

#import <Foundation/Foundation.h>

#import "Comepute.h"

#import "Person.h"

#import "Methods.h"

@interface Judge:methods

-(void) Caijue;

@end

#import "Judge.h"

@implementation Judge

-(void) Caijue

{

int a=1, I;

while (a==1| | a==2| | a==3) {

NSLog (@ "Please enter the way: Scissors stone 2--scissors 3--cloth");

scanf ("%d", &a);

if (a==1| | a==2| | a==3) {

Person *per=[[person Alloc]init];

Per.ren=a;

NSLog (@ "person out is:%@", [per Personuse]);

Comepute *com=[comepute New];

Com.ji=arc4random ()%3+1;

NSLog (@ "Computer out of:%@", [COM jisuse]);

[Super Personwithperson:per.ren Andcomeputerwithcomputer:com.ji];

i++;

}

else{

NSLog (@ "input error, end of game");

}

}

NSLog (@ "scissors number of times is:%d wins the number of times is:%d computer wins the number of times:%d draw:%d", i,super.rensheng,super.jisuansheng,i-(super.rensheng+ Super.jisuansheng));

}

@end

#import <Foundation/Foundation.h>

#import "Person.h"

#import "Comepute.h"

@interface Methods:nsobject

@property (assign,nonatomic) int rensheng;

@property (assign,nonatomic) int jisuansheng;

-(void) Personwithperson: (int) a andcomeputerwithcomputer: (int) b;

@end

#import "Methods.h"

@implementation Methods

-(void) Personwithperson: (int) a andcomeputerwithcomputer: (int) b

{

if ((a==1&&b==3) | | | (a==2&&b==1) | | (a==3&&b==2)) {

NSLog (@ "computer wins");

self.jisuansheng++;

} else if ((a==1&&b==2) | | | (a==2&&b==3) | | (a==3&&b==1)) {

NSLog (@ "man wins");

self.rensheng++;

} else{

NSLog (@ "Draw");

}

}

@end

Play rock and scissors with your computer

Related Article

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.