Simple light-off games without checkpoints

Source: Internet
Author: User

There are two images


Create a closelight class

Closelight. h

import <UIKit/UIKit.h>@interface CloseLight : UIViewController@property (nonatomic , assign)NSInteger tag;@end

Closelight. m

# Import "closelight. H "@ interface closelight () @ end @ implementation closelight-(ID) initwithnibname :( nsstring *) bundle :( nsbundle *) handle {self = [Super initwithnibname: nibnameornil Bundle: nibbundleornil]; If (Self) {// custom initialization} return self;}-(void) viewdidload {[Super viewdidload]; self. view. backgroundcolor = [uicolor whitecolor]; // do any additional setup after loading the view. uiview * view = [[uiview alloc] initwithframe: cgrectmake (15, 50,290,310)]; view. backgroundcolor = [uicolor browncolor]; view. layer. cornerradius = 10; [self. view addsubview: View]; [view release]; _ Tag = 10000; For (INT I = 0; I <5; I ++) {for (Int J = 0; j <5; j ++) {uibutton * button = [uibutton buttonwithtype: uibuttontypecustom]; [Button setframe: cgrectmake (10 + 10 * j + 45 * J, 14 + 14 * I + 45 * I, 50, 50)]; // [Button setbackgroundcolor: [uicolor redcolor]; [Button setbackgroundimage: [uiimage imagenamed: @ "1"] forstate: uicontrolstatenormal]; button. layer. cornerradius = 5; [Button addtarget: Self action: @ selector (gobutton :) forcontrolevents: uicontroleventtouchupinside]; button. tag = _ Tag + 1000 * (I + 1) + (J + 1); [view addsubview: button] ;}} uibutton * button = [uibutton buttonwithtype: uibuttontypesystem]; [Button settitle: @ "Start game" forstate: uicontrolstatenormal]; button. frame = cgrectmake (120,310, 60, 30); [Button addtarget: Self action: NULL forcontrolevents: uicontroleventtouchupinside]; [view addsubview: button];}-(void) change :( uibutton *) button {// uicolor * newcolor = button. backgroundcolor; uiimage * image = [Button backgroundimageforstate: 1]; If (image = [uiimage imagenamed: @ "1"]) {// [Button setbackgroundcolor: [uicolor blackcolor]; [Button setbackgroundimage: [uiimage imagenamed: @ "2"] forstate: uicontrolstatenormal];} else if (image = [uiimage imagenamed: @ "2"]) {// [Button setbackgroundcolor: [uicolor redcolor]; [Button setbackgroundimage: [uiimage imagenamed: @ "1"] forstate: uicontrolstatenormal];} -(void) gobutton :( ID) sender {uibutton * newbutton = (uibutton *) sender; [self change :( uibutton *) [self. view viewwithtag: newbutton. tag]; [self change :( uibutton *) [self. view viewwithtag: newbutton. tag + 1]; [self change :( uibutton *) [self. view viewwithtag: newbutton. tag-1]; [self change :( uibutton *) [self. view viewwithtag: newbutton. tag + 1000]; [self change :( uibutton *) [self. view viewwithtag: newbutton. tag-1000];}-(void) didreceivememorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .}



Appdelegate. m

#import "AppDelegate.h"#import "CloseLight.h"@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    CloseLight *light = [[CloseLight alloc] init];    self.window.rootViewController = light;            [_window release];    return YES;}- (void)dealloc{    [_window release];    [super dealloc];}- (void)applicationWillResignActive:(UIApplication *)application{    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application{    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application{    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application{    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application{    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end




This article from the "Liu _ blog" blog, please be sure to keep this source http://liuyafang.blog.51cto.com/8837978/1548160

Simple light-off games without checkpoints

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.