现在的位置: 首页 > 综合 > 正文

关灯游戏主源码

2018年01月23日 ⁄ 综合 ⁄ 共 1300字 ⁄ 字号 评论关闭

- (void)viewDidLoad

{

    [super
viewDidLoad];

    // Do any additional setup after loading the view.

   
int tag = 1;

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

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

           
UIButton *imageButton = [UIButton
buttonWithType:UIButtonTypeCustom];

            imageButton.frame =
CGRectMake( 45 * j +
30, 45 * i +
80, 40,
40
);

            imageButton.backgroundColor = [UIColor
whiteColor];

            [imageButton addTarget:self
action:@selector(change:)
forControlEvents:UIControlEventTouchUpInside];

            [imageButton
setTag:tag++];

            [self.view
addSubview:imageButton];

        }

    }

    

   

    

}

- (void)change:(UIButton *)button

{

    [self
changeColor:button];

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

       
UIButton *leftButton = (UIButton *)[self.view
viewWithTag:button.tag -
1];

        

        [self
changeColor:leftButton];

    }

    

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

       
UIButton *rightButton = (UIButton *)[self.view
viewWithTag:button.tag +
1];

        [self
changeColor:rightButton];

    }

    

   
if (button.tag >
6) {

       
UIButton *upButton = (UIButton *)[self.view
viewWithTag:button.tag -
6];

        [self
changeColor:upButton];

    }

    

   
if (button.tag <
43) {

       
UIButton *downButton = (UIButton *)[self.view
viewWithTag:button.tag +
6];

        [self
changeColor:downButton];

    }

}

- (void)changeColor:(UIButton *)button

{

   
if (button.backgroundColor == [UIColor
whiteColor]) {

        button.backgroundColor = [UIColor
blackColor];

    }
else

    {

        button.backgroundColor = [UIColor
whiteColor];

    }

    

    

}

抱歉!评论已关闭.