一.ViewController.h中代码
//
// ViewController.h
// ThirdSignleView
//
// Created by on 15/6/10.
// Copyright (c) 2015年. All rights reserved.
//
#import
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *number1;
@property (weak, nonatomic) IBOutlet UITextField *number2;
@property (weak, nonatomic) IBOutlet UITextField *number3;
@property (weak, nonatomic) IBOutlet UITextField *number4;
@property (weak, nonatomic) IBOutlet UITextField *number5;
@property (weak, nonatomic) IBOutlet UITextField *number6;
@property (weak, nonatomic) IBOutlet UITextField *number7;
@property (weak, nonatomic) IBOutlet UITextField *number8;
@property (weak, nonatomic) IBOutlet UITextField *number9;
- (IBAction)replay:(id)sender;
- (IBAction)finish:(id)sender;
@property (nonatomic, strong ) NSMutableArray *finishArray;
@property (weak, nonatomic) IBOutlet UILabel *result;
@end
二.ViewController.m中代码
//
// ViewController.m
// ThirdSignleView
//
// Created by jabez.huang on 15/6/10.
// Copyright (c) 2015年 jabez.huang. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)replay:(id)sender {
NSArray *numberArray = @[ @[@"1",@"2", @"3"], @[@"2", @"3", @"1"], @[@"3", @"1", @"2"]];
NSMutableArray *muArray = [NSMutableArray arrayWithArray:numberArray];
int rand1 = arc4random() % 3;
int rand2 = arc4random() % 3;
NSArray *tmpArray = @[];
tmpArray = muArray[rand1];
muArray[rand1] = muArray[rand2];
muArray[rand2] = tmpArray;
_finishArray = muArray;
NSArray *textfieldArray = @[ _number1 , _number2 , _number3 , _number4, _number5 , _number6, _number7 , _number8 ,_number9];
int flag = 0;
for( int i = 0; i
for( int j = 0; j
//NSLog( @"%i , %@", flag, muArray[i][j] );
UITextField *str = textfieldArray[flag];
str.text = muArray[i][j];
flag++;
}
}
for( int n = 0 ; n
int tmpFlag = arc4random() % 9 ;
UITextField *str1 = textfieldArray[tmpFlag];
str1.text = @"";
}
}
- (IBAction)finish:(id)sender {
NSArray *textfieldArray = @[ @[_number1 , _number2 , _number3] , @[_number4, _number5 , _number6], @[_number7 , _number8 ,_number9]];
//_finishArray
int flag = 1;
NSLog( @"finshArray :%@", _finishArray);
NSLog(@"-->%lu",(unsigned long)[textfieldArray count]);
for( int i = 0; i
for( int j = 0; j
UITextField *field = textfieldArray[i][j];
if( ![field.text isEqualToString: _finishArray[i][j]] ){
flag = 0;
}
}
}
if( flag == 1 ){
_result.text = @"恭喜!你赢了!";
}else{
_result.text = @"失败抱歉!";
}
}
@end