PDA

View Full Version : Match Game help


bettypage222
07-02-2008, 04:53 PM
Hi,

I have a program for a card match game... and I have a question... can anyone think of a solution for this? If two of the cards are matched, the code now removes the movie clips...

I would like to change it so that when a match is made, the movie clips ARE NOT removed, however I want them to NOT BE ENABLED either... that the card match is unclickable...

I'm not sure how to do that... thanks for any help

//<AS>


initGame();
stop();

function initGame() {
// make sorted list of cards
cardsListOrdered = [];
for(i=1;i<=8;i++) {
cardsListOrdered.push(i,i);
}

// shuffle list
cardsListSorted = [];
while (cardsListOrdered.length > 0) {
r = int(Math.random()*cardsListOrdered.length);
cardsListSorted.push(cardsListOrdered[r]);
cardsListOrdered.splice(r,1);
}

// create card clips and assign their location and picture
x = 0;
y = 0;
for(i=0;i<16;i++) {
attachMovie("Card","Card"+i,i);
_root["Card"+i].picture = cardsListSorted[i];
_root["Card"+i]._x = x*85+275;
_root["Card"+i]._y = y*85+80;

// move to next card spot
x++;
if (x > 3) {
x = 0;
y++;
}
}

firstclip = 0;
}

function clickCard(clip) {
// see whether two cards are showing
if (secondclip != 0) {

// turn those two cards back over
firstclip.gotoAndStop(1);
secondclip.gotoAndStop(1);
firstClip = 0;
secondClip = 0;
}

// see whether same card was clicked
if (firstclip == clip) {

// turn card back over
firstclip.gotoAndStop(1);
firstClip = 0;

// see whether no cards are showing
} else if (firstclip == 0) {

// turn first card over
clip.gotoAndStop(clip.picture+1);
firstclip = clip;

// must be one card showing
} else {

// turn second card over
clip.gotoAndStop(clip.picture+1);
secondClip = clip;

// see whether two cards match
if (firstclip.picture == secondClip.picture) {

// remove both cards
firstClip.removeMovieClip();
secondClip.removeMovieClip();
firstClip = 10;
secondClip = 20;
}
}

}

CobaltBlueDW
07-02-2008, 06:56 PM
Some important code seems to be missing, but if I conjecture right using something like this would work:

// remove both cards
firstClip.onRelease = null;
secondClip.onRelease = null;


I don't know if you used onRelease, there are so many different possibilities for that, so hoefully you get the idea.

bettypage222
07-02-2008, 07:28 PM
that worked perfect, thanks!

Actually, there is no code missing... that's all of it...the mc in the library are being exported for AS, that's probably what you mean?

bettypage222
07-02-2008, 08:16 PM
actually, I'm getting this error with the code

**Warning** The linkage identifier 'Card_Button' was already assigned to the symbol 'cbutton', and cannot be assigned to the symbol 'cbutton', since linkage identifiers must be unique.


Here is the code:

//<AS>

initGame();
stop();

function initGame() {
// make sorted list of cards
cardsListOrdered = [];
for(i=1;i<=8;i++) {
cardsListOrdered.push(i,i);
}

// shuffle list
cardsListSorted = [];
while (cardsListOrdered.length > 0) {
r = int(Math.random()*cardsListOrdered.length);
cardsListSorted.push(cardsListOrdered[r]);
cardsListOrdered.splice(r,1);
}

// create card clips and assign their location and picture
x = 0;
y = 0;
for(i=0;i<16;i++) {
attachMovie("Card","Card"+i,i);
_root["Card"+i].picture = cardsListSorted[i];
_root["Card"+i]._x = x*85+275;
_root["Card"+i]._y = y*85+80;

// move to next card spot
x++;
if (x > 3) {
x = 0;
y++;
}
}

firstclip = 0;
}

function clickCard(clip) {
// see whether two cards are showing
if (secondclip != 0) {

// turn those two cards back over
firstclip.gotoAndStop(1);
secondclip.gotoAndStop(1);
firstClip = 0;
secondClip = 0;
}

// see whether same card was clicked
if (firstclip == clip) {

// turn card back over
firstclip.gotoAndStop(1);
firstClip = 0;

// see whether no cards are showing
} else if (firstclip == 0) {

// turn first card over
clip.gotoAndStop(clip.picture+1);
firstclip = clip;

// must be one card showing
} else {

// turn second card over
clip.gotoAndStop(clip.picture+1);
secondClip = clip;

// see whether two cards match
if (firstclip.picture == secondClip.picture) {

// remove both cards
firstClip.onRelease = null;
secondClip.onRelease = null;
firstClip = 0;
secondClip = 0;
}
}

}