ios扫雷
就这些代码敲了我两个小时。。。。。。
// ViewController.m
// 扫雷
//
// Created by 晚起的蚂蚁 on 2017/3/22.
// Copyright © 2017年 晚起的蚂蚁. All rights reserved.
//
#define Width [UIScreen mainScreen].bounds.size.width
#define Height [UIScreen mainScreen].bounds.size.height
#define NUM //格子边长个数
#define NUMRED //雷的个数
#import "ViewController.h"
@interface ViewController ()
{
UIImageView* imageView;
NSMutableArray* dataSource;//雷的位置
NSMutableArray* allArr; //所有按钮的数字
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
[self createImageView];
[self createButton];
[self createData];
[self numberOfRedBtn];
}
//创建背景视图
-(void)createImageView{
, Width, Width)];
imageView.image=[UIImage imageNamed:@""];
imageView.userInteractionEnabled=YES;
imageView.backgroundColor=[UIColor greenColor];
[self.view addSubview:imageView];
, , )];
imageViewHeader.image=[UIImage imageNamed:@"0fd7eeeee49905d8e4d7f1b02b937f40.png"];
[self.view addSubview:imageViewHeader];
, , )];
imageViewFoot.image=[UIImage imageNamed:@"a10e9fc0ccdc64360c8a90f97918b0a3.png"];
[self.view addSubview:imageViewFoot];
}
//创建按钮
-(void)createButton{
CGFloat btnHeight=imageView.frame.size.width/NUM;
; i<NUM; i++) {
; j<NUM; j++) {
UIButton* btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn., btnHeight-);
btn.;
[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[btn.];
btn.layer.borderColor = [UIColor grayColor].CGColor;
btn.backgroundColor=[UIColor brownColor];
[imageView addSubview:btn];
}
}
}
//按钮点击事件
-(void)btnAction:(UIButton*)sender{
; i<dataSource.count; i++) {
if(sender.tag==[dataSource[i] intValue]){
NSArray* arr=[imageView subviews];
; k<arr.count; k++) {
];
]) {
btn.backgroundColor=[UIColor redColor];
}else{
[btn setTitle:allArr[k] forState:UIControlStateNormal];
btn.backgroundColor=[UIColor blueColor];
}
}
return;
}
}
] forState:UIControlStateNormal];
sender.backgroundColor=[UIColor blueColor];
}
//随机分布雷
-(void)createData{
dataSource=[NSMutableArray new];
int numB=NUM*NUM;
;
) {
number=(;
;
) {
[dataSource addObject:[NSString stringWithFormat:@"%d",number]];
}else if(dataSource.count<NUMRED){
for (NSString* str in dataSource) {
if ([str intValue]==number) break;
else time++;
if (time==dataSource.count) {
[dataSource addObject:[NSString stringWithFormat:@"%d",number]];
break;
}
}
}else{
break;
}
}
}
//非雷区的数字
-(void)numberOfRedBtn{
allArr=[NSMutableArray new];
; i<NUM*NUM; i++) {
[allArr addObject:@"0"];
}
//按钮的坐标
;
;
;
NSArray* btnArr=[imageView subviews];
for (UIButton* btn in btnArr) {
if ((btn.backgroundColor!=[UIColor redColor])) {
coordinateX=(btn.)%NUM;
coordinateY=(btn.)/NUM;
//左
) {
]) {
number++;
}
}else{
&&coordinateY<) {
)+(coordinateY+)*]) {
number++;
}
)+(coordinateY-)*]) {
number++;
}
}else{
)+(coordinateY+)*]) {
number++;
}
}
}
//右
) {
]) {
number++;
}
}else{
&&coordinateY<) {
)+(coordinateY+)*]) {
number++;
}
)+(coordinateY-)*]) {
number++;
}
}else{
)+(coordinateY-)*]) {
number++;
}
}
}
//上
) {
)*]) {
number++;
}
}else{
&&coordinateX<) {
)*)+]) {
number++;
}
)*)+]) {
number++;
}
}else{
)*)+]) {
number++;
}
}
}
//下
) {
)*]) {
number++;
}
}else{
&&coordinateX<) {
)*)+]) {
number++;
}
)*)+]) {
number++;
}
}else{
)*)+]) {
number++;
}
}
}
//中间按钮的斜角
&&coordinateY<&&coordinateX>&&coordinateX<) {
)*)+]) {
number++;
}
)*)+]) {
number++;
}
)*)+]) {
number++;
}
)*)+]) {
number++;
}
}
//将数据存入数组
NSString* numberStr=[NSString stringWithFormat:@"%ld",number];
//[btn setTitle:numberStr forState:UIControlStateNormal];
]=numberStr;
number=;
}
}
}
//判断是该按钮是否为雷
-(BOOL)tagIsEqulTag:(NSInteger)tag{
; i<dataSource.count; i++) {
if(tag==[dataSource[i] intValue]){
return YES;
}
}
return NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
ios扫雷的更多相关文章
- iOS 扫雷游戏
代码地址如下:http://www.demodashi.com/demo/11254.html 1.项目结构图 Viewcontroller:扫雷逻辑代码 LevelModel:扫雷难度选择代码 2. ...
- iOS - 适配 iOS 13 之工兵连扫雷
iOS 13 支持适配的机型 目前最新 iPhone 11.iPhone 11 Pro和iPhone 11 Pro Max iPhone X.iPhone XR.iPhone XS.iPhone XS ...
- 神奇的NOIP模拟赛 T1 LGTB 玩扫雷
LGTB 玩扫雷 在一个n m 的棋盘上,有位置上有雷(用“*” 表示),其他位置是空地(用“.” 表示).LGTB 想在每个空地上写下它周围8 个方向相邻的格子中有几个雷.请帮助他输出写了之后的棋盘 ...
- iOS开发环境C语言基础 数组 函数
1 求数组元素的最大值 1.1 问题 创建程序,实现查询数组中最大值的功能,需求为:创建一个长度为10的数组,数组内放置10个0~99之间(包含0,包含99)的随机数作为数组内容,要求查询出数组中的最 ...
- (史上最全的ios源码汇总)
按钮类 按钮 Drop Down Control http://www.apkbus.com/android-106661-1-1.html 按钮-Circular M ...
- 2015最新iOS学习线路图
iOS是由苹果公司开发的移动操作系统,以xcode为主要开发工具,具有简单易用的界面.令人惊叹的功能,以及超强的稳定性,已经成为iPhone.iPad 和iPod touch 的强大基础:iOS 内置 ...
- HDU 5965(三行扫雷 dp)
题意是在一个 3 行 n 列的图上进行扫雷,中间一行没有雷,且中间一行的每一格都会显示周围的雷数,问根据已知的雷数在上下两行设置地雷的方法数. 分析知每一列所填雷数的和与周围的雷数有关,但每列具体的填 ...
- HDU 5965 扫雷
扫雷游戏是晨晨和小璐特别喜欢的智力游戏,她俩最近沉迷其中无法自拔. 该游戏的界面是一个矩阵,矩阵中有些格子中有一个地雷,其余格子中没有地雷. 游戏中,格子可能处于己知和未知的状态.如果一个己知的格子中 ...
- 【BZOJ1088】扫雷(递推)
[BZOJ1088]扫雷(递推) 题面 BZOJ 题解 忽然发现这就是一道逗逼题. 只需要枚举一下第一个是什么,后面都能够推出来了.. #include<iostream> using n ...
随机推荐
- promise(3) '静态'方法
要是人没有梦想,跟咸鱼又有什么两样了?一直恐惧读源码,哪怕是一个简单的库也是读百来行遇到难点就放弃了.对于新的东西也仅仅是知道它拿来干什么,社区资源在哪里,要用时就突击文档资源使用即可.未有过深入之心 ...
- phpcms和php格式化时间戳
用PHPCMS V9 建站时,经常会用到时间标签,它是通用标签调用-日期时间格式化,适用全站. 一.日期时间格式化显示: a\标准型:{date('Y-m-d H:i:s', $rs['inputti ...
- springboot(十四):springboot整合shiro-登录认证和权限管理
这篇文章我们来学习如何使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉及到这方面的需求.在Java领域一般有Spring Security ...
- js判断密码强度是否符合
/** 判断密码强度是否符合 */ function check_passwd_intensity(password) { value = $.trim(password); if( value.le ...
- 导出CSV表格数据
<?php class Csv{ //导出csv文件 public function put_csv($list,$title){ $file_name="CSV".date ...
- 【LeetCode】190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
- js-ES6学习笔记-Set结构和Map结构
http://www.cnblogs.com/lonhon/ 1.ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set ...
- ReadTeacherObj
package JBJADV003;import java.io.*;public class ReadTeacherObj { /** * @param args */ public static ...
- [asp.net mvc 奇淫巧技] 05 - 扩展ScriptBundle,支持混淆加密javascript
一.需求: 在web开发中,经常会处理javascript的一些问题,其中就包括js的压缩,合并,发布版本以及混淆加密等等问题.在asp.net 开发中我们使用ScriptBundle已经可以解决ja ...
- JavaScript用typeof判断变量是数组还是对象,都返回object
在JavaScript中所有数据类型严格意义上都是对象,但实际使用中我们还是有类型之分,如果要判断一个变量是数组还是对象使用typeof搞不定,因为它全都返回object. 使用typeof加leng ...