Advertisement
Guest User

Luck Game with PHP

a guest
Oct 1st, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.47 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="en-US">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>My Simple PHP Game</title>
  6.    
  7.    
  8. <style>
  9.  
  10. .game{
  11.    
  12.     background-color:orange;
  13.     text-align:center;
  14.     font-family:Calibri;
  15.     position: absolute;
  16.     width:200px;
  17.     top:0;
  18.     bottom: 0;
  19.     left: 0;
  20.     right: 0;
  21.     height:75px;
  22.  
  23.     margin: auto;
  24.    
  25. }
  26.  
  27. h1,h2{
  28.    
  29.  
  30.     font-family:Calibri;
  31.     text-align:center;
  32.    
  33. }
  34.  
  35.  
  36. </style>
  37.  
  38.    
  39. </head>
  40. <body>
  41.    
  42.     <h1>Simple Game made with PHP</h1> <!-- Page Title -->
  43.     <h2>Find serial killer from three man, if you can't you will die.</h2> <!--Desc. of the game-->
  44.    
  45.     <?php ##OPEN NEW TAG FOR PHP
  46.         $killer = rand(1, 3); # Determine a number 1 between 3 (1,2,3)
  47.    
  48.         if($_POST){ #If user do post action, It will work.
  49.            
  50.            
  51.            
  52.             $blamedman = $_POST['sel']; #Get who player selected man as number
  53.            
  54.             if($killer == $blamedman){ #if determined number equals to selected man number it will work
  55.                
  56.                 echo '<p style="background-color:green;text-align:center;font-size:25px;font-family:Calibri;">You win, reloading in 3 seconds</p>'; #YOU WIN MESSAGE
  57.                 header("refresh: 3;"); #refreshs the page
  58.                
  59.             }
  60.            
  61.             else{ #if not equals it, you will die
  62.                
  63.                 echo '<p style="background-color:red;text-align:center;font-size:25px;font-family:Calibri;">You died, reloading in 3 seconds</p>'; #YOU LOSE MESSAGE
  64.                 header("refresh: 3;"); #refreshs the page
  65.             }
  66.            
  67.            
  68.         }
  69.    
  70.    
  71.     ?> <!-- close php tag -->
  72.     <div class="game"> <!-- created game class (css) for good look  -->
  73.         <!----><a>Hint: Killer's name is contains "<?php  #We gave them hint. So we will use php there
  74.        
  75.         if($killer == 1){ #If killer is John hint will show killer name is contains J
  76.            
  77.             echo 'J';
  78.            
  79.         }
  80.         else if($killer == 2){ #If killer is John hint will show killer name is contains A
  81.            
  82.             echo 'A';
  83.            
  84.         }
  85.         else if($killer == 3){ #If killer is John hint will show killer name is contains E
  86.            
  87.             echo 'E';
  88.            
  89.         }
  90.         ?> "</a> <!-- -->
  91.         <form method="post"> <!--THIS IS IMPORTANT, IF YOU DONT DO THAT IT WILL NOT WORK IF($POST]} SECTION-->
  92.        
  93.             <select name="sel"> <!--name is important too. we used name at php codes-->
  94.            
  95.                 <option value="1">John</option> <!--These man value is 1-->
  96.                
  97.                 <option value="2">Daniel</option> <!-- 2-->
  98.                
  99.                 <option value="3">James</option> <!--3 -->
  100.                
  101.            
  102.             </select>
  103.            
  104.             <input type="submit" value="Blame"> <!--Submit button, need for this game-->
  105.        
  106.         </form>
  107.     </div>
  108.    
  109. </body>
  110. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement