#import <Foundation/Foundation.h>
@interface Computer:nsobject
@property (assign,nonatomic) int comcount;
-(int) punches;//Punch
@end
#import "Computer.h"
@implementation Computer
-(int) punches
{
int num=arc4random ()%3+1;//randomly generates a value of 1-3
Switch (NUM)
{
Case 1:
NSLog (@ "The computer is out of stone");
Break
Case 2:
NSLog (@ "Computer out of Scissors");
Break
Case 3:
NSLog (@ "Computer is out of cloth");
Break
Default
Break
}
return num;
}
@end
#import <Foundation/Foundation.h>
@interface Person:nsobject
@property (assign,nonatomic) int percount;
-(int) punches;
-(int) Playcompare: (int) computer and:(int) person;
@end
#import "Person.h"
@implementation person
Types of Punches
-(int) punches
{
int num1;
NSLog (@ "Please punch:1--> stone,2--> scissors,3--> cloth");
scanf ("%d", &num1);
Switch (NUM1)
{
Case 1:
NSLog (@ "You're out of stone! ");
Break
Case 2:
NSLog (@ "You're out of scissors! ");
Break
Case 3:
NSLog (@ "You're out of cloth! ");
Break
Default
Break
}
return NUM1;
}
A comparison between the method of punching and the method of computer random punch
-(int) Playcompare: (int) computer and: (int) person
{
if ((computer==1&&person==2) | | | (computer==2&&person==3) | | (computer==3&&person==1))
{
NSLog (@ "Computer wins! ");
return-1;
}
else if (Computer==person)
{
NSLog (@ "Draw");
return 0;
}
Else
{
NSLog (@ "Congratulations: you won!" ");
return 1;
}
}
@end
#import <Foundation/Foundation.h>
#import "Computer.h"
#import "Person.h"
int main (int argc, const char * argv[])
{
@autoreleasepool
{
Computer *computer=[computer new];
Person *person=[person new];
int count=0;
int num2;
for (int i=0; i<=20; i++)
{
int First=[person punches];
int Second=[computer punches];
int Third=[person Playcompare:first And:second];
if (third==1)
{
Person. percount++;
}
if (third==2)
{
computer.comcount++;
}
NSLog (@ "1--> continues 0--> end");
scanf ("%d", &num2);
count++;
NSLog (@ "A total of%d innings", count);
NSLog (@ "man wins%d innings, computer wins%d innings", person.percount,computer.comcount);
}
}
return 0;
}
Scissors Stone cloth (man-machine battle)