Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

+ Reply to Thread
Results 1 to 2 of 2
  1. #1

    Default Memory game problem: comparing consecutive numbers in a list

    I have a simple memory game where the cards are number consecutively, shuffled and arranged face-down on the stage. I can test for the same card and get a positive result, I can test for different cards and get a positive result, and I can test to see if the first card flipped is larger or smaller than the second card.

    What I think I want to do is flip _selectedCards[0], see if it is an even or odd integer, then flip _selectedCards[1] and check with the first. If _selectedCards[0] is odd, I would want to check that _selectedCards[1] is the card number immediately preceding _selectedCards[0]. if _selectedCards[0] is even, I would want to check that _selectedCards[1] is the next number. In other words, cards numbered 0 & 1 match, 2 & 3 match, etc...

    My current if statement only checks for the same card and is as follows:

    Code:
    if (_selectedCards[0].cardNumber == _selectedCards[1].cardNumber) {
    I just don't know enough code to write what I want. Thanks.

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    Nov 2010
    Posts
    24

    Default

    Hi,

    please check the following this may help you out.

    // let say selCard is the card that was clicked first
    // let say checkCard is the card the was clicked second.
    // so we would compare whether checCard is the correct card on the basis of selCard being even or odd.

    // check wether the selCard is Even on Odd
    // i.e if divisible by 2 its even else odd
    var even:Boolean = ((selCard.cardNumber % 2) == 0);

    // if the selCard is even
    if (even) {
    if (checkCard.cardNumber == (selCard.cardNumber + 1)) {
    trace("Success, Card matched");
    }else {
    trace("Cards dont match");
    }
    }else {
    // if the selCar is odd
    if (checkCard.cardNumber == (selCard.cardNumber - 1)) {
    trace("Success, Card matched");
    }else {
    trace("Cards dont match");
    }
    }

    Regards,
    Shane Achary

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial