PDA

View Full Version : game switch statement help


withease
06-17-2008, 03:13 PM
I have a 6 ball lottery style game in which the player has the option of playing up to 4 seperate cards.

each of the cards are colored (red, blue, green, and purple).

on each play 6 numbered balls roll on to the screen.

the player can win different amounts depending on the balls and cards numbers matching. (ie. matched in order, matched in any order)

the problem I am having is that the sixth ball drawn randomly draws as a colored ball. and if the player has any win on the colored card that matches the color of the sixth ball all the pays on that card are doubled.

i have tried several different ways to write this conditional statement but i cant get this to work. please help.

GMaker0507
06-17-2008, 09:36 PM
ready your post, and looked at the code, and i dont exactly get your code. Maybe some commenting would help me understand what exactly is going on. I have some guess based off of common sense and how variables are named. But those are only guesses.

But just some advice when posting:You can embed as in your posts by wrapping it in tags

if (card1Active) {
switch (Card1InOrder) {
case 6 :
if (_level2.drawNum6 == reddraw) {
Card1InOrderWon = 10000 * BetPerCard * DenomCents;
} else {
Card1InOrderWon = 5000 * BetPerCard * DenomCents;
}
break;
case 5 :
if (_level2.drawNum6 == reddraw) {
Card1InOrderWon = 2000 * BetPerCard * DenomCents;
} else {
Card1InOrderWon = 1000 * BetPerCard * DenomCents;
}
break;
case 4 :
if (_level2.drawNum6 == reddraw) {
Card1InOrderWon = 500 * BetPerCard * DenomCents;
} else {
Card1InOrderWon = 250 * BetPerCard * DenomCents;
}
break;
case 3 :
if (_level2.drawNum6 == reddraw) {
Card1InOrderWon = 100 * BetPerCard * DenomCents;
} else {
Card1InOrderWon = 50 * BetPerCard * DenomCents;
}
break;
case 2 :
if (_level2.drawNum6 == reddraw) {
Card1InOrderWon = 20 * BetPerCard * DenomCents;
} else {
Card1InOrderWon = 10 * BetPerCard * DenomCents;
}
break;
case 1 :
if (_level2.drawNum6 == reddraw) {
Card1InOrderWon = 2 * BetPerCard * DenomCents;
} else {
Card1InOrderWon = BetPerCard * DenomCents;
}
break;
default :
break;
}
switch (Card1Hits) {
case 5 :
if (_level2.drawNum6 == reddraw) {
Card1HitsWon = 1000 * BetPerCard * DenomCents;
} else {
Card1HitsWon = 500 * BetPerCard * DenomCents;
}
break;
case 4 :
if (_level2.drawNum6 == reddraw) {
Card1HitsWon = 50 * BetPerCard * DenomCents;
} else {
Card1HitsWon = 25 * BetPerCard * DenomCents;
}
break;
case 3 :
if (_level2.drawNum6 == reddraw) {
Card1HitsWon = 20 * BetPerCard * DenomCents;
} else {
Card1HitsWon = 10 * BetPerCard * DenomCents;
}
break;
case 2 :
if (_level2.drawNum6 == reddraw) {
Card1HitsWon = 8 * BetPerCard * DenomCents;
} else {
Card1HitsWon = 4 * BetPerCard * DenomCents;
}
break;
default :
break;
}
Card1InOrderWonText = (Card1InOrderWon / DenomCents).toString();
Card1HitsWonText = (Card1HitsWon / DenomCents).toString();
TotalWins += Card1InOrderWon + Card1HitsWon;

if (Card1InOrderWon || Card1HitsWon) {
card1.win.play ();
}
if (Card1InOrderWon || Card1HitsWon) {
Ding.start ();
}
}

withease
06-17-2008, 11:01 PM
i apologize i am new to both this forum and action script.

this snippet refers to what is paid for a win on this card.
case 6 is refering to all 6 numbers on the card matching all 6 number in the ball draw movie clip.

the else statment below is the normal pay for a win which is 5000 times what is bet times the set denomination and this works fine.

the if statement is where i run into problems.

i have a mc called balldraw in that clip i have 6 mc's callled ballClip1 , ballClip2...etc.

ballClip6 has with in it 4 additional mc's redballs, blueballs... etc.

if the ball 6 draw is colored i need to double the pay on that card

should the if statement name the movie clip or the instance?


