Advertisement
VZhelev

RoYaL The Bored One

May 30th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.41 KB | None | 0 0
  1. <?php
  2. //$input = "25|1:1|MLSM MLFL LPPF LPSS";
  3. $input = fgets(STDIN);
  4.  
  5. // player variables
  6. $boredom = 20;
  7. // get the drunkness from the input
  8. $drunkness = strtok($input, "|");
  9. // get the position from the input
  10. $position = strtok("|");
  11.  
  12. // convert the XXXX XXXX XXXX XXXX to an 2D array
  13. $magicMatrix[0] = strtok("|");
  14. $magicMatrix[0] = strtok($magicMatrix[0]," ");
  15. $magicMatrix[1] = strtok(" ");
  16. $magicMatrix[2] = strtok(" ");
  17. $magicMatrix[3] = strtok(" ");
  18.  
  19. $magicMatrix[0] = str_split($magicMatrix[0]);
  20. $magicMatrix[1] = str_split($magicMatrix[1]);
  21. $magicMatrix[2] = str_split($magicMatrix[2]);
  22. $magicMatrix[3] = str_split($magicMatrix[3]);
  23.  
  24. // convert 1:1 position to an array
  25. $royal_pos[0] = strtok($position, ":");
  26. $royal_pos[1] = strtok(":");
  27.  
  28. //gameplay variables
  29. $game_end = false;
  30. $last_magic = ""; // P, M, L, S, F
  31. $direction = true; // true = Up, false = Down
  32. $cornerEnd = false;
  33.  
  34. // Play the game
  35. while(!$game_end)
  36. {
  37.     // Check for magic trick
  38.     // ---------------------------------------------------------------------------------------------------------
  39.     switch($magicMatrix[$royal_pos[0]][$royal_pos[1]])
  40.     {
  41.         case "P": {
  42.             $boredom += $last_magic == "P" ? (5 + ((5/100) * $drunkness)) * 2 : (5 + ((5/100) * $drunkness));
  43.             $last_magic = "P";
  44.             break;
  45.             }
  46.         case "M": {
  47.             $boredom += $last_magic == "M"? (10 + ((10/100) * $drunkness)) * 2 : (10 + ((10/100) * $drunkness));
  48.             $last_magic = "M";
  49.             break;
  50.             }
  51.         case "L": {
  52.             $boredom += $last_magic == "L" ? (7 + ((7/100) * $drunkness)) * 2 : (7 + ((7/100) * $drunkness));
  53.             $last_magic = "L";
  54.             break;
  55.             }
  56.         case "S": {
  57.             $boredom -= $last_magic == "S" ? (5 + ((5/100) * $drunkness)) * 2 : (5 + ((5/100) * $drunkness));
  58.             $last_magic = "S";
  59.             break;}
  60.         case "F": {
  61.             $boredom -= $last_magic == "F" ? (15 + ((15/100) * $drunkness)) * 2 : (15 + ((15/100) * $drunkness));
  62.             $last_magic = "F";
  63.             break;}
  64.         default : break;
  65.     }
  66.     // ---------------------------------------------------------------------------------------------------------
  67.    
  68.     // Check for game end
  69.     // ---------------------------------------------------------------------------------------------------------
  70.     if($boredom <= 0)
  71.     {
  72.         echo "<p>Angel succeeded RoYaL is asleep</p>";
  73.         $game_end = true;
  74.     }elseif($boredom >= 100)
  75.     {
  76.         echo "<p>RoYaL went mad and killed Angel at " . $royal_pos[0] . ":" . $royal_pos[1] . "</p>";
  77.         $game_end = true;
  78.     }
  79.    
  80.     if($cornerEnd)
  81.     {
  82.         echo "<p>Angel succeeded RoYaL is asleep</p>";
  83.         $game_end = true;
  84.     }
  85.     // ---------------------------------------------------------------------------------------------------------
  86.    
  87.     //moving the royal
  88.     // ---------------------------------------------------------------------------------------------------------
  89.     if(!$game_end)
  90.     {
  91.         if($direction)
  92.         {
  93.             // moving upward
  94.             if($royal_pos[0] > 0)
  95.             {
  96.                 $royal_pos[0] -= 1;
  97.             }
  98.             elseif($royal_pos[1] > 0)
  99.             {
  100.                 $royal_pos[1] -= 1;
  101.                 $direction = false;
  102.             }
  103.             else
  104.             {
  105.                 // game ends at {0:0}
  106.                 $cornerEnd = true;
  107.             }
  108.         }
  109.         else
  110.         {
  111.             // moving downward
  112.             if($royal_pos[0] < 3)
  113.             {
  114.                 $royal_pos[0] += 1;
  115.             }
  116.             elseif($royal_pos[1] > 0)
  117.             {
  118.                 $royal_pos[1] -= 1;
  119.                 $direction = true;
  120.             }
  121.             else
  122.             {
  123.                 // game ends at {3:0}
  124.                 $cornerEnd = true;
  125.             }
  126.         }
  127.     }
  128.     // ---------------------------------------------------------------------------------------------------------
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement