码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发之-猜数游戏的简单改进

时间:2015-07-22 09:29:09      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:游戏   objective-c   封装   ios开发   foundation框架   

//
//  main.m
//  猜数


#import <Foundation/Foundation.h>
#import "Guess.h"

int main(int argc, const char * argv[])
{

    Guess * number = [[Guess alloc]init];
    NSLog(@"请输入您所猜的数字");
    int guessNumber;
    int n = 5;
    int i = 0;
    NSLog(@"您有5次机会");
    while (n--) {
        scanf("%d",&guessNumber);
        [number guessNumber:guessNumber];
        if (guessNumber==100) {
            break;
        }
        i++;
        if(i==5)
            NSLog(@"对不起您没有猜对");
    }
    //NSComparisonResult

    /*typedef NS_ENUM(NSInteger, NSComparisonResult) {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};*/
    //scanf("%d",&guessNumber);
    //[number guessNumber:guessNumber];
    //NSLog(@"%d",number->_guessNumber);

    return 0;
}
#import <Foundation/Foundation.h>

@interface Guess : NSObject
{
    @public
    int _guessNumber;
}

-(void)guessNumber:(int)number;

@end

#import "Guess.h"

@implementation Guess

-(id)init
{
    self = [super init];
    if (self != nil) {
        _guessNumber = 100;
    }
    return self;
}
-(void)guessNumber:(int)number
{
    //NSLog(@"请输入您所猜的数字");
    
    if(number==_guessNumber)
    {
        NSLog(@"您猜对了");
    }
    else if(number > _guessNumber)
    {
        NSLog(@"您猜的大了");
    }
    else
    {
        NSLog(@"您猜的小了");
    }
   
}
@end


版权声明:本文为博主原创文章,未经博主允许不得转载。

iOS开发之-猜数游戏的简单改进

标签:游戏   objective-c   封装   ios开发   foundation框架   

原文地址:http://blog.csdn.net/u012701023/article/details/46997479

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!