From bef6c4c6a8e7e408652a911f1a7bb620dc10f351 Mon Sep 17 00:00:00 2001 From: coderZsq Date: Mon, 14 Sep 2020 20:41:42 +0800 Subject: [PATCH] add --- SQNumbers/SQNumbers/SQSceneView.h | 2 -- SQNumbers/SQNumbers/SQSceneView.m | 22 ++++++++++++++++++++-- SQNumbers/SQNumbers/ViewController.m | 1 - 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/SQNumbers/SQNumbers/SQSceneView.h b/SQNumbers/SQNumbers/SQSceneView.h index 82aa9c8c..16989745 100644 --- a/SQNumbers/SQNumbers/SQSceneView.h +++ b/SQNumbers/SQNumbers/SQSceneView.h @@ -12,8 +12,6 @@ NS_ASSUME_NONNULL_BEGIN @interface SQSceneView : UIView -@property (nonatomic, assign) NSUInteger capacity; - - (void)renderToCanvas:(UIView *)superView; @end diff --git a/SQNumbers/SQNumbers/SQSceneView.m b/SQNumbers/SQNumbers/SQSceneView.m index 7ddc02b5..7d6a2b29 100644 --- a/SQNumbers/SQNumbers/SQSceneView.m +++ b/SQNumbers/SQNumbers/SQSceneView.m @@ -6,15 +6,23 @@ // Copyright © 2020 朱双泉. All rights reserved. // +#import "SceneDelegate.h" #import "SQSceneView.h" #import "SQSpriteView.h" +@interface SQSceneView () + +@property (nonatomic, assign) NSInteger currnetLevel; + +@end + @implementation SQSceneView - (void)renderToCanvas:(UIView *)superView { [superView addSubview:self]; - NSInteger capacity = self.capacity ? self.capacity : 5; + self.currnetLevel += 1; + NSInteger capacity = arc4random_uniform(5) + 1; NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:capacity]; UIView *containerView = [UIView new]; @@ -63,7 +71,17 @@ - (void)renderToCanvas:(UIView *)superView { } } if (successed) { - NSLog(@"游戏通关"); + UIAlertController *altvc = [UIAlertController alertControllerWithTitle:@"闯关成功" message:[NSString stringWithFormat:@"恭喜你通过第%li关, 请进入第%li关", self.currnetLevel, self.currnetLevel + 1] preferredStyle:UIAlertControllerStyleAlert]; + [altvc addAction:[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + for (UIView *view in self.subviews) { + [view removeFromSuperview]; + } + [self renderToCanvas:superView]; + }]]; + NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; + UIWindowScene *windowScene = (UIWindowScene *)array.firstObject; + SceneDelegate *delegate = (SceneDelegate *)windowScene.delegate; + [delegate.window.rootViewController presentViewController:altvc animated:YES completion:nil]; } }; diff --git a/SQNumbers/SQNumbers/ViewController.m b/SQNumbers/SQNumbers/ViewController.m index 9c394cc5..5918d5ea 100644 --- a/SQNumbers/SQNumbers/ViewController.m +++ b/SQNumbers/SQNumbers/ViewController.m @@ -20,7 +20,6 @@ - (void)viewDidLoad { SQSceneView *sceneView = [SQSceneView new]; sceneView.frame = self.view.bounds; - sceneView.capacity = arc4random() % 6; [sceneView renderToCanvas:self.view]; }