I have made a rough dice game , so far i have the numbers randomly generating corectly but as per the rules of craps i have to have an original throw where 7 wins and 2 and 6 looses , then a point roll where rolling the original number rolled if not a 7 2 or 12 player wins ,else you have to roll again , how can i assign this to one button. The function the reset my game is also broken.
stop();
dice1.stop();
dice2.stop();
pointRoll_btn.visible=false;
//adds listener to quit button
quit_btn.addEventListener(MouseEvent.CLICK , quit);
// quit function
function quit(event:MouseEvent):void {
gotoAndStop(2);
}
function randRange(max, min) {
var temp:int;
do {
temp = Math.random()*(max -min) + min;
} while (temp ==0);
return temp;
}
var randomnumber=uint;
var randomnumber2=uint;
var value1;
var value2;
roll_btn.addEventListener(MouseEvent.CLICK ,Roll);
playAgain_btn.addEventListener(MouseEvent.CLICK , playAgain);
//pointRoll_btn.addEventListener(MouseEvent.CLICK , pointRoll);
stop_btn.addEventListener(MouseEvent.CLICK ,stopdice);
function init4() {
}
function Roll(m:MouseEvent) {
dice1.gotoAndPlay(randRange(7,1));
dice2.gotoAndPlay(randRange(7,1));
randomnumber=(randRange(7,1));
randomnumber2=(randRange(7,1));
text1.text=randomnumber;
text2.text=randomnumber2;
value1=text1.text+text2.text;
}
function stopdice(m:MouseEvent) {
dice1.gotoAndStop(randomnumber);
dice2.gotoAndStop(randomnumber2);
//randomnumber=(randRange (1,7));
if (value1==7||value1==11) {
result_txt.text="you win";
} else if (value1 == 2 || value1 == 3 || value1 == 12) {
result_txt.text="you lose";
roll_btn.enabled=false;
playagain_btn.enabled=true;
roll_btn.visible=false;
} else {
value2=value1;
roll_btn.visible=false;
pointRoll_btn.visible=true;
}
}
//function pointRoll(e:MouseEvent) {
// value2=randomnumber+randomnumber2;
//
// if (value2==value1) {
// result_txt.text="you win";
// winGame();
// } else if (value2 == 7) {
// result_txt.text="you lose";
// loseGame();
// } else {
// result_txt.text="roll again";
// }
//}
//win game
function winGame():void {
roll_btn.enabled=false;
playagain_btn.enabled=true;
roll_btn.visible=false;
}
function winGame1():void {
roll_btn.enabled=false;
playagain_btn.enabled=true;
roll_btn.visible=false;
}
//lose game
function loseGame():void {
roll_btn.enabled=false;
playagain_btn.enabled=true;
roll_btn.visible=false;
}
function playAgain(event:MouseEvent):void {
// runs init reseting the game()
init4();
}
init4();