PDA

View Full Version : Set Inverval/Random number help


fluke12
09-03-2009, 02:12 AM
I'm trying to write a card counting counting program and am having issues with the pause on my set interval. Basically, the problem comes when it starts running out of cards; the pause gets longer. I've pasted the code below. Any ideas on how I can make the pause wait until after the card is attached? THANKS!





Stop;

card_name = new Array("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A");
card_value = new Array(1, 1, 1, 1, 1, 0, 0, 0, -1, -1, -1, -1, -1);
card_suit = new Array("Hearts", "Diamonds", "Spades", "Clubs");
Hearts_count = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Spades_count = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Diamonds_count = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Clubs_count = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);



//initial count variables
var depth = 1;
var x = 10
var totalCount = 0;
var totalNumber=0;


//object to declare a card
cardObject = {number:card_name, suit:card_suit, count:card_value};



function layCards(){


//random variables to get a random card
randomCardName = Math.floor(Math.random()*(13));
randomCardSuit = Math.floor(Math.random()*(4));

//gets specific card
card = String(cardObject.number[randomCardName] + "_" +cardObject.suit[randomCardSuit]);


if(randomCardSuit == 0 && Hearts_count[randomCardName] != 0){
test= CardAttach();
test2= PullCard();
} else if (randomCardSuit == 1 && Diamonds_count[randomCardName] !=0){
test= CardAttach();
test2= PullCard();
} else if (randomCardSuit == 2 && Spades_count[randomCardName] != 0){
test= CardAttach();
test2= PullCard();
} else if (randomCardSuit == 3 && Clubs_count[randomCardName] != 0){
test= CardAttach();
test2= PullCard();
}

}


var intervalID;
intervalID = setInterval( layCards, 1000 );


someListener = new Object();
someListener.onKeyDown = function () {


//listener to make sure count is correct
if(Key.getCode() == Key.SPACE){
clearInterval( intervalID )
}else if (Key.getCode() == Key.UP){
trace(totalCount);
intervalID = setInterval( layCards, 1000 );
}
};
Key.addListener(someListener);


//attaches card graphic to empty movie clip
function CardAttach (){
CardStack.attachMovie(card, "CardStack", CardStack.getNextHighestDepth(), {_y:Math.floor(Math.random()*(20))-10,_x:Math.floor(Math.random()*(20))-10,_rotation:Math.floor(Math.random()*(20)) -10});

}


//takes the card out of the shoe and adds or subtracts to the total count
function PullCard (){
if (randomCardSuit == 0) {
Hearts_count[randomCardName] = Hearts_count[randomCardName]-1;
totalCount = totalCount+card_value[randomCardName];
} else if (randomCardSuit == 1) {
Diamonds_count[randomCardName] = Diamonds_count[randomCardName]-1;
totalCount = totalCount+card_value[randomCardName];
} else if (randomCardSuit == 2) {
Spades_count[randomCardName] = Spades_count[randomCardName]-1;
totalCount = totalCount+card_value[randomCardName];
} else if (randomCardSuit == 3) {
Clubs_count[randomCardName] = Clubs_count[randomCardName]-1;
totalCount = totalCount+card_value[randomCardName];
}
}