|
| 1 | +<?php |
| 2 | + |
| 3 | +$results = []; |
| 4 | + |
| 5 | +function doChoice($situation) { |
| 6 | + |
| 7 | + $question = key($situation); |
| 8 | + $options = $situation[$question]; |
| 9 | + $validAnswers = array_keys($options); |
| 10 | + |
| 11 | + do { |
| 12 | + $answer = readline($question .' (' . implode(',', $validAnswers) . ')' . PHP_EOL); |
| 13 | + } while ( !in_array($answer, $validAnswers )); |
| 14 | + |
| 15 | + $result = $options[$answer]; |
| 16 | + |
| 17 | + if (!is_array($result)) { |
| 18 | + echo $result . PHP_EOL; |
| 19 | + } else { |
| 20 | + doChoice($result); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +$stories = [ |
| 25 | + 'what direction will you go?' => [ |
| 26 | + 'north' => [ |
| 27 | + 'you continue for miles without seeing anything. what will you do?' => [ |
| 28 | + 'leave road' => 'a giant monster appeared and broke your neck', |
| 29 | + 'continue' => [ |
| 30 | + 'a castle appears in front of you. what will you do?' => [ |
| 31 | + 'enter' => 'the castle is owned by a mad king. he makes you his slave and you work there for the rest of your short life', |
| 32 | + 'climb' => [ |
| 33 | + 'you scale the castle walls. eventually you come to a window where you see a king sleeping. what will you do?' => [ |
| 34 | + 'enter' => [ |
| 35 | + 'the king hasn\t woken up. what will you do to him?' => [ |
| 36 | + 'wake' => 'the king wakes up and roars angrily. the guards come and beat you to death with guitars', |
| 37 | + 'kill' => 'as you drive your sword into the kings side his mouth opens and an evil spirit streams out. you\'ve killed the wicked king of Norrland and you are declared a hero' |
| 38 | + ] |
| 39 | + ], |
| 40 | + 'more climbing' => 'your arms get tired and eventually you fall to your death' |
| 41 | + ] |
| 42 | + ], |
| 43 | + ] |
| 44 | + ], |
| 45 | + ] |
| 46 | + ], |
| 47 | + 'south' => [ |
| 48 | + 'you see a bridge, will you cross it?' => [ |
| 49 | + 'yes' => 'the bridge broke and you fell to your death', |
| 50 | + 'no' => 'you stayed in the same place for the rest of your short life', |
| 51 | + ] |
| 52 | + ], |
| 53 | + 'east' => [ |
| 54 | + 'you meet an old woman on the road, say hello?' => [ |
| 55 | + 'yes' => [ |
| 56 | + 'she greets you friendlily and offers you directions. follow her directions?' => [ |
| 57 | + 'yes' => 'your faith in people paid off, with her help you reached your goal.', |
| 58 | + 'no' => 'you get lost in a dark forrest and eventually a wolf eats you for dinner' |
| 59 | + ] |
| 60 | + ], |
| 61 | + 'no' => 'the woman scowls at you. after you pass her she turns around and shoots you in the back' |
| 62 | + ], |
| 63 | + ], |
| 64 | + 'west' => [ |
| 65 | + 'you see a cat. be nice to the cat?' => [ |
| 66 | + 'yes' => 'after stroking the cat\'s back it turns into a witch and grants you superpowers. You win!', |
| 67 | + 'no' => 'lasers shoot from the cat\'s eyes, destroying you instantly', |
| 68 | + ] |
| 69 | + ], |
| 70 | + ] |
| 71 | +]; |
| 72 | + |
| 73 | +doChoice($stories); |
0 commit comments