您的位置:首页 > 产品设计 > UI/UE

UI关灯游戏 代码

2014-04-09 21:00 393 查看
#import "GameViewController.h"

@interface
GameViewController ()

@end

@implementation GameViewController

- (void) dealloc
{

[_nameLabel
release];

_nameLabel =
nil;
[super
dealloc];


}

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

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

if (self) {

// Custom initialization
}

return
self;
}

- (void)viewDidLoad
{

[super
viewDidLoad];

// Do any additional setup after loading the view.



_nameLabel =[[UILabel
alloc] initWithFrame:CGRectMake(60,
20,
200, 40)];

[_nameLabel
setBackgroundColor:[UIColor
whiteColor]];

[_nameLabel
setText:@"白雪公主的黑暗骑士丶"];

UIFont * font = [UIFont
boldSystemFontOfSize:20];
[_nameLabel
setFont:font];

[_nameLabel
setTextAlignment:NSTextAlignmentCenter];

[_nameLabel
setTextColor:[UIColor
redColor]];
[self.view
addSubview:_nameLabel];

[_nameLabel
release];



UILabel * ziLabel = [[UILabel
alloc] initWithFrame:CGRectMake(60,
420, 200,
40)];

[ziLabel setBackgroundColor:[UIColor
whiteColor]];
[ziLabel
setText:@"小火龙丶就决定是你了"];

UIFont * font1 = [UIFont
boldSystemFontOfSize:20];
[ziLabel
setFont:font1];

[ziLabel setTextAlignment:NSTextAlignmentCenter];

[ziLabel setTextColor:[UIColor
redColor]];
[self.view
addSubview:ziLabel];
[ziLabel
release];



[self
creatImageButton];

}

- (void) creatImageButton
{



int tag = 1;

for (int i =
0; i < 7; i++) {

for (int j =
0; j < 6; j++) {

UIButton * button = [[UIButton
alloc] initWithFrame:CGRectMake(10 +
50 * j, 70 +
50 * i, 50,
50)];





[button setImage:[UIImage
imageNamed:@"321.png"]
forState:UIControlStateNormal];



[button setImage:[UIImage
imageNamed:@"000.png"]
forState:UIControlStateSelected];



[button addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchUpInside];
[button
setTag:tag++];
[self.view
addSubview:button];
[button
release];
}
}


}

- (void) buttonAction:(UIButton*)sender
{



NSLog(@"%d",sender.tag);
[sender
setSelected:![sender
isSelected]];


if ((sender.tag %
6 != 1) ) {

UIButton * abutton = (UIButton*)[self.view
viewWithTag:sender.tag-1];
[abutton
setSelected:![abutton
isSelected]];
}

if ((sender.tag %
6 != 0) ) {

UIButton * abutton = (UIButton*)[self.view
viewWithTag:sender.tag+1];
[abutton
setSelected:![abutton
isSelected]];
}



if (sender.tag >
6) {

UIButton * abutton = (UIButton*)[self.view
viewWithTag:sender.tag-6];
[abutton
setSelected:![abutton
isSelected]];
}

if (sender.tag <
37) {

UIButton * abutton = (UIButton*)[self.view
viewWithTag:sender.tag+6];
[abutton
setSelected:![abutton
isSelected]];
}




}

---------------------------------分割线---------------------------------------

GameViewController.h

#import <UIKit/UIKit.h>

@interface GameViewController :
UIViewController

//显示游戏名

@property (retain,
nonatomic) UILabel * nameLabel;

@end

---------------------------------分割线---------------------------------------

#import "AppDelegate.h"

#import "GameViewController.h"

@implementation AppDelegate

- (void) dealloc
{
[_window
release];

_window = nil;
[super
dealloc];




}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{

self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];

// Override point for customization after application launch.

self.window.backgroundColor = [UIColor
whiteColor];



GameViewController * game = [[GameViewController
alloc]
init];

[self.window
setRootViewController:game];



[self.window
makeKeyAndVisible];

return
YES;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: