MainView.m
上传用户:qhdwjd2004
上传日期:2020-12-29
资源大小:362k
文件大小:5k
源码类别:

iPhone

开发平台:

Objective-C

  1. #import "MainView.h"
  2. @implementation MainView
  3. - (id)initWithFrame:(CGRect)rect 
  4. {
  5.     if ((self == [ super initWithFrame: rect ]) != nil) {
  6.         viewRect = rect;
  7.         // -------------------- init --------------------
  8.         aEffect = [[NSArray alloc] initWithObjects: 
  9.             @"pageCurl",@"pageUnCurl",
  10.             @"suckEffect",@"spewEffect",
  11.             @"genieEffect",@"unGenieEffect",
  12.             @"swirl",@"rippleEffect",
  13.             @"twist",@"tubey",
  14.             @"oglFlip",nil
  15.         ];
  16.         // -------------------- init transView --------------------
  17.         transView = [ [ UITransitionView alloc ] initWithFrame: viewRect ];
  18.         [ self addSubview: transView ];
  19.         // -------------------- init messageSheet  --------------------
  20.         messageSheet = [[UIAlertSheet alloc] initWithFrame : CGRectMake(0,240,320,240)];
  21.         [messageSheet setDestructiveButton :[messageSheet addButtonWithTitle:@"OK"]];
  22.         [messageSheet setDelegate: self];
  23.         // -------------------- init coverView --------------------
  24.         coverView = [[CoverView alloc] initWithFrame: viewRect];
  25. [coverView setParentView: self];
  26.         // -------------------- init gameView --------------------
  27.         gameView = [[GameView alloc] initWithFrame: viewRect];
  28. [gameView setParentView: self];
  29.         // -------------------- init listView --------------------
  30.         listView = [[ListView alloc] initWithFrame: viewRect];
  31. [listView setParentView: self];
  32.         // -------------------- init settingView --------------------
  33.         settingView = [[SettingView alloc] initWithFrame: viewRect];
  34. [settingView setParentView: self];
  35.         // -------------------- init aboutView --------------------
  36.         aboutView = [[AboutView alloc] initWithFrame: viewRect];
  37.         [aboutView setParentView: self];
  38.         [self transTo: coverView];
  39.     }
  40.     return self;
  41. }
  42. - (void)dealloc
  43. {
  44.     [ self dealloc ];
  45.     [ super dealloc ];
  46. }
  47. //////////////////////////////////////////////////////
  48. // 公共函数
  49. //////////////////////////////////////////////////////
  50. // 显示提示信息
  51. - (void)showMessage:(NSString *)msg Title:(NSString *)title
  52. {
  53.     [messageSheet setTitle: title];
  54. [messageSheet setBodyText: msg];
  55.     [messageSheet popupAlertAnimated:YES];
  56. }
  57. -(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button
  58. {
  59.     [sheet dismiss];
  60. }
  61. // 切换视图
  62. - (void)showView:(int)viewname
  63. {
  64.     switch(viewname)
  65.     {
  66.     case COVERVIEW:
  67.         [self transTo: coverView];
  68.         break;
  69.     case GAMEVIEW:
  70.         [self transTo: gameView];
  71.         break;
  72.     case LISTVIEW:
  73.         [self transTo: listView];
  74.         break;
  75.     case SETTINGVIEW:
  76.         [self transTo: settingView];
  77.         break;
  78.     case ABOUTVIEW:
  79.         [self transTo: aboutView];
  80.         break;
  81.     }
  82. }
  83. // 切换视图
  84. - (void)transTo:(UIView *)view
  85. {
  86.     LKAnimation *animation = [ LKTransition animation ];
  87.     [ animation setType: [aEffect objectAtIndex:[Map GetRandNum] % 11]];
  88.     [ animation setSubtype: @"fromLeft"];
  89.     [ animation setTimingFunction:
  90.         [ LKTimingFunction functionWithName: @"easeInEaseOut"]];
  91.     [ animation setFillMode: @"extended" ];
  92.     [ animation setTransitionFlags: 3 ];
  93.     [ animation setSpeed: 0.50 ];
  94.     [ [ self  _layer ] addAnimation: animation forKey: 0 ];
  95.     [ transView transition: 0 toView: view ];
  96. }
  97. // 显示封面
  98. - (void)showCover
  99. {
  100.     [coverView updateview];
  101.     [self transTo: coverView];
  102. }
  103. // 设备方向发生改变
  104. - (void)orientationChanged:(int)orientation
  105. {
  106.     if([gameView IsPlaying])
  107.     {
  108.         [gameView changeOrientation:orientation];
  109.     }
  110. }
  111. // 程序将退出
  112. - (void)appWillExit
  113. {
  114.     if([gameView IsPlaying])
  115.     {
  116.         [gameView save];
  117.     }
  118. }
  119. //////////////////////////////////////////////////////
  120. // 菜单响应
  121. //////////////////////////////////////////////////////
  122. // 开始游戏
  123. - (void)startGame
  124. {
  125.     Mess mdata;
  126.     if([Map CheckMessExist])
  127.     {
  128.         mdata = [Map LoadMess];
  129.     }
  130.     else
  131.     {
  132.         mdata.enableChapterCount = 1;
  133.     }
  134.     
  135.     mdata.chapterIndex = 0;
  136.     mdata.isCustom=NO;
  137.     [Map LoadChapter:mdata.chapterIndex Data:mdata.mapdata];
  138.     [gameView load:mdata];
  139.     [self transTo:gameView];
  140. }
  141. // 继续游戏
  142. - (void)continueGame
  143. {
  144.     Mess mdata = [Map LoadMess];
  145.     [gameView load:mdata];
  146.     [self transTo:gameView];
  147. }
  148. // 选择关卡
  149. - (void)customGame:(bool)isCustomMap
  150. {
  151.     if(isCustomMap)
  152.     {
  153.         [listView loadMapList];
  154.     }
  155.     else
  156.     {
  157.         [listView loadChapterList];
  158.     }
  159.     [self transTo:listView];
  160. }
  161. // 显示关于
  162. - (void)showAbout
  163. {
  164.     [self transTo:aboutView];
  165. }
  166. // 关卡被选择
  167. -(void)characterSelected:(int)cindex
  168. {
  169.     Mess mdata = [Map LoadMess];
  170.     mdata.chapterIndex = cindex;
  171.     mdata.isCustom=NO;
  172.     [Map LoadChapter:mdata.chapterIndex Data:mdata.mapdata];
  173.     [gameView load:mdata];
  174.     [self transTo:gameView];
  175. }
  176. // 自定义地图被选择
  177. -(void)mapSelected:(NSString*)mappath
  178. {
  179.     Mess mdata = [Map LoadMess];
  180.     mdata.isCustom=YES;
  181.     [Map LoadMap:mappath Data:mdata.mapdata];
  182.     [gameView load:mdata];
  183.     [self transTo:gameView];
  184. }
  185. @end