Program Log--ios "Test reaction poker Game" program

Source: Internet
Author: User

Give me the tools to do the program: Mac OS X virtual machine 10.9.3 Xcode6 Baidu-^-^ reference IPhone30 Day Proficient


Summary and experience, as well as the problems encountered, are written in the program, look at the long, in fact, from the beginning to look down 10 minutes are all understand, my comments are "vernacular."


ViewController.h

12.1
//
Created by Liddy on 15-7-28.
Copyright (c) 2015 Liddy. All rights reserved.
//
/*
Here to summarize this procedure: I this program and the logic of the book is not the same, I use the loop of the timer, I think the book is not suitable for me to write the idea of the program.
This program did a day
1. There is a new control "Uiimageview" used to display the picture of the control, put the control in the storyboard inside their own size, you can display the picture on "Uiimageview", the picture format will be displayed in PNG format, The image is then added to the folder, and the display is called "imagename.image = [UIImage imagenamed:@" Name.png "];" Method can be used.
2. There is really nothing to say at the back, the specific experience and the process of writing the problems encountered in the program is written out.
*/
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface viewcontroller:uiviewcontroller{
Iboutlet Uiimageview *pokerimage;
NSDate * StartDate;
Nstimer * TIMER;
}

@property Uiimageview *pokerimage;
@property NSDate *startdate;
@property Nstimer *timer;

-(ibaction) pokerpressed;


@end


//VIEWCONTROLLER.M
12.1
//
Created by Liddy on 15-7-28.
Copyright (c) 2015 Liddy. All rights reserved.
//

#import "ViewController.h"

@interface Viewcontroller ()


@end

@implementation Viewcontroller
@synthesize Startdate,pokerimage,timer;

int Spadeon;

-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.
When the View controller (Viewcontroller) reads into memory, a prompt box is created to introduce the game

Define the game Poker Image View object as "back of Poker"----The back of poker at the beginning
Pokerimage.image = [UIImage imagenamed:@ "0000.png"];

Show this prompt box, the following prompt box has only one "OK" option, when the dialog box is hidden when determined
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "test reaction Poker" message:@ "press poker at the fastest speed when the spades appear" delegate:self cancelbuttontitle:@ "game start" otherbuttontitles:nil, nil];
[Alert show];
}


Next is the way to start the game, but also the default method of Uialertview, when the prompt box is hidden when the code is automatically executed, do not need to implement the agent or anything, just write the method name right
-(void) Alertview: (Uialertview *) Alertview Diddismisswithbuttonindex: (Nsinteger) buttonindex{

Let the "controller" Spadeon to 0, so if you just start to click on Poker, there is a hint that the response is wrong.
Spadeon = 0;

Do timer, change the game display of Poker regularly
To determine whether the timer is open, open it, if it is open, do not have to tube, so with an if statement control.
IsValid This method is to determine if the timer is running and returns a Boolean type value
I do this timer is to let it repeat the execution, every 1 seconds for a poker, so in the click on the poker and then make a click on the correct judgment, you need to pause the timer, that is, in the Pokerpressed method to make a pause action.
if (![ Self.timer IsValid]) {
Self.timer = [Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (Onacetimer) Userinfo:nil Repeats:yes];
Note: I have been a bug in the previous program, that is, the way to stop the back of the timer has not worked, the reason is that my previous statement did not "Self.timer =" This code, that is, I defined the timer has been a null pointer, so there is no way to give this null pointer timer, and then added " Self.timer = "After this code, the timer can be paused using the pause statement.
}
}


This is a click on the poker response method, linked to this method is the button, I put the button to enlarge, let it spread on the picture of Poker, so click on the Poker screen is click button
-(Ibaction) pokerpressed{
The timer's turned on, so we're going to shut him down.
if (Self.timer) {
[Self.timer invalidate];
Self.timer = nil;
}

Under different circumstances, click Poker will have different results, now write a ibaction method, and finally write the method of starting the program it
Two things happen, one is point, the other is wrong. The right situation is to calculate the reaction time, the wrong situation will pop up the warning box.
NSString *reactiontime;//There are two different kinds of cues, so make a judgment here.
if (spadeon==1) {
Double noseconds = (double) [Self.startdate timeintervalsincenow]*-1000; Timeintervalsincenow *-1000;
Reactiontime = [[NSString alloc] initwithformat:@ "response speed is%1.0f milliseconds, continue. ", Noseconds];
}
if (spadeon==0) {
Reactiontime = @ "Please don't worry, wait until the spades a appears and press";
}
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "One More Time" Message:reactiontime delegate:self cancelButtonTitle:@ "OK" otherbuttontitles:nil, nil];
[Alert show];
}


The prompt box disappears when you press "Start Game", then you can use the method called after the view is hidden.
(-(void) Alertview: (Uialertview *) Alertview Diddismisswithbuttonindex: (Nsinteger) Buttonindex) to start the game.


The timer calls this method to display a card
-(void) onacetimer{
int rnumber = rand ()%4;//4 cards, 0,1,2,3 four random numbers, control 4 cards display
Switch (rnumber) {
Case 0:
Pokerimage.image = [UIImage imagenamed:@ "11.png"];
Spadeon = 1;
StartDate = [NSDate date];//when the spades appear, the Date object is created, and the NSDate method can be called to get the time difference.
Break
Case 1:
Pokerimage.image = [UIImage imagenamed:@ "21.png"];
Spadeon = 0;
Break
Case 2:
Pokerimage.image = [UIImage imagenamed:@ "31.png"];
Spadeon = 0;
Break
Case 3:
Pokerimage.image = [UIImage imagenamed:@ "41.png"];
Spadeon = 0;
}//Random 4 results, only the first result will show the spades a, so let the custom control conditions Spadeon = 1, the others are 0, and then there will be if Spadeon 1 or 0 o'clock respectively, click the poker will appear different effects of ibaction method.
}



-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}

@end



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Program Log--ios "Test reaction poker Game" program

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.