Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$input = "25|1:1|MLSM MLFL LPPF LPSS";
- $input = fgets(STDIN);
- // player variables
- $boredom = 20;
- // get the drunkness from the input
- $drunkness = strtok($input, "|");
- // get the position from the input
- $position = strtok("|");
- // convert the XXXX XXXX XXXX XXXX to an 2D array
- $magicMatrix[0] = strtok("|");
- $magicMatrix[0] = strtok($magicMatrix[0]," ");
- $magicMatrix[1] = strtok(" ");
- $magicMatrix[2] = strtok(" ");
- $magicMatrix[3] = strtok(" ");
- $magicMatrix[0] = str_split($magicMatrix[0]);
- $magicMatrix[1] = str_split($magicMatrix[1]);
- $magicMatrix[2] = str_split($magicMatrix[2]);
- $magicMatrix[3] = str_split($magicMatrix[3]);
- // convert 1:1 position to an array
- $royal_pos[0] = strtok($position, ":");
- $royal_pos[1] = strtok(":");
- //gameplay variables
- $game_end = false;
- $last_magic = ""; // P, M, L, S, F
- $direction = true; // true = Up, false = Down
- $cornerEnd = false;
- // Play the game
- while(!$game_end)
- {
- // Check for magic trick
- // ---------------------------------------------------------------------------------------------------------
- switch($magicMatrix[$royal_pos[0]][$royal_pos[1]])
- {
- case "P": {
- $boredom += $last_magic == "P" ? (5 + ((5/100) * $drunkness)) * 2 : (5 + ((5/100) * $drunkness));
- $last_magic = "P";
- break;
- }
- case "M": {
- $boredom += $last_magic == "M"? (10 + ((10/100) * $drunkness)) * 2 : (10 + ((10/100) * $drunkness));
- $last_magic = "M";
- break;
- }
- case "L": {
- $boredom += $last_magic == "L" ? (7 + ((7/100) * $drunkness)) * 2 : (7 + ((7/100) * $drunkness));
- $last_magic = "L";
- break;
- }
- case "S": {
- $boredom -= $last_magic == "S" ? (5 + ((5/100) * $drunkness)) * 2 : (5 + ((5/100) * $drunkness));
- $last_magic = "S";
- break;}
- case "F": {
- $boredom -= $last_magic == "F" ? (15 + ((15/100) * $drunkness)) * 2 : (15 + ((15/100) * $drunkness));
- $last_magic = "F";
- break;}
- default : break;
- }
- // ---------------------------------------------------------------------------------------------------------
- // Check for game end
- // ---------------------------------------------------------------------------------------------------------
- if($boredom <= 0)
- {
- echo "<p>Angel succeeded RoYaL is asleep</p>";
- $game_end = true;
- }elseif($boredom >= 100)
- {
- echo "<p>RoYaL went mad and killed Angel at " . $royal_pos[0] . ":" . $royal_pos[1] . "</p>";
- $game_end = true;
- }
- if($cornerEnd)
- {
- echo "<p>Angel succeeded RoYaL is asleep</p>";
- $game_end = true;
- }
- // ---------------------------------------------------------------------------------------------------------
- //moving the royal
- // ---------------------------------------------------------------------------------------------------------
- if(!$game_end)
- {
- if($direction)
- {
- // moving upward
- if($royal_pos[0] > 0)
- {
- $royal_pos[0] -= 1;
- }
- elseif($royal_pos[1] > 0)
- {
- $royal_pos[1] -= 1;
- $direction = false;
- }
- else
- {
- // game ends at {0:0}
- $cornerEnd = true;
- }
- }
- else
- {
- // moving downward
- if($royal_pos[0] < 3)
- {
- $royal_pos[0] += 1;
- }
- elseif($royal_pos[1] > 0)
- {
- $royal_pos[1] -= 1;
- $direction = true;
- }
- else
- {
- // game ends at {3:0}
- $cornerEnd = true;
- }
- }
- }
- // ---------------------------------------------------------------------------------------------------------
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement