PHP Dice Roll

Hi,

I have an assignment where I need to have two users input their names and then press enter.

Then two dice 6 sided die will be rolled. They both get a random result and it declares who is the winner based on the higher roll.

I have already completed the dice roll part and declared the winner based on higher roll. I was then asked to only declare the winner based on the outcome of 5 rolls. So best 3/5 will be the winner.

I’m still pretty new at coding.

Any help will be greatly appreciated. Thank you.

I’d solve it with using sessions, just do something like this

[code]start session

if playAgainButtonClicked/NewGame {
session totalRolls = 0
session user1 = 0
session user2 = 0
}

if session totalRolls < 5 {
roll dice
add values to session scores
increment session rolls with 1
echo values
}

if session totalRolls == 5 {
game over
user X won
echo play again button
} else {
echo roll again button
}[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service