A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

/**
出拳枚举
*/
typedef enum
{
    HMFistTypeJianDao = 1,
    HMFistTypeShiTou =2,
    HMFistTypeBu =3
} HMFistType;

//声明玩家类
#import <Foundation/Foundation.h>
#import "HMFistType.h"
@interface HMPlayer : NSObject
{
    @public
    NSString *_name;
    HMFistType _fistType;
    int _score;
}

- (void)showFist;

- (NSString *)fistTypeWithNumber:(int)num;

+ (HMPlayer *)player;

+ (HMPlayer *)playerWithName:(NSString *)name;
@end

#import "HMPlayer.h"

@implementation HMPlayer
- (void)showFist
{

    NSLog(@"请出拳: 1.剪刀 2.石头 3.布");

    int userSelected = 0;
    scanf("%d",&userSelected);

    NSString *type = [self fistTypeWithNumber:userSelected];
    NSLog(@"玩家[%@]出拳是[%@]",_name,type);

    _fistType = userSelected;
}

- (NSString *)fistTypeWithNumber:(int)num
{
    switch (num)
    {
        case 1:
            return @"剪刀";
        case 2:
            return @"石头";
        case 3:
            return @"布";
        default:
            return @"想使诈,你输了.";
    }
}

+ (HMPlayer *)player
{
    HMPlayer *p1 = [HMPlayer new];
    return p1;
}

+ (HMPlayer *)playerWithName:(NSString *)name
{
    HMPlayer *p1 = [HMPlayer new];
    p1->_name = name;
    return p1;
}


@end



#import <Foundation/Foundation.h>
#import "HMFistType.h"
@interface HMRobot : NSObject
{
    @public
    NSString *_name;
    HMFistType _fistType;
    int _score;
}
- (void)showFist;
- (NSString *)fistTypeWithNumber:(int)num;
+ (HMRobot *)robot;
+ (HMRobot *)robotWithName:(NSString *)name;
@end

#import "HMRobot.h"

@implementation HMRobot
- (void)showFist
{
    int robotSelected = arc4random_uniform(3)+1;
    NSString *type = [self fistTypeWithNumber:robotSelected];
    NSLog(@"机器人[%@]出拳是[%@]",_name,type);
    _fistType = robotSelected;
}
- (NSString *)fistTypeWithNumber:(int)num
{
    switch (num)
    {
        case 1:
            return @"剪刀";
        case 2:
            return @"石头";
        case 3:
            return @"布";
        default:
            return @"想使诈,你输了.";
    }

}
+ (HMRobot *)robot
{
    HMRobot *r1 = [HMRobot new];
    return r1;
}
+ (HMRobot *)robotWithName:(NSString *)name
{
    HMRobot *r1 = [HMRobot new];
    r1->_name = name;
    return r1;
}


@end


#import <Foundation/Foundation.h>
#import "HMPlayer.h"
#import "HMRobot.h"
@interface HMJudge : NSObject
{
    @public
    NSString *_name;

}
- (void)caiJueWithPlayer:(HMPlayer *)player andRobot:(HMRobot *)robot;
+ (HMJudge *)judge;
+ (HMJudge *)judgeWithName:(NSString *)name;
@end





3 个回复

倒序浏览
今天刚敲了两遍,再来温习一下
回复 使用道具 举报
可以可以,这个游戏还是可以再优化的
回复 使用道具 举报
好人一生平安...
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马