关灯游戏源码(iOS)
就是点一下灯 它本身和周围4盏灯会变色
ViewController.m文件
#import "ViewController.h"
#import "UIView+change.h"
@interface ViewController ()
@property(assign,nonatomic)int totalColums; @property(assign,nonatomic)NSInteger tag;
@property(strong,nonatomic)UIButton *btn;
@end
@implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
CGFloat height=;
CGFloat width=;
self.view.tag=;
self.totalColums=; CGFloat marginX=(self.view.frame.size.width-width*self.totalColums)/(self.totalColums+);
CGFloat marginY=;
for (int i=; i<; i++) {
int row=i/self.totalColums;
int col=i%self.totalColums;
CGFloat appX=marginX+col*(width+marginX);
CGFloat appY=marginY+row*(height+marginY);
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(appX, appY, width, height)];
btn.backgroundColor=[UIColor redColor];
[btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchDown];
btn.tag=i;
[self.view addSubview:btn];
} }
/**
* 点击事件
*
*
*/
-(void)onClick:(UIButton *)btn{
[btn change];
self.btn=btn;
self.tag=btn.tag;
[self lie];
[self sigiao];
[self hang];
[self qita];
}
/**
* 最左边一列和最右边一列
*/
-(void)lie{ if ((self.tag%self.totalColums==||self.tag%self.totalColums==)&&(self.tag/self.totalColums!=&&self.tag/self.totalColums!=)) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
if (self.tag%self.totalColums==) {
[[self.view viewWithTag:self.tag+] change];
}else if(self.tag%self.totalColums==){
[[self.view viewWithTag:self.tag-] change];
}
}
}
/**
* 最上面一行和最下面一行
*/ -(void)hang{ if ((self.tag/self.totalColums==||self.tag/self.totalColums==)&&(self.tag%self.totalColums!=&&self.tag%self.totalColums!=)) {
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+] change];
if (self.tag/self.totalColums==) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag/self.totalColums==){
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
} }
/**
* 四个角
*/
-(void)sigiao{ if (self.tag==) {
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if (self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag==-self.totalColums){
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}else if(self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
}
/**
* 其他的
*/
-(void)qita{ if (self.tag/self.totalColums!=&&self.tag/self.totalColums!=&&self.tag%self.totalColums!=&&self.tag%self.totalColums!=) {
[[self.view viewWithTag:self.tag-self.totalColums]change];
[[self.view viewWithTag:self.tag-]change];
[[self.view viewWithTag:self.tag+self.totalColums]change];
[[self.view viewWithTag:self.tag+] change];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import "ViewController.h"
#import "UIView+change.h"
@interface ViewController ()
@property(assign,nonatomic)int totalColums; @property(assign,nonatomic)NSInteger tag;
@property(strong,nonatomic)UIButton *btn;
@end
@implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
CGFloat height=;
CGFloat width=;
self.view.tag=;
self.totalColums=; CGFloat marginX=(self.view.frame.size.width-width*self.totalColums)/(self.totalColums+);
CGFloat marginY=;
for (int i=; i<; i++) {
int row=i/self.totalColums;
int col=i%self.totalColums;
CGFloat appX=marginX+col*(width+marginX);
CGFloat appY=marginY+row*(height+marginY);
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(appX, appY, width, height)];
btn.backgroundColor=[UIColor redColor];
[btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchDown];
btn.tag=i;
[self.view addSubview:btn];
} }
/**
* 点击事件
*
*
*/
-(void)onClick:(UIButton *)btn{
[btn change];
self.btn=btn;
self.tag=btn.tag;
[self lie];
[self sigiao];
[self hang];
[self qita];
}
/**
* 最左边一列和最右边一列
*/
-(void)lie{ if ((self.tag%self.totalColums==||self.tag%self.totalColums==)&&(self.tag/self.totalColums!=&&self.tag/self.totalColums!=)) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
if (self.tag%self.totalColums==) {
[[self.view viewWithTag:self.tag+] change];
}else if(self.tag%self.totalColums==){
[[self.view viewWithTag:self.tag-] change];
}
}
}
/**
* 最上面一行和最下面一行
*/ -(void)hang{ if ((self.tag/self.totalColums==||self.tag/self.totalColums==)&&(self.tag%self.totalColums!=&&self.tag%self.totalColums!=)) {
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+] change];
if (self.tag/self.totalColums==) {
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag/self.totalColums==){
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
} }
/**
* 四个角
*/
-(void)sigiao{ if (self.tag==) {
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if (self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag+self.totalColums] change];
}else if(self.tag==-self.totalColums){
[[self.view viewWithTag:self.tag+] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}else if(self.tag==){
[[self.view viewWithTag:self.tag-] change];
[[self.view viewWithTag:self.tag-self.totalColums] change];
}
}
/**
* 其他的
*/
-(void)qita{ if (self.tag/self.totalColums!=&&self.tag/self.totalColums!=&&self.tag%self.totalColums!=&&self.tag%self.totalColums!=) {
[[self.view viewWithTag:self.tag-self.totalColums]change];
[[self.view viewWithTag:self.tag-]change];
[[self.view viewWithTag:self.tag+self.totalColums]change];
[[self.view viewWithTag:self.tag+] change];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
类目文件UIView+change.h
#import <UIKit/UIKit.h> @interface UIView (change)
/**
* 变颜色
*/
-(void)change;
@end
UIView+change.m
#import "UIView+change.h" @implementation UIView (change)
-(void)change{
if (self.backgroundColor==[UIColor redColor]) {
self.backgroundColor=[UIColor blueColor];
}else{
self.backgroundColor=[UIColor redColor];
}
}
@end
运行效果

关灯游戏源码(iOS)的更多相关文章
- ios源码-ios游戏源码-ios源码下载
游戏源码 一款休闲类的音乐小游戏源码 该源码实现了一款休闲类的音乐小游戏源码,该游戏的源码很简单,而且游戏的玩法也很容易学会,只要我们点击视图中的grid,就可以 人气:2943运行环境:/Xco ...
- iOS版打地鼠游戏源码
打地鼠游戏源码,游戏是一款多关卡基于cocos2d的iPad打地鼠游戏源码,这也是一款高质量的打地鼠游戏源码,可以拥有逐步上升的关卡的设置,大家可以在关卡时设置一些商业化的模式来盈利的,非常完美的一款 ...
- ios跑酷游戏源码完整版
今天在网上看到了一个很流行的ios游戏源码,酷跑游戏源码,个人下载感觉非常不错,运行起来非常不错的,大家可以研究一下吧,由于源码文件较大,没有上传,请大家见谅. 由于文件较大,没有上传了,大家可以到这 ...
- 卡通风格的连连看ios游戏源码
卡通风格的连连看游戏源码,该游戏是一款韩国人做的卡通风格的ios连连看游戏源码,源码设计的效果非常漂亮的,而且运行起来感觉也很好.1.游戏采用倒计时模式2.该游戏是一款社交游戏,需要通过faceboo ...
- ios球体弹跳游戏源码
一款耐玩的ios游戏源码,画面上有很多小星星,球体落下的时候,你需要在画面上画出一条条的线条让球体弹跳起来然后吃掉小星星,如果没借助球体就失败了.游戏有很多关卡.注意: <ignore_js_o ...
- 实例源码--IOS高仿微信打飞机游戏(完整功能)
下载源码 技术要点: 1. IOS游戏开发基础框架 2. 高仿打飞机游戏 3. 游戏背景音频技术 4.源码详细的中文注释 ……. 详细介绍: 1. IOS游戏开发基础框架 此套源码为涉及IOS游戏开发 ...
- 比较不错的一个ios找茬游戏源码
找茬游戏源码 ,这个是一款非常不错的ios找茬游戏源码,该游戏的兼容性非常好的,并且还可以支持ipad和iphone,UI界面设计得也很漂亮,游戏源码真的是一款非常完美,而且又很完整的一款休闲类的游戏 ...
- ios版弹珠游戏源码
这个是我们比较喜欢玩的一直小游戏的,ios版弹珠游戏源码,该游戏源码来着IOS教程网其他网友提供上传的,大家可以了解一下吧. nore_js_op> <ignore_js_op&g ...
- ios水果风暴游戏源码下载
游戏源码是从那个IOS教程网IOS.662p.com分享给大家的. 这是一款ios水果风暴游戏源码下载,介绍给大家一下,喜欢的朋友可以下载学习一下吧.应用介绍:这是一个以获得高分和挑战更高难度为目的的 ...
随机推荐
- Python 闭包
什么是闭包? 闭包(closure)是词法闭包(lexical closure)的简称.闭包不是新奇的概念,而是早在高级程序语言开始发展的年代就已产生. 对闭包的理解大致分为两类,将闭包视为函数或者是 ...
- 快乐的JS正则表达式(开篇)
我不喜欢一开始就去讨论某某有多强大,因为我觉得那样没意思,首先我们的知道它是干什么,对我们有啥用,再去讨论它的强大之处也不迟.那和往常一样我们先来看几个例子. var arr = [1,4,2,5,2 ...
- 【struts2】OGNL
1 OGNL概述 OGNL是对象图导航语言Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言(Expression Language,简称为EL),通 ...
- RandomUser – 生成随机用户 JSON 数据的 API
RandomUser 是一个 API,它为您提供了一个或者一批随机生成的用户.这些用户可以在 Web 应用程序原型中用作占位符,将节省您创建自己的占位符信息的时间.您可以使用 AJAX 或其他方法来调 ...
- node debug包
'use strict'; var debug = require('debug')('http') , http = require('http') , name = 'My App'; // fa ...
- XPATH使用总结
最近公司里需要写一些爬虫项目,所以去接触学习了xpath的内容.在w3c上给出了xpath的语法,但是我感觉不全,而且讲得也不详细,我又去网上找了一些文章,总结一下. 这几个都是比较常用的,能解决基本 ...
- API Design
REST API Design Guidelines V 1.0.201208 Draft 5 Last Updated: 08/31/2012 1 简介 本文档旨在规范REST API的 ...
- mysql update时报错You are using safe update mode
在使用mysql执行update的时候,如果不是用主键当where语句,会报如下错误,使用主键用于where语句中正常. ) Error Code: . You are using safe upda ...
- JS 数组去重的几个方法
Array.prototype.unique1 = function () { var n = []; //一个新的临时数组 for (var i = 0; i < this.length; i ...
- 设计模式--建造者(Builder)模式
将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示 --<设计模 ...