超级猜图

#import "ViewController.h"

#import "CZquestions.h"


@interface ViewController ()<UIAlertViewDelegate>


//所有问题的数据都在这个数组中

@property(nonatomic,strong)NSArray * questions;

@property (weak, nonatomic) IBOutlet UIButton *money;


//控制题目索引

@property(nonatomic,assign)int index;


//阴影

@property(nonatomic,weak)UIButton * cover;

-(void)tapCover;


//保存原始大小

@property(nonatomic,assign)CGRect imgFrame;


@property (weak, nonatomic) IBOutlet UILabel *lblIndex;


@property (weak, nonatomic) IBOutlet UILabel *lbltitle;


@property (weak, nonatomic) IBOutlet UIButton *btnImg;

- (IBAction)tapImg:(id)sender;


@property (weak, nonatomic) IBOutlet UIButton *btnNext;

- (IBAction)nextQuestion;


- (IBAction)biggerImg;


@property (weak, nonatomic) IBOutlet UIView *answerView;


@property (weak, nonatomic) IBOutlet UIView *optionsView;


@property(nonatomic,assign)int tishiIndex;

@property(nonatomic,strong)NSMutableString * tishiBtnAnswer;

@property (weak, nonatomic) IBOutlet UIButton *btnTishi;


- (IBAction)tishi;




@end


@implementation ViewController


-(NSArray*)questions

{

    if (_questions == nil) {

        NSString* path = [[NSBundle mainBundle]pathForResource:@"pic.plist" ofType:nil];

        NSArray * array = [NSArray arrayWithContentsOfFile:path];

        NSMutableArray * modelCZ = [NSMutableArray array];

        for (NSDictionary * dict in array) {

            CZquestions * cz = [CZquestions czquestionsWithDict:dict];

            [modelCZ addObject:cz];

            

        }

        

        _questions = modelCZ;

        

        

    }

    return _questions;

    

}


//改变状态栏的颜色为白色

-(UIStatusBarStyle)preferredStatusBarStyle

{

//    return UIStatusBarStyleDefault;//状态栏的颜色为深色

    return UIStatusBarStyleLightContent;//状态栏的颜色为白色

}



//隐藏状态栏

-(BOOL)prefersStatusBarHidden

{

    return YES;

}



- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    self.tishiBtnAnswer = [NSMutableString string];

    

    self.index = -1;

    

    [self next];

//    self.cover = nil;


}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (IBAction)biggerImg {


    self.imgFrame = self.btnImg.frame;

    CGFloat w = self.view.frame.size.width;

    CGFloat h = w;

    CGFloat x = 0;

    CGFloat y = (self.view.frame.size.height - h) / 2;

    

    CGRect viewFrame = self.view.frame;

    self.cover = [UIButton buttonWithType:UIButtonTypeSystem];

    self.cover.frame = viewFrame;

    self.cover.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:self.cover];

    self.cover.alpha = 0.0;

    [UIView animateWithDuration:0.7 animations:^{

        self.btnImg.frame = CGRectMake(x, y, w, h);

        self.cover.alpha = 0.6;

    }];

    

    [self.cover addTarget:self action:@selector(tapCover) forControlEvents:UIControlEventTouchUpInside];

    

    [self.view bringSubviewToFront:self.btnImg];

}


-(void)tapCover

{


    [UIView animateWithDuration:0.7 animations:^{

        self.btnImg.frame = self.imgFrame;

        self.cover.alpha = 0.0;

    } completion:^(BOOL finished) {

        if (finished) {

            

            [self.cover removeFromSuperview];

        }

    }];

    

    self.cover = nil;

    

}


- (IBAction)tapImg:(id)sender {


    if (self.cover == nil) {

        [self biggerImg];

    }else{

        [self tapCover];

    }

    

}


- (IBAction)nextQuestion {

    [self next];

    

}


-(void)isTishiEnabled

