前言
这是一个猜拳游戏,玩家选择想要出的拳头:1 剪刀 2 石头 3 布, 机器人随机出拳头, 裁判宣布比赛结果,并为胜利者加1分。
一、玩家类Player.h和Player.m两个文件Player.h文件:
#import #import “FistType.h” NS_ASSUME_NONNULL_BEGIN
@interface Player : NSObject @property NSString *name; @property FistType fistType; @property int score;
- (void)showFist;
- (NSString *)fistTypeWithNumber:(int)number; @end
NS_ASSUME_NONNULL_END
Player.m文件:
#import “Player.h”
@implementation Player
-
(void)showFist { NSLog(@“亲爱的玩家【%@】,请输入你要出的拳头,1 剪刀 2 石头 3 布:”,self.name); int userSelected = 0; rewind(stdin); scanf(“%d”,&userSelected); NSString *fistType = [self fistTypeWithNumber:userSel