,点击第一项建立,得到如图2所示
图2
单击Next,进入如 图3 的界面
图3
在空格中填入项目名称,将下拉箭头中的iPad改为iPhone,点击Next,进入下一界面,如图4所示
图4
单击Creat项目就创建成功了,最终界面如图5所示
图5
到图5所示后,Xcode的创建就完成了,要实现相应的功能就要依赖软件的编程和对一些图片的设置了。
三、程序的编写和实现
1、程序的编写
(1)MainViewController.h文件的程序
#import "FlipsideViewController.h"
#import
#import
#import
#import "BoardView.h"
#define BRICKHIGHT 15
#define BRICKWIDTH 44
#define BOARDHIGHT 10
#define BOARDWIDTH 48
#define TOP 40
@interface MainViewController : UIViewController {
IBOutlet UILabel *highestLabel;
IBOutlet UILabel *levelLabel;
IBOutlet UILabel *scoreLabel;
NSTimer *timer;
UIImageView *ball;
CGPoint moveDis;
BoardView *board;
NSMutableArray *bricks;
int level,numOfBricks,score,highest;
double speed;
NSString *soundFile;
}
@property int level,score,highest;
@property int numOfBricks;
@property double speed;
@property(nonatomic,retain)NSString *soundFile;
- (IBAction)onLeft:(id)sender;
- (IBAction)onRight:(id)sender;
- (IBAction)onStart:(id)sender;
- (void)levelMap:(int)inlevel;
-(void)playSound:(NSString*)soundAct;
- (IBAction)showInfo:(id)sender;
@end
(2)MainViewController.m文件的程序
#import "MainViewController.h"
@implementation MainViewController
@synthesize level;
@synthesize numOfBricks;
@synthesize speed,score,highest;
@synthesize soundFile;
-(void)playSound:(NSString*)soundAct{
NSString *path = [NSString stringWithFormat:@"%@%@",
[[NSBundle mainBundle] resourcePath],
soundAct];
NSLog(@"%@\n", path);
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
[filePath release];
}
- (IBAction)onLeft:(id)sender {
[UIImageView beginAnimations:@"animLeft" context:NULL];
[UIImageView setAnimationDuration:0.2];
board.center=CGPointMake(board.center.x-20, board.center.y);
[UIImageView commitAnimations];
soundFile = [NSString stringWithFormat:@"/button_press.caf"];
[self playSound: soundFile];
}
- (IBAction)onRight:(id)sender {
[UIImageView beginAnimations:@"animRight" context:NULL];
[UIImageView setAnimationDuration:0.2];
board.center=CGPointMake(board.center.x+20, board.center.y);
[UIImageView commitAnimations];
soundFile = [NSString stringWithFormat:@"/button_press.caf"];
[self playSound: soundFile];
}
- (IBAction)onStart:(id)sender {
if(!timer){timer=[NSTimer scheduledTimerWithTimeInterval:speed target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
ball.frame=CGRectMake(160, 328, 32, 32);
[self.view addSubview:ball];
board.frame=CGRectMake(160, 360, 48, 10);
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
moveDis=CGPointMake(-3, -3);
speed=0.03;
board=[[BoardView alloc] initWithImage:[UIImage imageNamed:@"board.png"]];
[board setUserInteractionEnabled:YES];
board.frame=CGRectMake(160, 360, BOARDWIDTH, BOARDHIGHT);
ball=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ball.png"]];
[self.view addSubview:board];
level=1; score=0; highest=0;
levelLabel.text=[NSString stringWithFormat:@"游戏级别: %i",level];
scoreLabel.text=[NSString stringWithFormat:@"现时得分: %i",score];
highestLabel.text=[NSString stringWithFormat:@"最高成绩: %i",highest];
[self levelMap:lev