{

    int score =self.money.currentTitle.intValue;

    if (score - 1000 < 1000) {

        self.btnTishi.enabled = NO;

    }else{

        self.btnTishi.enabled = YES;

    }

    

}


-(void)next

{

    self.tishiIndex = 0;

    

    [self isTishiEnabled];

    

    

    if (self.index+1 == self.questions.count) {

        

        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"操作提示" message:@"恭喜通关" delegate: nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

        alert.delegate = self;

        [alert show];

        

        return;

    }

//    1. 索引++

    self.index++;

    CZquestions * model = self.questions[self.index];

    

    

    

//    2.切换显示

    [self loadNextTopViewPart:model];


    [self loadNextBottomViewPart:model];

    

    self.optionsView.userInteractionEnabled = YES;


    

}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex == 1) {

        self.index = -1;

        [self next];

    }



}


-(void)loadNextTopViewPart:(CZquestions*)model

{

    [self.lblIndex setText:[NSString stringWithFormat:@"%d / %lu",self.index + 1,self.questions.count]];

    self.lbltitle.text = model.title;

    

    

    [self.btnImg setImage:[UIImage imageNamed:model.icon] forState:UIControlStateNormal];

    //    3.最后一题时,下一题禁用

    self.btnNext.enabled = (self.index != self.questions.count - 1);

}


-(void)loadNextBottomViewPart:(CZquestions*)model

{

    [self loadAnswerView:model];

    [self loadOptionsView:model];

    

}


-(void)loadAnswerView:(CZquestions*)model

