#import "sm2ViewController.h"
@implementation sm2ViewController
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
//数値を表示
-(void)updatedisplay
{
display.text=[NSString stringWithFormat:@"%d",count];
}
- (void)viewDidLoad
{
[super viewDidLoad];
srand(time(NULL));
[NSTimer scheduledTimerWithTimeInterval:1.5
target:self
selector:@selector(move:)
userInfo:nil
repeats:YES];
//解像度取得
CGRect r = [[UIScreen mainScreen] bounds];
CGFloat w = r.size.width;
CGFloat h = r.size.height;
NSLog(@"%f",h);
//音の指定
NSString *path= [[NSBundle mainBundle]
pathForResource:@"Alarm" ofType:@"caf"];
NSURL *url=[NSURL fileURLWithPath:path];
//NSLog(@"%s",path);
//
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url,&SoundID);
}
-(void)move:(NSTimer *)timer
{
//アニメーションの動きの定義
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
//iPhoneの解像度を取得する(これをすることで未来の解像度にも対応できるかも)
CGRect r = [[UIScreen mainScreen] bounds];
CGFloat w = r.size.width;
CGFloat h = r.size.height;
//CGFloatはfloat型なのでintにキャスト
int wid=(int)w;
int hei=(int)h;
//x,y座標rand()%hogeで0〜(hoge-1)までの数値をランダムで出力
int x = rand()%wid;
int y = rand()%hei;
//targetアウトレットのcenterプロパティ
target.center = CGPointMake(x,y);
//アニメーション終了
[UIView commitAnimations];
}
//あたらなかった場合のペナルティ
-(IBAction)nohit;
{
count=count-1;
[self updatedisplay];
}
//あたった場合に音が鳴る
-(IBAction)smash
{
AudioServicesPlaySystemSound(SoundID);
AudioServicesPlayAlertSound(SoundID);
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
//あたった場合カウントアップする
-(IBAction)countsmash
{
count = count+1;
[self updatedisplay];
}
//解像度取得メソッド
-(void)getresolution
{
CGRect r = [[UIScreen mainScreen] bounds];
CGFloat w = r.size.width;
// CGFloat h = r.size.height;
NSLog(@"%f",w);
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
2011年11月2日水曜日
テスト
« 次の投稿
No response to “テスト”
Leave a Reply