game_map = [ 0 => [ ['split1_left', 'split1_right'], ["A moss-covered path veers LEFT into deeper woods.", "A sunlit trail leads RIGHT toward distant birdsong."] ], 1 => [ ['split2_left', 'split2_right'], ["Thorny vines block the LEFT path slightly.", "The RIGHT path shows fresh deer tracks."] ], 2 => [ ['split3_left', 'split3_right'], ["An old stone marker points LEFT silently.", "Strange fungi grow along the RIGHT path."] ], 3 => [ ['exit', 'dead_end'], ["A faint light suggests an opening LEFT.", "The RIGHT path disappears into mist."] ] ]; $this->token_visuals = [ 'split1_left' => "🌲🌲🌲", 'split1_right' => "🌳🌳🌳", 'split2_left' => "πŸ‚πŸ‚πŸ‚", 'split2_right' => "🐾🐾🐾", 'split3_left' => "πŸͺ¨πŸͺ¨πŸͺ¨", 'split3_right' => "πŸ„πŸ„πŸ„", 'exit' => "πŸšͺ✨.EXIT.✨πŸšͺ", 'dead_end' => "πŸš«πŸ’€.DEAD END.πŸ’€πŸš«" ]; $this->outcome_messages = [ 'exit' => "You've found the forest exit! Sunlight warms your face as you step into the open.\nPress 'HOME' to play again.", 'dead_end' => "This is a dead end. Ancient trees block any further passage.\nPress SPACE to go back, or HOME to restart." ]; $this->events = [ 'treasure' => [ 'trigger' => 0.2, 'message' => "πŸ’° You found ancient coins in a hollow tree!", 'token' => "πŸ’° GOLD FOUND! πŸ’°" ], 'trap' => [ 'trigger' => 0.15, 'message' => "πŸ”₯ You narrowly avoid a collapsing path!", 'token' => "πŸ”₯ PATH CRUMBLES! πŸ”₯" ] ]; } public function initializeGame() { $_SESSION['path_choices'] = []; $_SESSION['current_split'] = 0; $_SESSION['active_events'] = []; $_SESSION['game_initialized'] = true; } public function processInput($user_input) { if (!isset($_SESSION['game_initialized'])) { $this->initializeGame(); } $user_input = strtoupper(trim($user_input)); if ($user_input === 'HOME') { $this->initializeGame(); return "[Game restarted]"; } if ($user_input === 'SPACE') { if (!empty($_SESSION['path_choices']) && $_SESSION['current_split'] > 0) { array_pop($_SESSION['path_choices']); $_SESSION['current_split']--;; return "[Undid choice: returned to split " . ($_SESSION['current_split'] + 1) . "]"; } elseif ($_SESSION['current_split'] == 0 && empty($_SESSION['path_choices'])) { return "[Already at start]"; } else { return "[Cannot go back further]"; } } if ($_SESSION['current_split'] < count($_SESSION['path_choices'])) { $current_path = $_SESSION['path_choices'][$_SESSION['current_split']]; if (in_array($current_path, ['exit', 'dead_end'])) { return $this->outcome_messages[$current_path]; } else { $_SESSION['current_split']++; return ""; } } if (in_array($user_input, ['L', 'R'])) { if ($_SESSION['current_split'] < 4) { // Trigger random events $this->triggerRandomEvents(); $choices = $this->game_map[$_SESSION['current_split']][0]; $chosen_outcome = ($user_input === 'L') ? $choices[0] : $choices[1]; $_SESSION['path_choices'][] = $chosen_outcome; $direction = ($user_input === 'L') ? "Left" : "Right"; $_SESSION['current_split']++; return "ok, you took the {$direction} path and are walking for a bit until..."; } else { return "[No more splits]"; } } return ""; } private function triggerRandomEvents() { foreach ($this->events as $event_name => $event_data) { if (mt_rand(0, 100) / 100 < $event_data['trigger']) { $_SESSION['active_events'][] = [ 'split' => $_SESSION['current_split'], 'name' => $event_name, 'message' => $event_data['message'], 'token' => $event_data['token'] ]; } } } public function displayCurrentSplit() { if (!isset($_SESSION['game_initialized'])) { return ""; } if ($_SESSION['current_split'] >= count($_SESSION['path_choices'])) { if (isset($this->game_map[$_SESSION['current_split']])) { $choices = $this->game_map[$_SESSION['current_split']][1]; return "SPLIT " . ($_SESSION['current_split'] + 1) . "/4\n" . "[L] " . $choices[0] . "\n" . "[R] " . $choices[1]; } return ""; } else { $current_path = $_SESSION['path_choices'][$_SESSION['current_split']]; $token = isset($this->token_visuals[$current_path]) ? $this->token_visuals[$current_path] : ""; if (in_array($current_path, ['exit', 'dead_end'])) { return $this->token_visuals[$current_path] . "\n" . $this->outcome_messages[$current_path]; } else { $event_display = ""; if (isset($_SESSION['active_events'])) { foreach ($_SESSION['active_events'] as $event) { if ($event['split'] == $_SESSION['current_split']) { $event_display .= "\n" . $event['token'] . "\n" . $event['message']; } } } return $token . " You're at this point in your journey." . $event_display; } } } } // Initialize game $game = new ForestPathGame(); // Handle form submission $message = ""; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $message = $game->processInput($_POST['action']); } // Get current display $display = $game->displayCurrentSplit(); ?> Forest Path Game

🌲 FOREST PATH ADVENTURE 🌲

Navigate through the forest by choosing paths. Find the exit!

How to Play: Click buttons to navigate. Find the exit through 4 path splits. Watch for random events!

				
					console.log( 'Code is Poetry' );