Skip to content

Instantly share code, notes, and snippets.

@lucablackwell
Last active November 29, 2022 09:58
Show Gist options
  • Save lucablackwell/d021e6fa7d53cc38f8f06591c32fa093 to your computer and use it in GitHub Desktop.
Save lucablackwell/d021e6fa7d53cc38f8f06591c32fa093 to your computer and use it in GitHub Desktop.
<?php
# Colours
function cyan($text) {
return "\e[0;36m$text\e[0m";
}
function cyan_bold($text) {
return "\e[1;36m$text\e[0m";
}
function white_bold($text) {
return "\e[1;37m$text\e[0m";
}
function black($text) {
return "\e[1;30m$text\e[0m";
}
function yellow($text) {
return "\e[0;33m$text\e[0m";
}
function slow_print($time, $line, $newline) {
# Split the line into an array to be iterated over
$line_arr = preg_split("//u", $line, -1, PREG_SPLIT_NO_EMPTY);
# Iterate over each character in the line
foreach ($line_arr as $char) {
echo $char;
# Sleep for the given time (for aesthetic reasons)
usleep($time);
}
# If newlines enabled
if ($newline) {
echo "\n";
}
}
# Time variables
$time_logo = 1100;
$time_text = 45000;
$time_choice = 22500;
#$time_text = 1000; # debug speed
# Show and take input for choices
function show_choice($time_choice, $choices) {
# Initial spacer
echo " ";
# For each choice
for ($i = 0; $i < count($choices); $i++) {
# If it is the last
if ($i == count($choices)-1) {
# Show the choice
slow_print($time_choice, white_bold($i+1 . ". ") . yellow($choices[$i]), true);
# If it is not the last
} else {
# Show the choice
slow_print($time_choice, white_bold($i+1 . ". ") . yellow($choices[$i]), true);
# Intermediate spacer
echo " ";
}
}
# Take user input
$input = readline('> ');
$forward = false;
$to_return = null;
while (!$forward) {
# Loop through each choice
foreach ($choices as $choice) {
# If the input is only numbers, is within the range of choices and is equal to the current choice
if (preg_match('/[0-9]/', $input) && !preg_match('/[a-z]/', $input) && $input <= count($choices) && $choices[$input-1] == $choice) {
# Set the current choice to be returned
$to_return = $choice;
# If the input is the same as the current choice
} elseif (strtolower($input) == strtolower($choice)) {
# Set the current choice to be returned
$to_return = $choice;
}
}
# If there is something to return
if ($to_return) {
# End the loop
$forward = true;
# If there isn't something to return (i.e. the input is invalid)
} else {
slow_print($time_text, "\nInvalid input.", true);
# Take user input again
$input = readline('> ');
}
}
# Return the assigned value
return $to_return;
}
slow_print($time_text, "\nThere, on a hilltop,\nits' stone walls looming,\nlies what remains of the dead house.\n\nYou, a passerby,\ncurious and alone,\ndecide to venture into that long-forgotten home.", true);
# Show the choices and receive the user's input
$choice = show_choice($time_choice, ['Walk up the hill']);
slow_print($time_text, "\nYou amble up the incline,\nframed by wooden fences.\nThe rot is older than time,\nrough oak wreathed by decayed vines.", true);
$choice = show_choice($time_choice, ['Try the front door', 'Go into the garden']);
while ($choice != 'Go into the garden') {
if ($choice == 'Try the front door') {
slow_print($time_text, "\nArched ash with misted glass,\nthe door stands before you.\nThe doorknob refuses stubbornly -\nthe grand entrance is locked.", true);
$choice = show_choice($time_choice, ['Go into the garden']);
}
}
slow_print($time_text, "\nThe garden gate creaks as it closes,\nleaving you alone with\ndead plants, dry soil\nlittered with the reluctant corpses of insects.", true);
$choice = show_choice($time_choice, ['Try the back door']);
slow_print($time_text, "\nThe unlocked door leads into an office;\nthe wind rustles paper that lies loosely on the floor.\nYou run your finger slowly along a desk,\nyears of dust gather on firmly shut drawers.", true);
$choice = show_choice($time_choice, ['Inspect the desk', 'Explore further']);
while ($choice != 'Explore further') {
if ($choice == 'Inspect the desk') {
slow_print($time_text, "\nGrimy documents reveal that\na couple named Vango\nonce inhabited the husk of a home.\nWhere are they now?", true);
$choice = show_choice($time_choice, ['Explore further']);
}
}
slow_print($time_text, "\nThe door from the office opens easily,\nand leaves you in awe\nof a grand spiral staircase\nand a cold marble floor.\nYou pay no mind to the" . white_bold(' shadow ') . "that shifts in the corner", true);
$choice = show_choice($time_choice, ['Explore upstairs', 'Explore downstairs']);
$upstairs = false;
if ($choice == 'Explore upstairs') {
$upstairs = true;
slow_print($time_text, "\nHandle after handle denies entry,\nevery door sits tempting, locked.", true);
$choice = show_choice($time_choice, ['Return downstairs']);
slow_print($time_text, "\nUpon descent of the grand staircase,\nthere is no longer a" . white_bold(' shadow ') . "in the corner.", true);
$choice = show_choice($time_choice, ['Explore downstairs']);
}
slow_print($time_text, "\nThrough the low doorframe into the living room,\nwith shards of glass scattered across the boards of the floor.\nA grandfather clock stands, a patient observer,\nas you slowly continue your tour.", true);
usleep(500000);
slow_print($time_text, "\nYou struggle against heavy wood as the door opens to reveal\na dining table fully dressed,\ndelicate plates and stainless steel.\nA small knife falls off of the edge of the table;\nyou blame the wind and continue\nunder a veneer archway,\ngreeted by food cupboards and stove.\nBoxes of food lie empty -\nare you truly alone?", true);
$choice = show_choice($time_choice, ['Inspect the boxes', 'Explore further']);
while ($choice != 'Explore further') {
if ($choice == 'Inspect the boxes') {
slow_print($time_text, "\nThe boxes are ripped,\ntheir use-by dates long past.\nWhat was hungry here,\nand what will it eat now?", true);
$choice = show_choice($time_choice, ['Explore further']);
}
}
slow_print($time_text, "\nBack through the kitchen and up cold stone steps.\nLong-silenced static is idle on an old TV;\nstacks of books remain untouched.\nThrough the spokes of an antique bicycle,\nyou glimpse something" . white_bold(' corrupt') . ".\n\nStartled, you run back to the majestic staircase.\nPanting, you hear a crash upstairs." , true);
$choice = show_choice($time_choice, ['Investigate']);
if ($upstairs) {
slow_print($time_text, "\nThe once locked doors lie ajar, you find,", true);
} else {
slow_print($time_text, "\nMost doors are locked, you find,", true);
}
slow_print($time_text, "then stumble into a bathroom.\nA wide bath, filled with what once was mould;\nit is decay in its purest form.", true);
usleep(500000);
slow_print($time_text, "\nA glance behind you, then into a child's room,\na wooden rocking horse sits dormant,\nits' paint blistering.\nYou cannot bear to think of the owner's fate.", true);
usleep(500000);
slow_print($time_text, "\nA cautious entrance into the biggest bedroom.\nOn the bed sits a form of" . white_bold(' darkness') . ",\nall evil coalesced into one being.\nIt had remained on the edge of sight, but now is seen.", true);
usleep(500000);
slow_print($time_text, "\nShocked, you stumble backwards,\nyour eyes still drawn to" . white_bold(' the horror') . ".\nThe wooden bannister is low,\nand leaves you stranded forevermore\nbelow the grand spiral staircase\non the cold marble floor.", true);
usleep(500000);
slow_print($time_text, "\nYou, a passerby,\nonce curious and alone,\nare among the many victims of that long-forgotten home.\n", true);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment