PDA

View Full Version : [AS3] Dice rolling game help


sandyjabbour
06-29-2009, 06:53 PM
hello.
i am new here.. i am making a simple game :
it has a player and a machine playing
with a dice to roll

my idea is that you press the roll button and it roll the dice and it shows some bullets on the place of machine or the player zone depending on the number showed in the dice [ the number is randomly generated]
the dice is a movie clip tht has 6 keyframes.
the player_zone/machine_zone is the place where the bullet will show


anyways .. i dont know if my code is correct.. please any1 know wat is wrong ? :"(





function rolling(event:MouseEvent):void
{
var dicePlayer:Number = Math.ceil(Math.random()*6);
player_zone.new bullet(); +=dicePlayer;
dice.gotoAndStop(dicePlayer);
var valPl = player_zone
var valCm = machine_zone


var diceMachine:Number = Math.ceil(Math.random()*6);

if (valPl - valCm > 8 )
diceMachine = Math.ceil(Math.random()*6)+ 34;



machine_zone.new bullet(); +=dicePlayer;

}

roll.addEventListener(MouseEvent.CLICK, rolling);

jdevries
06-29-2009, 07:52 PM
Okay, looking through the code I think i get the general idea of what you are trying to do. Unfortunately, the code is quite frankly full of problems. I'd be happy to give it a try helping you on the way, but I'd really like to make sure I got it all figured out right, before typing up a lengthy reply.

So first of all, let me see if I figured out what everything is. This is what I got out of it, but let me know if I'm right or wrong. Is this about right?


player_zone: is a MovieClip
dice: is a MovieClip
valPl: is a Number
valCm: is a Number
machine_zone: is a MovieClip


I'm also pretty confused about this line:

if (valPl - valCm > 8 )

What are you trying to do here? What values can valPl and valCM contain as far as you are concerned?

To conclude, let me try rephrasing what you try to do, so I'm sure I got it right. What I understand is that you have one die (dice is the plural of die :cool:) that both you and the computer roll. You compare the two rolls and if the difference between the two is greater than a certain value it should display as many bullets on the machine_zone MovieClip as the die shows. Vica versa, if the difference between the two rolls is less than that certain value, the player_zone MovieClip should show the amount of bullets as shown on the player's die.

Am I warm? :)

sandyjabbour
06-29-2009, 08:16 PM
well actually the val's i got them from another formula i used the same concept of what i wanted ..
and am sory for my poor english :P but the die [ that is singular of dice] will be present down and two movie clips thats player_zone and machine_zone and btw, if no need for them to be made then tell me :P ..
um so on this two places when i roll the dice the number that is randomly generated will be shown as bullets in those two movie clips..

i duno what is the if (valPl - valCm > 8 ) for bt i think it is for the die rolling !!

um you are warm but i am geting so cold in here :'(