#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