IOS UI 关灯游戏
来源:互联网 发布:连云港网络咨询招聘 编辑:程序博客网 时间:2024/04/30 08:16
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
#import "AppDelegate.h"
#import "mainViewController.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]]autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
mainViewController * main = [[mainViewController alloc]init];
[_window setRootViewController:main];
[main release];
[self.window makeKeyAndVisible];
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 = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
View * view = [[View alloc]initWithFrame:CGRectMake(0, 70, 320, 320)];
[view setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:view];
[view release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// 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
{
[super dealloc];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_lightArray = [[NSMutableArray alloc]init];
for (int i = 0; i < 25; i++) {
float x = 15 + (i % 5) * 60;
float y = 15 + (i / 5) * 60;
UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(x, y, 50,50)];
[button setImage:[UIImage imageNamed:@"110.png"]forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"119.png"]forState:UIControlStateSelected];
[button addTarget:self action:@selector(Action:)forControlEvents:UIControlEventTouchUpInside];
[_lightArray addObject:button];
[self addSubview:button];
[button release];
}
}
return self;
}
-(void)Action:(UIButton *)sender
{
//改变状态
sender.selected = !sender.selected;
//打印sender下标
NSLog(@"%d",[_lightArray indexOfObject:sender]);
//把下标存到index里
NSInteger index = [_lightArray indexOfObject:sender];
if (index%5 != 0) {
//获取左边的按钮
UIButton * button = [_lightArray objectAtIndex:index-1];
//改变状态(取反)
button.selected =! button.selected;
}
if (index >= 5 ) {
UIButton * button = [_lightArray objectAtIndex:index- 5];
button.selected =! button.selected;
}
if (index%5 != 4) {
UIButton * button =[_lightArray objectAtIndex:index + 1];
button.selected =! button.selected;
}
if (index<20) {
UIButton * button = [_lightArray objectAtIndex:index+5];
button.selected =! button.selected;
}
}
- IOS UI 关灯游戏
- UI关灯游戏 代码
- UI游戏实现 关灯游戏
- IOS 关灯游戏
- ios关灯游戏源代码
- 关灯游戏(iOS)
- ios 关灯游戏
- iOS 关灯游戏
- 初学UI之关灯游戏
- UI, 关灯游戏的实现
- IOS关灯游戏 无限关卡
- IOS关灯游戏的做法
- iOS实现简单的关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- 关灯游戏
- FPGA设计开发软件ISE使用技巧之:片上逻辑分析仪(ChipScope Pro)使用技巧
- [代码阅读]gem5 classic cache初步(3)
- 错误处理(Error Handling)
- cocos2dx3.x使用cocostudio触摸事件不响应的奇葩问题
- shell set -e
- IOS UI 关灯游戏
- iOS开发- 蓝牙后台接收数据(BLE4.0)
- 等弥侨矣赡腹焕客购诵韧止倮雌谑
- 错误的配置(Error configuration)
- 关闭tomcat6下的stdout日志
- 水墨江南
- ExpandoObject的使用
- Activity间通过Intent传递对象的方法
- 创建您自己的错误处理程序