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.