if (card1Active) {
switch (Card1InOrder) {
case 6 :
if (_level2.drawNum6 == reddraw) {
Card1InOrderWon = 10000 * BetPerCard * DenomCents;
} else {
Card1InOrderWon = 5000 * BetPerCard * DenomCents;
}
break

GMaker0507
06-18-2008, 12:34 AM
okay, so let me get this straight because i think i know of a solution.

Ball 6 can be one of 4 different colors

Your trying to figure out how to refer to the 6th ball, and or find out if it is colored the same color as one of the cards or not, and/or if it is a specific color.

If so, then i already have a solution. But ill wait for you to reply to post it.

withease
06-18-2008, 02:40 PM
yes!!!
that is exactly what i need to do

GMaker0507
06-18-2008, 04:57 PM
Create a new layer in the 6th ball's movieclip and insert this code on the first keyframe of that layer

_global.Ball6=this

This creates a global variable for the 6th ball that can be accessed from from anywhere in flash by simply testing if it is null,if it isnt null then the 6th ball does exist and you should be ableto make alterations with like "_global.Ball6._x=2342"

I assumed that the code you orignally posted was made for card 1, Correct? That means you would have to have 3 other versions of this code made for each card. If that be the case i made it into a function which you could use on each card

It might not be perfect but since you understand the original code more than i, you should be able fix it up some.

If you have any questions send me a pm.Im on everyday so i should get back to you soon.

Heres what i figured:


/* This example assumes that on frame 1, the 6th ball is red,
on frame 2 the 6th ball is green, etc.. Change to fit your needs.*/

var RED:Number = 1;
var GREEN:Number = 2;
var BLUE:Number = 3;
var YELLOW:Number = 4;

/* I created a function in which you could use to test each card with. Here is what each parameter stands for.

--Mc:MovieClip - The card Mc used to replace: ' card1.win.play ()' from your original code with: 'Mc.win.play()'.

--CardColor:Number - The color of the card, either 'RED','GREEN','BLUE',or 'YELLOW' for this parameter just type in one
of the upper case variable names above (no quotations or such)

--IsActive:Boolean, InOrder:Number, HitsWon:Number - These in your original code were Card1IsActive, Card1InOrder,
Card1HitsWon. Here i just changed their names.

--BetPerCard:Number, DenomCents:Number - Whatever you wanted them to mean
*/

function TestCard (Mc:MovieClip, CardColor:Number, IsActive:Boolean, InOrder:Number, Hits:Number, BetPerCard:Number, DenomCents:Number) {

/* Instead of encapsulating the whole thing in an if(IsActive) statement, we just tell the flash to return if it isnt active
return just means "dont go on" or "stop here", everything in the same function after it will be ignored.*/
if (!IsActive) {
return;
}
// The amount to multiply the final value by. Its simple math, if the value is to be
// doubled, we multply by two, elsewise we multiply by one.
var Multilplier:Number = 1;

// Make sure it exists
if (_global.Ball6 != null) {
// This is assuming for example purposes that on frame 1 the ball is red, on frame 2 the ball is green, etc.//
// Change to fit your setup.//
if (_global.Ball6.currentFrame == CardColor) {
Multiplier = 2;
}
} else {
return;
}
// The base amount you win to be multiplied by the 'BetPerCard' and 'DenomCents' variables.//
var InOrder_BaseWinAmount:Number = 0;
var HitsWon_BaseWinAmount:Number = 0;

// Variables for how much was won total from how many hits there were,and how many cards were in order.
var InOrderWon:Number;
var HitsWon:Number;

// We dont want a negative number or zero,so we test if it is above zero.
if (InOrder > 0) {
// The amounts we can win based on how many cards are in order we have
var InOrderAmounts:Array = new Array (1, 10, 50, 250, 1000, 5000);
InOrder_BaseWinAmount = InOrderAmounts[InOrder - 1];
}
// Finally decide how much we won based on the ordering alone.
InOrderWon = (InOrder_BaseWinAmount * Multiplier) * BetPerCard * DenomCents;

// We dont want a negative number, zero, or one so we test if it is above one.
if (Hits > 1) {
// The amounts we can win based on how many hits we have.
var HitsWonAmounts:Array = new Array (4, 10, 25, 500);
HitsWon_BaseWinAmount = HitsWonAmounts[Hits - 2];
}
// Finally decide how much we won based on hits alone.
HitsWon = (HitsWon_BaseWinAmount * Multiplier) * BetPerCard * DenomCents;

InOrderWonText = (InOrderWon / DenomCents).toString ();
HitsWonText = (HitsWon / DenomCents).toString ();
TotalWins += InOrderWon + HitsWon;

if (InOrderWon || HitsWon) {
Mc.win.play ();
}
if (InOrderWon || HitsWon) {
Ding.start ();
}
}

withease
06-18-2008, 05:15 PM
Thank you very much!

I will try this and will pm if i have questions.