Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(isset($_SESSION['cpuscore'])){
- $_SESSION['cpuscore'] = 0;
- }
- if(!isset($_SESSION['userscore'])){
- $_SESSION['userscore'] = 0;
- }
- ?>
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Dice Game Round #2</title>
- </head>
- <?php
- $uroll1 = rand(1,6);
- $uroll2 = rand(1,6);
- $utotal = $uroll1 + $uroll2;
- $cpuroll1 = rand(1,6);
- $cpuroll2 = rand(1,6);
- $cputotal = $cpuroll1 + $cpuroll2;
- ?>
- <body>
- <h1>Dice Game 2: The Last Jedi</h1>
- <h2>Your roll</h2>
- <p>You rolled <?php echo $uroll1?> and <?php echo $uroll2?> for a total of <?php echo $utotal?>;</p>
- <h2>Computer's Roll</h2>
- <p>The computer rolled <?php echo $cpuroll1?> and <?php echo $cpuroll2 ?> for a total of <?php echo $cputotal ?></p>
- <?php
- if($utotal==$cputotal){
- print "<p>You and the dealer tied! In the case of a tie the computer wins.</p>";
- $_SESSION['cpuscore']++;
- }
- else if($utotal<$cputotal){
- print "<p>The computer's roll was higher than yours - you lose.</p>";
- $_SESSION['cpuscore']++;
- }
- else if($utotal>$cputotal){
- print "<p>Your roll was higher than the computer's roll. Winner Winner, Chicken Dinner!</p>";
- $_SESSION['userscore']++;
- }
- else if ($_SESSION['userscore']==4){
- echo "<p>AAAAAAAAAAAAAAAAAAYOU WIN</p>";
- $_SESSION['userscore']=0;
- $_SESSION['cpuscore']=0;
- }
- else if ($_SESSION['cpuscore']==4)
- echo '<p>AAAAAAAAAAAAAAAAAAAYou have lost</p>';
- $_SESSION['userscore']=0;
- $_SESSION['cpuscore']=0;
- ?>
- <h3>Your score is <?php echo $_SESSION['userscore']; ?>/7</h3>
- <h3>The computer's score is <?php echo $_SESSION['cpuscore'];?>/7</h3>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement