Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS Game Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning iOS Game Development
This is the forum to discuss the Wrox book Beginning iOS Game Development by Patrick Alessi ; ISBN: 978-1-1181-0732-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS Game Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 8th, 2013, 08:22 AM
Registered User
Points: 68, Level: 1
Points: 68, Level: 1 Points: 68, Level: 1 Points: 68, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default AlertView to the Concentration Game

I was trying to add an alertView to the Concentration Game but can`t make it in any possible way. If I add

Code:
if (cardIndex==0) {
                [self performSelector:@selector(endGameWithMessage:) withObject:nil afterDelay:1];}
the game finishes as soon as the view appears. If I write

Code:
if (card==0) {
                [self performSelector:@selector(endGameWithMessage:) withObject:nil afterDelay:1];}
nothing happens. I tried to make it in many ways but nothing.
How knows how to add an alertView when the game finishes? Help me, please.
Reply With Quote
  #2 (permalink)  
Old November 10th, 2013, 02:20 PM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

Not sure why you think accessing the card or cardIndex will give you any useful information about the game being completed. These are transient values and are gone once the view is layed out. A couple of options exist for presenting an alertview at the end of the game. One would be to have either a static integer or an instance variable to keep track of the matches. When the count is equal to 32, you are done. Another would be, since the cards are the only subviews to the view controller's view, to present the alert when the subview count is equal to zero. Here is a demonstration of the latter approach, including a bug fix for the program as it is written.

Code:
        // A card has already been tapped, so test for a match
        if (firstTappedView.value == tappedCard.value)
        {
            NSLog(@"tappedCard is %@ and firstTappedView is %@",tappedCard,firstTappedView);
            // Player found a match
            // Remove the cards
            [UIView animateWithDuration:1 delay:1
                                options:UIViewAnimationOptionTransitionNone
                             animations:^{
                                 firstTappedView.alpha = 0; 
                                 tappedCard.alpha=0;
                             }
                             completion:^(BOOL finished) {
                                 
                                 [firstTappedView removeFromSuperview];
                                 [tappedCard removeFromSuperview];
                                 firstTappedView = nil;////RELOCATED FROM ORIGINAL CODE
                                 // Stop ignoring taps because animation is done
                                 isAnimating=NO;
                                 NSLog(@"subviews are %@",self.view.subviews);
                                 NSLog(@"the count is %d",self.view.subviews.count);
                                 
                                 if (self.view.subviews.count == 0) {////CALL TO ALERTVIEW
                                     [self performSelector:@selector(gameOver) withObject:nil afterDelay:.5];
                                 }
                             }
             ];
            
            
//            // Reset the first tapped card to nil
//            firstTappedView = nil; ////WRONG PLACE FOR THIS. THE VIEW IS GETTING SET TO NIL BEFORE THE COMPLETION BLOCK IS EXECUTED SO IT NEVER IS REMOVED FROM THE SUPERVIEW. I HAVE MOVED IT TO THE COMPLETION BLOCK TO CORRECT THIS
        }
        
        else
        {
            // Flip both cards back over
            secondTappedView = tappedCard;
            [self performSelector:@selector(flipCards) withObject:nil
                       afterDelay:2];
            
        }
    }
}

-(void)gameOver/////PRESENTS ALERTVIEW WITH FAIRLY OBVIOUS MESSAGE
{
    NSLog(@"GameOver!");
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Game Over!!" message:@"matches are completed" delegate:self cancelButtonTitle:@"Quit?" otherButtonTitles:@"Replay?", nil];
    [alert show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    ////IF REPLAY IS CHOSEN, THE PROGRAM STARTS OVER. OTHERWISE NOTHING.
    if (buttonIndex == 1) {
        [self createCards];
    }
    
}
Make sure the AlertView delegate is added to the header role.
Bob
Reply With Quote
  #3 (permalink)  
Old November 10th, 2013, 04:14 PM
Registered User
Points: 68, Level: 1
Points: 68, Level: 1 Points: 68, Level: 1 Points: 68, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

thepianoguy, I don`t know how to thank you! I would never do it without your help. I made some changes but it works perfectly.
Thank you so much!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 - long proces by 500 entries - alertView IandiPhone BOOK: Professional iPhone and iPad Database Application Programming 7 March 21st, 2012 12:37 PM
Concentration and the views Gordio BOOK: Beginning iOS Game Development 1 March 17th, 2012 08:29 PM
Game programming. Magxtopher BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 3 September 11th, 2008 09:49 AM
Old game review guti Need help with your homework? 0 March 20th, 2007 11:28 AM
STRATEGIE - GAME! WarKrife C++ Programming 1 August 21st, 2003 08:10 PM



All times are GMT -4. The time now is 04:30 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.