UI关灯游戏 代码

来源:互联网 发布:flag在c语言中的用法 编辑:程序博客网 时间:2024/04/27 20:22


#import "GameViewController.h"



@interface GameViewController ()


@end


@implementation GameViewController


- (void) dealloc

{


    [_nameLabel release];

    _nameLabel = nil;

    [superdealloc];

    

}


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

{

   self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];

   if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view.


    

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

    [_nameLabelsetBackgroundColor:[UIColorwhiteColor]];

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

    UIFont * font = [UIFontboldSystemFontOfSize:20];

    [_nameLabelsetFont:font];

    [_nameLabelsetTextAlignment:NSTextAlignmentCenter];

    [_nameLabelsetTextColor:[UIColorredColor]];

    [self.viewaddSubview:_nameLabel];

    [_nameLabel release];

    

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

    [ziLabel setBackgroundColor:[UIColorwhiteColor]];

    [ziLabelsetText:@"小火龙丶就决定是你了"];

   UIFont * font1 = [UIFontboldSystemFontOfSize:20];

    [ziLabelsetFont:font1];

    [ziLabel setTextAlignment:NSTextAlignmentCenter];

    [ziLabel setTextColor:[UIColorredColor]];

    [self.viewaddSubview:ziLabel];

    [ziLabelrelease];

    


    [selfcreatImageButton];



}


- (void) creatImageButton

{

    

   int tag = 1;

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

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

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

            

            

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

            

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

            

            [button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];

            [buttonsetTag:tag++];

            [self.viewaddSubview:button];

            [buttonrelease];

        }

    }

    

}


- (void) buttonAction:(UIButton*)sender

{

    

   NSLog(@"%d",sender.tag);

    [sendersetSelected:![sender isSelected]];


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

       UIButton * abutton = (UIButton*)[self.viewviewWithTag:sender.tag-1];

        [abuttonsetSelected:![abutton isSelected]];

    }

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

       UIButton * abutton = (UIButton*)[self.viewviewWithTag:sender.tag+1];

        [abuttonsetSelected:![abutton isSelected]];

    }

    

   if (sender.tag >6) {

       UIButton * abutton = (UIButton*)[self.viewviewWithTag:sender.tag-6];

        [abuttonsetSelected:![abutton isSelected]];

    }

   if (sender.tag <37) {

       UIButton * abutton = (UIButton*)[self.viewviewWithTag:sender.tag+6];

        [abuttonsetSelected:![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

{

    [_windowrelease];

   _window = nil;

    [superdealloc];

    

    

}


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

{

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColorwhiteColor];


    

    GameViewController * game = [[GameViewControlleralloc] init];

    [self.windowsetRootViewController:game];

    


    [self.windowmakeKeyAndVisible];

    return YES;

}



0 0
原创粉丝点击