Wednesday, 11 June 2025

Help a game by Paul Timothy Martin Ryan

Certainly! Here's a simple Ruby game called **"Help"**. In this game, the player is asked a series of questions to help them find their way out of a virtual maze. The game will give the player choices, and based on their input, it will progress or end. Feel free to customize or expand upon this! ```ruby # Help Game in Ruby def start_game puts "Welcome to the Help Game!" puts "You find yourself in a maze. Your goal is to find the exit." puts "Let's begin!\n\n" first_choice end def first_choice puts "You are at a crossroad. Do you go left or right? (left/right)" choice = gets.chomp.downcase if choice == "left" left_path elsif choice == "right" right_path else invalid_input first_choice end end def left_path puts "\nYou took the left path and encounter a river." puts "Do you swim across or look for a bridge? (swim/bridge)" choice = gets.chomp.downcase if choice == "bridge" bridge_crossing elsif choice == "swim" puts "\nYou tried to swim across, but the current was too strong. You got swept away." game_over else invalid_input left_path end end def right_path puts "\nYou took the right path and see a locked door." puts "Do you try to pick the lock or look for a key? (pick/look)" choice = gets.chomp.downcase if choice == "look" find_key elsif choice == "pick" pick_lock else invalid_input right_path end end def find_key puts "\nYou look around and find a key on the ground." puts "Do you take the key? (yes/no)" choice = gets.chomp.downcase if choice == "yes" door_with_key elsif choice == "no" puts "\nYou decided not to take the key. Without it, you can't open the door." game_over else invalid_input find_key end end def pick_lock puts "\nYou try to pick the lock but trigger an alarm. Guards catch you." game_over end def door_with_key puts "\nUsing the key, you unlock the door and find the exit!" puts "Congratulations! You escaped the maze!" end def bridge_crossing puts "\nYou cross the bridge safely and find a ladder leading out." puts "Do you climb the ladder? (yes/no)" choice = gets.chomp.downcase if choice == "yes" puts "\nYou climb out and escape the maze. Well done!" elsif choice == "no" puts "\nYou decide not to climb the ladder and stay stuck." game_over else invalid_input bridge_crossing end end def game_over puts "\nGame Over!" play_again end def play_again puts "\nWould you like to play again? (yes/no)" choice = gets.chomp.downcase if choice == "yes" start_game elsif choice == "no" puts "Thanks for playing! Goodbye!" else invalid_input play_again end end def invalid_input puts "Invalid input. Please try again." end # Start the game start_game ``` ### How to play: 1. Save this code in a file named `help_game.rb`. 2. Run it with the command: `ruby help_game.rb`. 3. Follow the prompts to navigate through the maze. Let me know if you'd like to add more features or customize the game!

No comments:

Post a Comment