The realization of the light-off game and the realization of the light-off game

Source: Internet
Author: User
Tags set background

The realization of the light-off game and the realization of the light-off game

UIImage * ima = [UIImage imageNamed: @ "1.png"]; for (int I = 0; I <5; I ++) {for (int j = 0; j <5; j ++) {ButtonSubview * button = [ButtonSubview buttonWithType: UIButtonTypeSystem]; button. frame = CGRectMake (5 + 63 * j, 100 + 63 * I, 58, 58); [button setBackgroundImage: ima forState: UIControlStateNormal]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside]; button. tag = 100 + I * 10 + j; button. flag = YES; // 0 [self. view addSubview: button] ;}} ButtonSubview * btn = [ButtonSubview buttonWithType: UIButtonTypeSystem]; btn. frame = CGRectMake (100,450,120, 40); [btn setTitle: @ "" forState: UIControlStateNormal]; [btn addTarget: self action: @ selector (touch :) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: btn];}

Set background and start button

-(Void) click :( ButtonSubview *) btn {UIImage * lamp = [UIImage imageNamed: @ "2.png"]; UIImage * ima = [UIImage imageNamed: @" 1.png"]; NSInteger a [5] = {btn. tag, btn. tag + 1, btn. tag-1, btn. tag + 10, btn. tag-10}; for (int I = 0; I <5; I ++) {ButtonSubview * button = (ButtonSubview *) [self. view viewWithTag: a [I]; if (button. flag = YES) {[button setBackgroundImage: lamp forState: UIControlStateNormal]; button. flag = NO;} else {[button setBackgroundImage: ima forState: UIControlStateNormal]; button. flag = YES ;}}// set the random light-on (void) touch (ButtonSubview *) bun {UIImage * lamp = [UIImage imageNamed: @ "2.png"]; UIImage * ima = [UIImage imageNamed: @ "1.png"]; for (int I = 100; I <145; I ++) {ButtonSubview * button = (ButtonSubview *) [self. view viewWithTag: I]; button. flag = arc4random () % 2; if (button. flag = 1) {[button setBackgroundImage: lamp forState: UIControlStateNormal]; button. flag = 0;} else {[button setBackgroundImage: ima forState: UIControlStateNormal]; button. flag = 1 ;}}}
Set to control the brightness of the surrounding lights until all the lights are turned off.



Algorithm for turning off the light game

I have done one before, but it is quite troublesome. to judge the boundary and the non-boundary, I just click one, and the four sides change. For example, it is an array of a (5, 5) and click a (2, 2) when (subscript starts with 0), a (), but this write is a bit complex, I don't know any better algorithms.

Write a light-off game in excel

Use VBA to write a small program, use if to determine the range, and use offset to set the data in the upper, lower, and left cells of a cell.
Set the background using the condition format.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.