续“打灰太狼”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里面的变量。