{

    [self.answerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

    

    NSUInteger length = [model.answer length];

    

    NSLog(@"length = %lu",length);

    

    CGFloat w = 35.0;

    CGFloat h = 35.0;

    CGFloat y = 0.0;

    CGFloat margin = 10.0;

    CGFloat leftMargin = (self.answerView.frame.size.width - length * w - (length - 1.0) * margin ) / 2.0;

    

    for (int i = 0; i < length ; i++) {

        UIButton * btnAnswer = [UIButton buttonWithType:UIButtonTypeCustom];

        CGFloat x = leftMargin + (w + margin) * i;

        btnAnswer.frame = CGRectMake(x, y, w, h);

        [btnAnswer setBackgroundImage:[UIImage imageNamed:@"center_img"] forState:UIControlStateNormal];

        [self.answerView addSubview:btnAnswer];

        [btnAnswer setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        [btnAnswer addTarget:self action:@selector(bthAnswerClick:) forControlEvents:UIControlEventTouchUpInside];

    }


}


-(void)bthAnswerClick:(UIButton *)sender

{

    for (UIButton * btn in self.optionsView.subviews) {

        if (btn.tag == sender.tag) {

            btn.hidden = NO;

            break;

        }

        

    }


    for (UIButton* btn in self.answerView.subviews) {

        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


    }

    [sender setTitle:nil forState:UIControlStateNormal];

    self.optionsView.userInteractionEnabled = YES;

}


-(void)loadOptionsView:(CZquestions*)model

{


    [self.optionsView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

    

    int sum =(int)model.options.count;

    

    CGFloat w = 35;

    CGFloat h = 35;

    CGFloat topY = 0;

    CGFloat marginX = 10;

    CGFloat marginY = marginX;

    int Hsum = 7;

    CGFloat leftMargin = (self.optionsView.frame.size.width - Hsum * w - (Hsum -1) * marginX ) / 2;

    

    for (int i = 0; i < sum; i++) {

        int hi = i % Hsum;

        int vi = i / Hsum;

        

        UIButton * btnOptions =[UIButton buttonWithType:UIButtonTypeSystem];

        CGFloat x = leftMargin + (w + marginX) * hi;

        CGFloat y = topY + (h + marginY) * vi;

        btnOptions.frame = CGRectMake(x, y, w, h);

        [btnOptions setBackgroundImage:[UIImage imageNamed:@"center_img"] forState:UIControlStateNormal];

        [self.optionsView addSubview:btnOptions];

        [btnOptions setTitle:model.options[i] forState:UIControlStateNormal];

        [btnOptions setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        

        [btnOptions addTarget:self action:@selector(bthOptionsClick:) forControlEvents:UIControlEventTouchUpInside];

        

        btnOptions.tag = i;

    

    }


}


-(void)bthOptionsClick:(UIButton *)sender

{

    sender.hidden = YES;

    

    NSString * strOptions = sender.currentTitle;

    

    for (UIButton* btn in self.answerView.subviews) {

        if (btn.currentTitle == nil) {

            [btn setTitle:strOptions forState:UIControlStateNormal];


            btn.tag = sender.tag;

            break;

        }

    }

    

    BOOL isFool = YES;

    NSMutableString * str = [NSMutableString string];

    for (UIButton * btn in self.answerView.subviews) {

        if (btn.currentTitle == nil) {

            isFool = NO;

            break;

        }else{

            [str appendString:btn.currentTitle];


        }

    }

    

    CZquestions * mod = self.questions[self.index];

    if (isFool) {

        if ([str isEqualToString:mod.answer]) {

          

             [self changAnswerTextColor:[UIColor blueColor]];

             [self changeScore:1000];

            [self performSelector:@selector(next) withObject:nil afterDelay:0.5];

        }else{

            [self changAnswerTextColor:[UIColor redColor]];

        }

            

    }

   

   

    self.optionsView.userInteractionEnabled = !isFool;



}


-(void)changeScore:(int)score

{

    int preScore = self.money.currentTitle.intValue;

    

    [self.money setTitle:[NSString stringWithFormat:@"%d",preScore + score] forState:UIControlStateNormal];


}


-(void)changAnswerTextColor:(UIColor *)color

{

    for (UIButton * btn in self.answerView.subviews) {

        [btn setTitleColor:color forState:UIControlStateNormal];

    }


}



- (IBAction)tishi {

    [self isTishiEnabled];

    CZquestions * model = self.questions[self.index];

    

    if ( self.tishiIndex > (int)model.answer.length - 1) {

        return;

    }

    

    [self changeScore:-1000];

    


    for (UIButton * btn in self.answerView.subviews) {

        [self bthAnswerClick:btn];

    }



    

    

    NSString * modelAnswer = [model.answer substringToIndex:self.tishiIndex + 1];

    

    int i = 0;

    for (UIButton*btnAns in self.answerView.subviews) {

        if (i  == modelAnswer.length) {

            break;

        }

        

        NSString * word = [modelAnswer substringWithRange:NSMakeRange(i, 1)];

        

        for (UIButton * btnOpt in self.optionsView.subviews) {

            if ([btnOpt.currentTitle isEqualToString:word]) {

                [self bthOptionsClick:btnOpt];

                break;

            }

        }

        

        

        i++;

        

        

        


    }

    

    self.tishiIndex++;


   

}

@end


//plist 模型

#import <Foundation/Foundation.h>


@interface CZquestions : NSObject


@property(nonatomic,strong)NSString * answer;


@property(nonatomic,strong)NSString * icon;


@property(nonatomic,strong)NSString * title;


@property(nonatomic,strong)NSArray * options;


-(instancetype)initWithDict:(NSDictionary*)dict;


+(instancetype)czquestionsWithDict:(NSDictionary*)dict;



@end




#import "CZquestions.h"


@implementation CZquestions


- (instancetype)initWithDict:(NSDictionary *)dict

{

    self = [super init];

    if (self) {

        self.answer = dict[@"answer"];

        self.title = dict[@"title"];

        self.icon = dict[@"icon"];

        self.options = dict[@"options"];

    }

    return self;

}


+(instancetype)czquestionsWithDict:(NSDictionary *)dict

{

    return [[self alloc]initWithDict:dict];

}



@end



weixin073智慧旅游平台开发微信小程序+ssm后端毕业源码案例设计 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值