OC关灯游戏
来源:互联网 发布:flag在c语言中的用法 编辑:程序博客网 时间:2024/04/30 14:37
#import <UIKit/UIKit.h>
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic) UIWindow *window;
@end
#import "AppDelegate.h"
#import "mainViewController.h"
@implementation AppDelegate
- (void)dealloc
{
[_windowrelease];
_window = nil;
[superdealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]]autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
mainViewController * main = [[mainViewControlleralloc]init];
[_windowsetRootViewController:main];
[mainrelease];
[self.windowmakeKeyAndVisible];
return YES;
}
#import <UIKit/UIKit.h>
@interface mainViewController :UIViewController
@end
#import "mainViewController.h"
#import "View.h"
@interface mainViewController ()
@end
@implementation mainViewController
- (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.
View * view = [[Viewalloc]initWithFrame:CGRectMake(0,70, 320, 320)];
[view setBackgroundColor:[UIColorblackColor]];
[self.viewaddSubview:view];
[viewrelease];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import <UIKit/UIKit.h>
@interface View : UIView
@property(retain,nonatomic)NSMutableArray * lightArray;
@end
#import "View.h"
@implementation View
- (void)dealloc
{
[superdealloc];
}
- (id)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
// Initialization code
_lightArray = [[NSMutableArrayalloc]init];
for (int i =0; i < 25; i++) {
float x = 15 + (i %5) * 60;
float y = 15 + (i /5) * 60;
UIButton * button = [[UIButtonalloc]initWithFrame:CGRectMake(x, y,50, 50)];
[button setImage:[UIImageimageNamed:@"110.png"]forState:UIControlStateNormal];
[button setImage:[UIImageimageNamed:@"119.png"]forState:UIControlStateSelected];
[button addTarget:selfaction:@selector(Action:)forControlEvents:UIControlEventTouchUpInside];
[_lightArrayaddObject:button];
[selfaddSubview:button];
[buttonrelease];
}
}
return self;
}
-(void)Action:(UIButton *)sender
{
//改变状态
sender.selected = !sender.selected;
//打印sender下标
NSLog(@"%d",[_lightArrayindexOfObject:sender]);
//把下标存到index里
NSInteger index = [_lightArrayindexOfObject:sender];
if (index%5 !=0) {
//获取左边的按钮
UIButton * button = [_lightArrayobjectAtIndex:index-1];
//改变状态(取反)
button.selected =! button.selected;
}
if (index >= 5 ) {
UIButton * button = [_lightArrayobjectAtIndex:index- 5];
button.selected =! button.selected;
}
if (index%5 !=4) {
UIButton * button =[_lightArrayobjectAtIndex:index + 1];
button.selected =! button.selected;
}
if (index<20) {
UIButton * button = [_lightArrayobjectAtIndex:index+5];
button.selected =! button.selected;
}
}
- OC关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- IOS 关灯游戏
- 关灯游戏无限关
- 关灯游戏源代码
- ios关灯游戏源代码
- UI关灯游戏 代码
- UITouchView实现关灯游戏
- IOS UI 关灯游戏
- 关灯游戏代码
- BD和ts是什么意思
- 一个阻塞队列引发的死锁和伪唤醒
- UI关灯游戏 代码
- VS2010编译警告:warning C4996: 'strcpy': This function
- vijos1579
- OC关灯游戏
- Word2013插入分隔符(分节符)实现任意页插入页码
- map data yet available
- 到处excel表格
- Python的包管理工具pip安装指南
- 江苏2012年高考零分作文非诚勿扰版
- CSS中的Position属性
- C11 随机数
- [深入理解计算机系统]C语言中的位运算、逻辑运算和移位运算