Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(isset($_SESSION['cpuscore'])){
  4. $_SESSION['cpuscore'] = 0;
  5. }
  6. if(!isset($_SESSION['userscore'])){
  7. $_SESSION['userscore'] = 0;
  8. }
  9. ?>
  10. <!doctype html>
  11. <html>
  12. <head>
  13. <meta charset="utf-8">
  14. <title>Dice Game Round #2</title>
  15. </head>
  16. <?php
  17. $uroll1 = rand(1,6);
  18. $uroll2 = rand(1,6);
  19. $utotal = $uroll1 + $uroll2;
  20.  
  21. $cpuroll1 = rand(1,6);
  22. $cpuroll2 = rand(1,6);
  23. $cputotal = $cpuroll1 + $cpuroll2;
  24. ?>
  25. <body>
  26.  
  27. <h1>Dice Game 2: The Last Jedi</h1>
  28.  
  29. <h2>Your roll</h2>
  30.  
  31. <p>You rolled <?php echo $uroll1?> and <?php echo $uroll2?> for a total of <?php echo $utotal?>;</p>
  32.  
  33.  
  34.  
  35.  
  36. <h2>Computer's Roll</h2>
  37.  
  38. <p>The computer rolled <?php echo $cpuroll1?> and <?php echo $cpuroll2 ?> for a total of <?php echo $cputotal ?></p>
  39.  
  40. <?php
  41.  
  42.  
  43. if($utotal==$cputotal){
  44. print "<p>You and the dealer tied! In the case of a tie the computer wins.</p>";
  45. $_SESSION['cpuscore']++;
  46. }
  47. else if($utotal<$cputotal){
  48. print "<p>The computer's roll was higher than yours - you lose.</p>";
  49. $_SESSION['cpuscore']++;
  50. }
  51. else if($utotal>$cputotal){
  52. print "<p>Your roll was higher than the computer's roll. Winner Winner, Chicken Dinner!</p>";
  53. $_SESSION['userscore']++;
  54. }
  55. else if ($_SESSION['userscore']==4){
  56. echo "<p>AAAAAAAAAAAAAAAAAAYOU WIN</p>";
  57. $_SESSION['userscore']=0;
  58. $_SESSION['cpuscore']=0;
  59. }
  60. else if ($_SESSION['cpuscore']==4)
  61. echo '<p>AAAAAAAAAAAAAAAAAAAYou have lost</p>';
  62. $_SESSION['userscore']=0;
  63. $_SESSION['cpuscore']=0;
  64.  
  65.  
  66.  
  67. ?>
  68.  
  69. <h3>Your score is <?php echo $_SESSION['userscore']; ?>/7</h3>
  70.  
  71.  
  72.  
  73. <h3>The computer's score is <?php echo $_SESSION['cpuscore'];?>/7</h3>
  74.  
  75.  
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement