2013年08月22日

续“打灰太狼”OC 代码:
        难度设置:(附带了声音的设置)[下面是设置界面的代码,也包括传值进game游戏界面的代码]
新建一个类,继承 UIViewController,下面是.h文件
@interface setViewController : UIViewController


{

    UISegmentedControl * enh;

    int h;

}

@property int h;

- (IBAction)back:(id)sender;

@property (strong,nonatomic) IBOutlet UISegmentedControl * enh;

- (IBAction)start:(id)sender;

-(IBAction)selectchange:(id)sender;

- (IBAction)shengyin:(id)sender;

@end

#import "setViewController.h"

#import "AppDelegate.h"

#import "MCSoundBoard.h"

@interface setViewController ()


@end

下面是.m文件

@implementation setViewController

@synthesize enh,h;

BOOL  isplay=YES;  //声音开关的变量

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

   

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    

}


- (IBAction)back:(id)sender {

    [AppDelegate switchViewController:1];  //回到主菜单

}

- (IBAction)start:(id)sender {

    [AppDelegate switchViewController:5];   //回到游戏界面

}


-(IBAction)selectchange:(id)sender{

    printf("%d",[enh selectedSegmentIndex]);

    h=[enh selectedSegmentIndex];  //传值

}

声音设置开关的控键

- (IBAction)shengyin:(id)sender {

  

    if (isplay) {

        [MCSoundBoard stopAudioForKey:@"loop1"];


    }

    else

    { [MCSoundBoard playAudioForKey:@"loop1"];}

        isplay=!isplay;

}

-(int)getenh

{

    return h;

   

}


@end


game界面代码:

AppDelegate * nowdelegate=[UIApplication sharedApplication].delegate;  //代理类

    setViewController *svController=nowdelegate.m_Set_VC;

    int  h=[svController.enh selectedSegmentIndex];  //接受h的值

    switch (h)

    {

        case 0:

            trm= [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(slete) userInfo:nil repeats:YES];    //简单程度3秒出现一个灰太狼

            break;

        case 1:

            trm= [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(slete) userInfo:nil repeats:YES];    //普通程度2秒出现一个灰太狼

            break;

        case 2:

            trm= [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(slete) userInfo:nil repeats:YES];    //困难程度1秒出现一个灰太狼

            break;

        default:

            break;

    }


AppDelegate * nowdelegate=[UIApplication sharedApplication].delegate;

    setViewController *svController=nowdelegate.m_Set_VC;

    int  h=[svController.enh selectedSegmentIndex];

    switch (h)

    {

        case 0:

            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(repmove) userInfo:nil repeats:NO];    //简单程度灰太狼在1秒消失

            break;

        case 1:

            [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(repmove) userInfo:nil repeats:NO];      //普通程度灰太狼在0.7秒消失

            break;

        case 2:

            [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(repmove) userInfo:nil repeats:NO];       //困难程度灰太狼在0.5秒消失

            break;

        default:

            break;

    }

游戏设置就是通过传值来设置game里面的变量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值