您当前的位置: 首页 >  游戏

清风清晨

暂无认证

  • 1浏览

    0关注

    71博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【猜拳游戏 基于Objective-C语言】

清风清晨 发布时间:2022-08-07 23:12:14 ,浏览量:1

前言

这是一个猜拳游戏,玩家选择想要出的拳头: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

关注
打赏
1663943137
查看更多评论
立即登录/注册

微信扫码登录

0.0357s