OC enables simple light-off games

Source: Internet
Author: User
// Layout the lamp image in the view. Five rows and five columns for (INT I = 0; I <5; I ++) {for (Int J = 0; j <5; j ++) {uibutton * lightbutton = [uibutton buttonwithtype: uibuttontypesystem]; lightbutton. frame = cgrectmake (I * 64,120 + (J * 64), 64, 64); [lightbutton setbackgroundimage: [uiimage imagenamed: @ "2.png"] forstate: uicontrolstatenormal]; [lightbutton addtarget: self action: @ selector (Click :) forcontrolevents: uicontroleventtouchupinside]; [self. window addsubview: lightbutton]; lightbutton. tag = 100 + J + 10 * I; // The tag difference between the left and right buttons is 1, and the tag difference between the upper and lower buttons is 10 }}

// Button click event-(void) Click :( uibutton *) button {// defines the button clicked by the array storage and its upper and lower right button int array [5] = {button. tag, button. tag + 1, button. tag + 10, button. tag-1, button. tag-10}; // when the front butonbackground image is not a bright light (2.png is a bright image name) if ([button. currentbackgroundimage isequal: [uiimage imagenamed: @ "2.png"]) {// traverse the array for (INT I = 0; I <5; I ++) {uibutton * abutton = (uibutton *) [self. window viewwithtag: array [I]; // specifies the status of the top left and right buttoners that are clicked on. If it is an out-of-the-box lamp, change the background image to a bright lamp (1.png is an out-of-Box Lamp image) If. currentbackgroundimage isequal: [uiimage imagenamed: @ "1.png"]) {[abutton failed: [uiimage imagenamed: @" 2.png"] forstate: uicontrolstatenormal];} else {[abutton failed: [uiimage imagenamed: @ "1.png"] forstate: uicontrolstatenormal] ;}// else checks whether the background image of the current buton is out of light.} else {for (INT I = 0; I <5; I ++) {uibutton * abutton = (uibutton *) [self. window viewwithtag: array [I]; If ([abutton. currentbackgroundimage isequal: [uiimage imagenamed: @ "2.png"]) {[abutton success: [uiimage imagenamed: @" 1.png"] forstate: uicontrolstatenormal];} else [abutton failure: [uiimage imagenamed: @ "2.png"] forstate: uicontrolstatenormal] ;}}

OC enables simple light-off games

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.