你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS開發之-猜數游戲的簡單改進

iOS開發之-猜數游戲的簡單改進

編輯:IOS開發綜合
//
//  main.m
//  猜數


#import 
#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 

@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


 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved