关灯游戏
来源:互联网 发布:flag在c语言中的用法 编辑:程序博客网 时间:2024/04/27 14:26
#import "MainViewController.h"
#import "CustomView.h"
@interface MainViewController ()
@end
@implementation MainViewController
-(void)dealloc{
[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.
CustomView * View = [[CustomViewalloc]initWithFrame:CGRectMake(25,50, 260, 265)];
[View setBackgroundColor:[UIColorblueColor]];
[self.viewaddSubview:View];
[Viewrelease];
}
#import "CustomView.h"
@implementation CustomView
-(void)dealloc
{
[superdealloc];
}
- (id)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
// Initialization code
[selfcreatButton];
}
return self;
}
-(void)creatButton
{
int tag = 101;
for (int i =0; i < 5; i++) {
for (int j =0; j < 5; j++) {
UIButton * button =[[UIButtonalloc]initWithFrame:CGRectMake(10 +50 *j, 10 +50 * i, 40,40)];
[button setBackgroundColor:[UIColorwhiteColor]];
[button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[buttonsetTag:tag];
[selfaddSubview:button];
[buttonrelease];
tag ++;
}
tag +=5;
}
}
-(void)buttonAction:(id)sender
{
UIButton * button = (UIButton *)sender;
UIButton * leftButton = (UIButton *)[selfviewWithTag:button.tag -1];
UIButton * rightButton = (UIButton *)[selfviewWithTag:button.tag +1];
UIButton * downButton = (UIButton *)[selfviewWithTag:button.tag +10];
UIButton * aboveButton = (UIButton *)[selfviewWithTag:button.tag -10];
if (button.backgroundColor == [UIColorwhiteColor]) {
[button setBackgroundColor:[UIColoryellowColor]];
}else{
[button setBackgroundColor:[UIColorwhiteColor]];
}
if (aboveButton.backgroundColor == [UIColorwhiteColor]) {
[aboveButton setBackgroundColor:[UIColoryellowColor]];
}else{
[aboveButton setBackgroundColor:[UIColorwhiteColor]];
}
if (leftButton.backgroundColor == [UIColorwhiteColor]) {
[leftButton setBackgroundColor:[UIColoryellowColor]];
}else{
[leftButton setBackgroundColor:[UIColorwhiteColor]];
}
if (rightButton.backgroundColor == [UIColorwhiteColor]) {
[rightButton setBackgroundColor:[UIColoryellowColor]];
}else{
[rightButton setBackgroundColor:[UIColorwhiteColor]];
}
if (downButton.backgroundColor == [UIColorwhiteColor]) {
[downButton setBackgroundColor:[UIColoryellowColor]];
}else{
[downButton setBackgroundColor:[UIColorwhiteColor]];
}
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- IOS 关灯游戏
- 关灯游戏无限关
- 关灯游戏源代码
- ios关灯游戏源代码
- UI关灯游戏 代码
- OC关灯游戏
- UITouchView实现关灯游戏
- IOS UI 关灯游戏
- 关灯游戏代码
- 基数排序
- Map Reduce
- atnodes远程执行grep --color无高亮显示引发的RTFSC
- 【gdb调试笔记】
- JRainbow 0.3版本发布
- 关灯游戏
- [Android] 为Android安装BusyBox —— 完整的bash shell
- 学习Python(2)
- html学习(一)
- codeblocks 修改控制台
- Vlc-for-android源码分析
- HashMap,LinkedHashMap,TreeMap的区别
- python学习教程(十二),一个文本界面下网络聊天室
- 程序员如何找个白富美!!!