Thursday, 6 March 2025

Behavior the Game

Sure! Below is a simple text-based Ruby game titled "Behavior." In this game, players will make choices that influence the outcome based on different behaviors. The objective is to navigate through scenarios and reach the best possible outcome based on the player's choices. ### Game: Behavior ```ruby class BehaviorGame def initialize @choices = { start: "You are at a crossroads. Do you want to be brave or cautious?", brave: { text: "You chose to be brave! You encounter a wild animal. Do you confront it or run away?", confront: "You confronted the animal and scared it away! You found a treasure! You win!", run: "You ran away safely, but you missed out on the treasure. Game over!" }, cautious: { text: "You chose to be cautious. You find a friendly traveler. Do you talk to them or ignore them?", talk: "You talked to the traveler and learned about the hidden village. You win!", ignore: "Ignoring the traveler, you wander aimlessly and get lost. Game over!" } } end def start puts @choices[:start] player_choice = gets.chomp.downcase if player_choice == "brave" brave_path elsif player_choice == "cautious" cautious_path else puts "Invalid choice. Please choose 'brave' or 'cautious'." start end end def brave_path puts @choices[:brave][:text] player_choice = gets.chomp.downcase if player_choice == "confront" puts @choices[:brave][:confront] elsif player_choice == "run" puts @choices[:brave][:run] else puts "Invalid choice. Please choose 'confront' or 'run'." brave_path end end def cautious_path puts @choices[:cautious][:text] player_choice = gets.chomp.downcase if player_choice == "talk" puts @choices[:cautious][:talk] elsif player_choice == "ignore" puts @choices[:cautious][:ignore] else puts "Invalid choice. Please choose 'talk' or 'ignore'." cautious_path end end end # Start the game game = BehaviorGame.new game.start ``` ### Instructions to Run the Game 1. Save the provided Ruby code into a file named `behavior_game.rb`. 2. Open your terminal or command prompt. 3. Navigate to the directory where you saved the `behavior_game.rb` file. 4. Run the game by typing: ```bash ruby behavior_game.rb ``` 5. Follow the prompts in the terminal to play the game! ### Description - The game starts with two main paths: being brave or cautious. - Each path leads to further choices that determine the game's outcome. - Players can explore various scenarios based on their behavior. - The game is simple and can be expanded with more scenarios and complexity based on your preference!Sure! Below is a simple text-based Ruby game titled "Behavior." In this game, players will make choices that influence the outcome based on different behaviors. The objective is to navigate through scenarios and reach the best possible outcome based on the player's choices. ### Game: Behavior ```ruby class BehaviorGame def initialize @choices = { start: "You are at a crossroads. Do you want to be brave or cautious?", brave: { text: "You chose to be brave! You encounter a wild animal. Do you confront it or run away?", confront: "You confronted the animal and scared it away! You found a treasure! You win!", run: "You ran away safely, but you missed out on the treasure. Game over!" }, cautious: { text: "You chose to be cautious. You find a friendly traveler. Do you talk to them or ignore them?", talk: "You talked to the traveler and learned about the hidden village. You win!", ignore: "Ignoring the traveler, you wander aimlessly and get lost. Game over!" } } end def start puts @choices[:start] player_choice = gets.chomp.downcase if player_choice == "brave" brave_path elsif player_choice == "cautious" cautious_path else puts "Invalid choice. Please choose 'brave' or 'cautious'." start end end def brave_path puts @choices[:brave][:text] player_choice = gets.chomp.downcase if player_choice == "confront" puts @choices[:brave][:confront] elsif player_choice == "run" puts @choices[:brave][:run] else puts "Invalid choice. Please choose 'confront' or 'run'." brave_path end end def cautious_path puts @choices[:cautious][:text] player_choice = gets.chomp.downcase if player_choice == "talk" puts @choices[:cautious][:talk] elsif player_choice == "ignore" puts @choices[:cautious][:ignore] else puts "Invalid choice. Please choose 'talk' or 'ignore'." cautious_path end end end # Start the game game = BehaviorGame.new game.start ``` ### Instructions to Run the Game 1. Save the provided Ruby code into a file named `behavior_game.rb`. 2. Open your terminal or command prompt. 3. Navigate to the directory where you saved the `behavior_game.rb` file. 4. Run the game by typing: ```bash ruby behavior_game.rb ``` 5. Follow the prompts in the terminal to play the game! ### Description - The game starts with two main paths: being brave or cautious. - Each path leads to further choices that determine the game's outcome. - Players can explore various scenarios based on their behavior. - The game is simple and can be expanded with more scenarios and complexity based on your preference!

No comments:

Post a Comment