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

iPhone

开发平台:

Objective-C

  1. #import "GameView.h"
  2. #import "MainView.h"
  3. @implementation GameView
  4. //////////////////////////////////////////////////////
  5. // 视图函数
  6. //////////////////////////////////////////////////////
  7. // 初始化
  8. -(id)initWithFrame:(CGRect)rect
  9. {
  10.     if ((self == [ super initWithFrame: rect ]) != nil) {
  11.         viewRect = rect;
  12.         // -------------------- init Fields  --------------------
  13.         direct = 0;
  14.         orientation = 0;
  15.         step = 0;
  16.         isCompleted = NO;
  17.         isPlaying = NO;
  18.         lockOrient = NO;
  19.         chapterCount = [Map ChapterCount];
  20.         canUndo = false;
  21.         // -------------------- init messageSheet  --------------------
  22.         confirmSheet = [[UIAlertSheet alloc] initWithFrame : CGRectMake(0,240,320,240)];
  23.         [confirmSheet setDestructiveButton :[confirmSheet addButtonWithTitle:@"Yes"]];
  24.         [confirmSheet addButtonWithTitle:@"No"];
  25.         [confirmSheet setDelegate: self];
  26.         // -------------------- init Image  --------------------
  27.         blockImage = [UIImage applicationImageNamed:@"images/block.png"];
  28.         boxImage = [UIImage applicationImageNamed:@"images/box1.png"];
  29.         destImage = [UIImage applicationImageNamed:@"images/dest.png"];
  30.         playerImage = [UIImage applicationImageNamed:@"images/player.png"];
  31.         playerUpImage = [UIImage applicationImageNamed:@"images/playerup.png"];
  32.     playerDownImage = [UIImage applicationImageNamed:@"images/playerdown.png"];
  33.     playerLeftImage = [UIImage applicationImageNamed:@"images/playerleft.png"];
  34.     playerRightImage = [UIImage applicationImageNamed:@"images/playerright.png"];
  35.     //playerOnDestImage = [UIImage applicationImageNamed:@"images/playerondest.png"];
  36.         boxOnDestImage = [UIImage applicationImageNamed:@"images/box2.png"];
  37.         backgroundImage = [UIImage applicationImageNamed:@"images/background.png"];
  38.         // -------------------- init menu  --------------------
  39.         menuSwitch = [UIImage applicationImageNamed:@"images/menuswitch.png"];
  40.         menuSwitchPos = CGRectMake(0, 430, 50 , 50 );
  41.         menu = [ [UINavigationBar alloc] initWithFrame: CGRectMake(0, 430, 320, 50)];
  42. [ menu setDelegate: self ];
  43. [ menu enableAnimation ];
  44. [ menu setBarStyle: 0 ];
  45. [ self addSubview: menu ];
  46.         CGRect btnRect = CGRectMake(0,5,60,30);
  47.         menuItemHidden = [[UINavBarButton alloc] initWithTitle: @"Hide"];
  48.         [menuItemHidden setFrame: btnRect];
  49.         [menuItemHidden setDrawContentsCentered: YES];
  50.         [menuItemHidden setNavBarButtonStyle: 2];
  51.         [menuItemHidden addTarget:self action:@selector(menuItemClick:) forEvents:255];
  52.         [menu addSubview:menuItemHidden];
  53.         btnRect = CGRectMake(64,5,60,30); 
  54.         menuItemExit = [[UINavBarButton alloc] initWithTitle: @"Exit"];
  55.         [menuItemExit setFrame: btnRect];
  56.         [menuItemExit setDrawContentsCentered: YES];
  57.         [menuItemExit setNavBarButtonStyle: 0];
  58.         [menuItemExit addTarget:self action:@selector(menuItemClick:) forEvents:255];
  59.         [menu addSubview:menuItemExit];
  60.         btnRect = CGRectMake(128,5,60,30); 
  61.         menuItemUndo = [[UINavBarButton alloc] initWithTitle: @"Undo"];
  62.         [menuItemUndo setFrame: btnRect];
  63.         [menuItemUndo setDrawContentsCentered: YES];
  64.         [menuItemUndo setNavBarButtonStyle: 0];
  65.         [menuItemUndo addTarget:self action:@selector(menuItemClick:) forEvents:255];
  66.         [menu addSubview:menuItemUndo];
  67.         [menuItemUndo setEnabled:NO];
  68.         btnRect = CGRectMake(192,5,60,30); 
  69.         menuItemPreStage = [[UINavBarButton alloc] initWithTitle: @"|<<"];
  70.         [menuItemPreStage setFrame: btnRect];
  71.         [menuItemPreStage setDrawContentsCentered: YES];
  72.         [menuItemPreStage setNavBarButtonStyle: 0];
  73.         [menuItemPreStage addTarget:self action:@selector(menuItemClick:) forEvents:255];
  74.         [menu addSubview:menuItemPreStage];
  75.         btnRect = CGRectMake(256,5,60,30); 
  76.         menuItemNextStage = [[UINavBarButton alloc] initWithTitle: @">>|"];
  77.         [menuItemNextStage setFrame: btnRect];
  78.         [menuItemNextStage setDrawContentsCentered: YES];
  79.         [menuItemNextStage setNavBarButtonStyle: 0];
  80.         [menuItemNextStage addTarget:self action:@selector(menuItemClick:) forEvents:255];
  81.         [menu addSubview: menuItemNextStage];
  82.         // 隐藏菜单
  83.         [self hideNavBar];
  84.     }
  85.     return self;
  86. }
  87. // -------------- 绘图 -----------------------
  88. - (void)drawRect:(CGRect)rect {
  89.     // 绘制背景
  90.     float black[4] = { 0, 0, 0, 1 };
  91.     CGContextRef ctx = UICurrentContext();
  92.     CGContextSetFillColor(ctx, black);
  93.     CGContextFillRect(ctx, rect);
  94.     // 绘制背景图片
  95.     [ backgroundImage draw1PartImageInRect: viewRect ];
  96.     // 检查是否完成
  97.     isCompleted = YES;
  98.     int i;
  99.     for(i=0;i<Map_LEN;i++) {
  100.         if(mdata.mapdata[i] == BoxBlock) isCompleted = NO;
  101.         switch(mdata.mapdata[i])
  102.         {
  103.         case WallBlock:
  104.             [ blockImage draw1PartImageInRect: positions[i] ];
  105.             break;
  106.         case BoxBlock:
  107.             [ boxImage draw1PartImageInRect: positions[i] ];
  108.             break;
  109.         case TargetBlock:
  110.             [ destImage draw1PartImageInRect: positions[i] ];
  111.             break;
  112.         case PlayerOnTargetBlock:
  113.         case PlayerBlock:
  114.             switch(direct)
  115.             {
  116.             case 0:
  117.                 [ playerImage draw1PartImageInRect: positions[i] ];
  118.                 break;
  119.             case 1:
  120.                 switch(orientation)
  121.                 {
  122.                 case 0:
  123.                     [ playerUpImage draw1PartImageInRect: positions[i] ];
  124.                     break;
  125.                 case 1:
  126.                     [ playerDownImage draw1PartImageInRect: positions[i] ];
  127.                     break;
  128.                 case 3:
  129.                     [ playerLeftImage draw1PartImageInRect: positions[i] ];
  130.                     break;
  131.                 case 2:
  132.                     [ playerRightImage draw1PartImageInRect: positions[i] ];
  133.                     break;
  134.                 }
  135.                 break;
  136.             case 2:
  137.                 switch(orientation)
  138.                 {
  139.                 case 0:
  140.                     [ playerDownImage draw1PartImageInRect: positions[i] ];
  141.                     break;
  142.                 case 1:
  143.                     [ playerUpImage draw1PartImageInRect: positions[i] ];
  144.                     break;
  145.                 case 3:
  146.                     [ playerRightImage draw1PartImageInRect: positions[i] ];
  147.                     break;
  148.                 case 2:
  149.                     [ playerLeftImage draw1PartImageInRect: positions[i] ];
  150.                     break;
  151.                 }
  152.                 break;
  153.             case 3:
  154.                 switch(orientation)
  155.                 {
  156.                 case 0:
  157.                     [ playerLeftImage draw1PartImageInRect: positions[i] ];
  158.                     break;
  159.                 case 1:
  160.                     [ playerRightImage draw1PartImageInRect: positions[i] ];
  161.                     break;
  162.                 case 3:
  163.                     [ playerDownImage draw1PartImageInRect: positions[i] ];
  164.                     break;
  165.                 case 2:
  166.                     [ playerUpImage draw1PartImageInRect: positions[i] ];
  167.                     break;
  168.                 }
  169.                 break;
  170.             case 4:
  171.                 switch(orientation)
  172.                 {
  173.                 case 0:
  174.                     [ playerRightImage draw1PartImageInRect: positions[i] ];
  175.                     break;
  176.                 case 1:
  177.                     [ playerLeftImage draw1PartImageInRect: positions[i] ];
  178.                     break;
  179.                 case 3:
  180.                     [ playerUpImage draw1PartImageInRect: positions[i] ];
  181.                     break;
  182.                 case 2:
  183.                     [ playerDownImage draw1PartImageInRect: positions[i] ];
  184.                     break;
  185.                 }
  186.                 break;
  187.             }
  188.             break;
  189.         case BoxOnTargetBlock:
  190.             [ boxOnDestImage draw1PartImageInRect: positions[i] ];
  191.             break;
  192.         case EmptyBlock:
  193.         default:
  194.             break;
  195.         }
  196.     }
  197.     if(menuFlag == NO)
  198.     {
  199.         [menuSwitch draw1PartImageInRect: menuSwitchPos];
  200.     }
  201. }
  202. // 释放资源
  203. - (void)dealloc
  204. {
  205.     [self dealloc];
  206.     [super dealloc];
  207. }
  208. // 提示信息
  209. -(void)showConfirm:(NSString *)msg Title:(NSString *)title
  210. {
  211.     [confirmSheet setTitle: title];
  212. [confirmSheet setBodyText: msg];
  213.     [confirmSheet popupAlertAnimated:YES];
  214. }
  215. // 提示信息处理
  216. -(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button
  217. {
  218.     switch(button) 
  219.     {
  220.     case 1: // YES
  221.         [self save];
  222.         isPlaying = NO;
  223.         [(MainView *)parentView showCover];
  224.         break;
  225.     case 2: // NO
  226.         // do nothing
  227.         break;
  228.     }
  229.     [sheet dismiss];
  230. }
  231. //////////////////////////////////////////////////////
  232. // 加载/保存
  233. //////////////////////////////////////////////////////
  234. -(void)load:(Mess)messdata
  235. {
  236.     mdata = messdata;
  237.     int i;
  238.     int x = 0, y = 0;
  239.     for(i=0;i<Map_LEN;i++)
  240.     {
  241.         x = (i % 14) * BoxSize + BorderSize;
  242. y = (i / 14) * BoxSize + BorderSize;
  243.         positions[i] = CGRectMake(x, y, BoxSize , BoxSize );
  244.         if(mdata.mapdata[i]==PlayerBlock || mdata.mapdata[i]== PlayerOnTargetBlock)
  245.             playerPos = i;
  246.     }
  247.     isPlaying = YES;
  248.     step = 0;
  249.     canUndo = NO;
  250.     [menuItemUndo setEnabled:NO];
  251.     [self setNeedsDisplayInRect:viewRect];
  252.     [self move:0];
  253. }
  254. - (void)save
  255. {
  256.     isPlaying = NO;
  257.     [Map SaveMess:mdata];    
  258. }
  259. - (void)reload
  260. {
  261.     [Map LoadChapter:mdata.chapterIndex Data:mdata.mapdata];
  262.     [self load:mdata];
  263. }
  264. //////////////////////////////////////////////////////
  265. // 属性
  266. //////////////////////////////////////////////////////
  267. // 是否正在游戏
  268. -(bool)IsPlaying
  269. {
  270.     return isPlaying;
  271. }
  272. //////////////////////////////////////////////////////
  273. // 控制
  274. //////////////////////////////////////////////////////
  275. // 鼠标按下
  276. - (void)mouseDown: (struct __GSEvent *)event
  277. {
  278.     CGPoint p = GSEventGetInnerMostPathPosition(event);
  279.     mDownXY = CGPointMake(p.x,p.y);
  280. }
  281. // 鼠标弹起
  282. - (void)mouseUp:(struct __GSEvent *)event
  283. {
  284.     CGPoint p = GSEventGetInnerMostPathPosition(event);
  285.     if(p.y>430) // 响应菜单
  286.     {
  287.         if(menuFlag==NO)
  288.         {
  289.             if(p.x<50)
  290.             {
  291.                 [self showNavBar];
  292.                 return;
  293.             }
  294.         }
  295.         else
  296.         {
  297.             // 响应菜单
  298.             return;
  299.         }
  300.     }
  301.     // 检查是否完成
  302.     if(isCompleted)
  303.     {
  304.         [self Pass];
  305.     }
  306.     else
  307.     {
  308.         // 响应移动
  309.         int x = mDownXY.x - p.x;
  310.         int y = mDownXY.y - p.y;
  311.     
  312.         bool turnx = x<0;
  313.         bool turny = y<0;
  314.     
  315.         if(turnx) x*=-1;
  316.         if(turny) y*=-1;
  317.     
  318.         if(x-y>5 || x-y <-5) // 精度5
  319.         {
  320.             if(x>y)
  321.             {
  322.                 if(turnx) [self move:4];     // right
  323.                 else [self move:3];          // left
  324.             }
  325.             else
  326.             {
  327.                 if(turny) [self move:2];    // down
  328.                 else [self move:1];         // up
  329.             }
  330.             step++; // 步数加一
  331.         }
  332.         else
  333.         {
  334.             //[self move:0];  // stay
  335.         }
  336.     }
  337. }
  338. // 玩家移动
  339. -(void)move:(int)dir;
  340. {
  341.     direct = dir;
  342.     switch(direct)
  343.     {
  344.     case 0:
  345.         [self setNeedsDisplayInRect:positions[playerPos]];
  346.         break;
  347.     case 1: // 上
  348.         if(playerPos<14 || mdata.mapdata[playerPos-14]== WallBlock)
  349.         {
  350.             break;
  351.         }
  352.         else
  353.         {
  354.             if((mdata.mapdata[playerPos-14]==BoxBlock || mdata.mapdata[playerPos-14]==BoxOnTargetBlock) && ([self moveBox:direct num:(playerPos-14)]==NO))
  355.             {
  356.                 break;
  357.             }
  358.             else
  359.             {
  360.                 mdata.mapdata[playerPos]-= PlayerBlock;
  361.                 mdata.mapdata[playerPos-14]+=PlayerBlock;
  362.                 [self setNeedsDisplayInRect:positions[playerPos]];
  363.                 [self setNeedsDisplayInRect:positions[playerPos-14]];
  364.                 playerPos -=14;
  365.             }
  366.         }
  367.         break;
  368.     case 2: // 下
  369.         if(playerPos>Map_LEN-14 || mdata.mapdata[playerPos+14]==WallBlock)
  370.         {
  371.             break;
  372.         }
  373.         else
  374.         {
  375.              if((mdata.mapdata[playerPos+14]==BoxBlock || mdata.mapdata[playerPos+14]==BoxOnTargetBlock)&& ([self moveBox:direct num:(playerPos+14)]==NO))
  376.              {
  377.                  break;
  378.              }
  379.              else
  380.             {
  381.                 mdata.mapdata[playerPos]-=PlayerBlock;
  382.                 mdata.mapdata[playerPos+14]+=PlayerBlock;
  383.                 [self setNeedsDisplayInRect:positions[playerPos]];
  384.                 [self setNeedsDisplayInRect:positions[playerPos+14]];
  385.                 playerPos +=14;
  386.             }
  387.         }
  388.         break;
  389.     case 3: // 左
  390.         if(playerPos%14==0 || mdata.mapdata[playerPos-1]==WallBlock)
  391.         {
  392.             break;
  393.         }
  394.         else
  395.         {
  396.              if((mdata.mapdata[playerPos-1]==BoxBlock  || mdata.mapdata[playerPos-1]==BoxOnTargetBlock)&& ([self moveBox:direct num:(playerPos-1)]==NO))
  397.              {
  398.                  break;
  399.              }
  400.              else
  401.             {
  402.                 mdata.mapdata[playerPos]-=PlayerBlock;
  403.                 mdata.mapdata[playerPos-1]+=PlayerBlock;
  404.                 [self setNeedsDisplayInRect:positions[playerPos]];
  405.                 [self setNeedsDisplayInRect:positions[playerPos-1]];
  406.                 playerPos--;
  407.             }
  408.         }
  409.         break;
  410.     case 4: // 右
  411.         if(playerPos%14==13 || mdata.mapdata[playerPos+1]==WallBlock)
  412.         {
  413.             break;
  414.         }
  415.         else
  416.         {
  417.         
  418.             if((mdata.mapdata[playerPos+1]==BoxBlock || mdata.mapdata[playerPos+1]==BoxOnTargetBlock) && ([self moveBox:direct num:(playerPos+1)]==NO))
  419.             {
  420.                 break;
  421.             }
  422.             else
  423.             {
  424.                 mdata.mapdata[playerPos]-=PlayerBlock;
  425.                 mdata.mapdata[playerPos+1]+=PlayerBlock;
  426.                 [self setNeedsDisplayInRect:positions[playerPos]];
  427.                 [self setNeedsDisplayInRect:positions[playerPos+1]];
  428.                 playerPos++;
  429.             }
  430.         }
  431.         break;
  432.     }
  433. }
  434. // 箱子移动
  435. - (bool)moveBox:(int)dir num:(int)n
  436. {
  437.     bool returnValue = NO;
  438.     switch(dir)
  439.     {
  440.     case 1: // 上
  441.         if(n<14 || mdata.mapdata[n-14]==WallBlock || mdata.mapdata[n-14]==BoxBlock || mdata.mapdata[n-14]== BoxOnTargetBlock)
  442.         {
  443.             returnValue = NO;
  444.         }
  445.         else
  446.         {
  447.             [self recordMess];
  448.             mdata.mapdata[n]-=BoxBlock;
  449.             mdata.mapdata[n-14]+=BoxBlock;
  450.             [self setNeedsDisplayInRect:positions[n]];
  451.             [self setNeedsDisplayInRect:positions[n-14]];
  452.             returnValue = YES;
  453.         }
  454.         break;
  455.     case 2: // 下
  456.         if(n>Map_LEN-14 || mdata.mapdata[n+14]==WallBlock || mdata.mapdata[n+14]==BoxBlock || mdata.mapdata[n+14]== BoxOnTargetBlock)
  457.         {
  458.             returnValue = NO;
  459.         }
  460.         else
  461.         {
  462.             [self recordMess];
  463.             mdata.mapdata[n]-=BoxBlock;
  464.             mdata.mapdata[n+14]+=BoxBlock;
  465.             [self setNeedsDisplayInRect:positions[n]];
  466.             [self setNeedsDisplayInRect:positions[n+14]];
  467.             returnValue = YES;
  468.         }
  469.         break;
  470.     case 3: // 左
  471.         if(n%14==0 || mdata.mapdata[n-1]== WallBlock || mdata.mapdata[n-1]==BoxBlock || mdata.mapdata[n-1]== BoxOnTargetBlock)
  472.         {
  473.             returnValue = NO;
  474.         }
  475.         else
  476.         {
  477.             [self recordMess];
  478.             mdata.mapdata[n]-=BoxBlock;
  479.             mdata.mapdata[n-1]+=BoxBlock;
  480.             [self setNeedsDisplayInRect:positions[n]];
  481.             [self setNeedsDisplayInRect:positions[n-1]];
  482.             returnValue = YES;
  483.         }
  484.         break;
  485.     case 4: // 右
  486.         if(n%14==13 || mdata.mapdata[n+1]==WallBlock || mdata.mapdata[n+1]==BoxBlock || mdata.mapdata[n+1]== BoxOnTargetBlock)
  487.         {
  488.             returnValue = NO;
  489.         }
  490.         else
  491.         {
  492.             [self recordMess];
  493.             mdata.mapdata[n]-=BoxBlock;
  494.             mdata.mapdata[n+1]+=BoxBlock;
  495.             [self setNeedsDisplayInRect:positions[n]];
  496.             [self setNeedsDisplayInRect:positions[n+1]];
  497.             returnValue = YES;
  498.         }
  499.         break;
  500.     }
  501.     return returnValue;
  502. }
  503. - (void)recordMess
  504. {
  505.     record = [Map MessCopy:mdata];
  506.     canUndo = YES;
  507.     [menuItemUndo setEnabled:YES];
  508. }
  509. - (void)undo
  510. {
  511.     if(canUndo == YES)
  512.     {
  513.         mdata = [Map MessCopy:record];
  514.         int i;
  515.         int x = 0, y = 0;
  516.         for(i=0;i<Map_LEN;i++)
  517.         {
  518.             x = (i % 14) * BoxSize + BorderSize;
  519.      y = (i / 14) * BoxSize + BorderSize;
  520.             positions[i] = CGRectMake(x, y, BoxSize , BoxSize );
  521.             if(mdata.mapdata[i]==PlayerBlock || mdata.mapdata[i]== PlayerOnTargetBlock)
  522.                 playerPos = i;
  523.         }
  524.         [self setNeedsDisplayInRect:viewRect];
  525.         [menuItemUndo setEnabled:NO];
  526.         canUndo = NO;
  527.     }
  528. }
  529. //////////////////////////////////////////////////////
  530. // 设置
  531. //////////////////////////////////////////////////////
  532. // 设备翻转
  533. -(void)changeOrientation:(int)neworient
  534. {
  535.     if(!lockOrient&&(neworient ==1||neworient ==2||neworient ==3||neworient ==4))
  536.     {
  537.         switch(neworient)
  538.         {
  539.         case 1:
  540.             orientation = 0;
  541.             break;
  542.         case 2:
  543.             orientation =1;
  544.             break;
  545.         case 3:
  546.             orientation =3;
  547.             break;
  548.         case 4:
  549.             orientation=2;
  550.             break;
  551.         }
  552.     
  553.         [playerImage setOrientation: orientation];
  554.         [playerUpImage setOrientation: orientation];
  555.         [playerDownImage setOrientation: orientation];
  556.         [playerLeftImage setOrientation: orientation];
  557.         [playerRightImage setOrientation: orientation];
  558.     
  559.         [self setNeedsDisplayInRect:positions[playerPos]];
  560.     }
  561. }
  562. // 设置主视图
  563. - (void)setParentView:(UIView*)view
  564. {
  565.     parentView = view;
  566. }
  567. // 检查是否过关
  568. - (void)Pass
  569. {
  570.     if(isCompleted)
  571.     {
  572.         if(mdata.isCustom)
  573.         {
  574.             // 返回自定义地图
  575.             [(MainView*)parentView customGame: YES];
  576.         }
  577.         else
  578.         {
  579.             // 进入下一关
  580.             [self nextChapter:YES];
  581.         }
  582.     }
  583. }
  584. - (void)preChapter
  585. {
  586.     if(mdata.isCustom)
  587.     {
  588.         // 返回自定义地图
  589.         [(MainView*)parentView customGame: YES];
  590.         return;
  591.     }
  592.     Mess nextdata;
  593.     nextdata.chapterIndex = mdata.chapterIndex;
  594.     nextdata.enableChapterCount = mdata.enableChapterCount;
  595.     nextdata.isCustom=NO;
  596.     if(nextdata.chapterIndex - 1 < 0)
  597.     {
  598.         nextdata.chapterIndex = nextdata.enableChapterCount - 1;
  599.     }
  600.     else
  601.     {
  602.         nextdata.chapterIndex--;
  603.     }
  604.     [Map LoadChapter:nextdata.chapterIndex Data:nextdata.mapdata];
  605.     [self load:nextdata];
  606.     [(MainView*)parentView showView: GAMEVIEW];
  607. }
  608. - (void)nextChapter:(bool)isPass
  609. {
  610.     if(mdata.isCustom)
  611.     {
  612.         // 如果是自定义地图,返回自定义地图选择界面
  613.         [(MainView*)parentView customGame: YES];
  614.         return;
  615.     }
  616.     Mess nextdata;
  617.     nextdata.chapterIndex = mdata.chapterIndex;
  618.     nextdata.enableChapterCount = mdata.enableChapterCount;
  619.     nextdata.isCustom=NO;
  620.     // 判断是否已经是最后一关
  621.     if(chapterCount>TOTAL_CHAPTER)
  622.     {
  623.         chapterCount = TOTAL_CHAPTER;
  624.     }
  625.     if(nextdata.chapterIndex + 1 >= chapterCount)
  626.     {
  627.         // 通过最后一关,进入第一关
  628.         nextdata.chapterIndex = 0;
  629.         nextdata.enableChapterCount = chapterCount;
  630.     }
  631.     else
  632.     {
  633.         // 是否过关
  634.         if(isPass)
  635.         {
  636.             // 过关进入下一关
  637.             nextdata.chapterIndex++;
  638.             // 判断下一关是否曾过
  639.             if(nextdata.chapterIndex >= nextdata.enableChapterCount)
  640.             {
  641.                 nextdata.enableChapterCount = nextdata.chapterIndex + 1;
  642.             }
  643.         }
  644.         else
  645.         {
  646.             if(nextdata.chapterIndex + 1 >= nextdata.enableChapterCount)
  647.             {
  648.                 nextdata.chapterIndex = 0;
  649.             }
  650.             else
  651.             {
  652.                 nextdata.chapterIndex++;
  653.             }
  654.         }
  655.     }
  656.     [Map LoadChapter:nextdata.chapterIndex Data:nextdata.mapdata];
  657.     [self load:nextdata];
  658.     [(MainView*)parentView showView: GAMEVIEW];
  659. }
  660. - (void)showNavBar
  661. {
  662. [menu setFrame:CGRectMake(0, 430, 320, 50)];
  663.     menuFlag = YES;
  664. }
  665. - (void)hideNavBar
  666. {
  667.     [menu setFrame:CGRectMake(0, 480, 320, 50)];
  668.     menuFlag = NO;
  669. }
  670. - (void)menuItemClick:(UIPushButton *)button
  671. {
  672.     if (button==menuItemHidden) {
  673.         [self hideNavBar];
  674.         [self setNeedsDisplayInRect:menuSwitchPos];
  675.     }
  676.     if (button==menuItemExit) {
  677.         [self showConfirm:@"Do you realy want to EXIT?" Title:@"Confirm"];
  678.     }
  679.     if (button==menuItemUndo) {
  680.         [self undo];
  681.     }
  682.     if (button==menuItemPreStage) {
  683.         [self preChapter];
  684.     }
  685.     if (button==menuItemNextStage) {
  686.         [self nextChapter:NO];
  687.     }
  688. }
  689. @end