Thursday, 3 July 2025
Apologies for being caught in the omaagh bombing
# all_apologies.rb
class Player
attr_accessor :name, :apologies_given
def initialize(name)
@name = name
@apologies_given = 0
end
def apologize(sincerity)
@apologies_given += 1
sincerity_message = case sincerity
when 1
"a little."
when 2
"a lot."
when 3
"from the bottom of your heart."
else
"with no sincerity at all."
end
puts "You apologize #{sincerity_message}"
end
end
class Character
attr_reader :name, :relationship
def initialize(name, relationship)
@name = name
@relationship = relationship
end
def respond
responses = [
"It's okay, I forgive you.",
"That hurt my feelings.",
"Please be more careful next time.",
"Thanks for apologizing."
]
responses.sample
end
end
class Game
def initialize
puts "Welcome to All Apologies!"
print "What's your name? "
@player_name = gets.chomp
@player = Player.new(@player_name)
@characters = [
Character.new("Mom", "family"),
Character.new("Best Friend", "friend"),
Character.new("Coworker", "colleague"),
Character.new("Sibling", "family")
]
end
def start
puts "\nHi #{@player.name}! Let's start apologizing."
@characters.each do |character|
puts "\nYou see #{character.name}, your #{character.relationship}."
apologize_to(character)
end
conclude
end
def apologize_to(character)
loop do
puts "Do you want to apologize to #{character.name}? (yes/no)"
answer = gets.chomp.downcase
if answer == 'yes'
sincerity_level = select_sincerity
@player.apologize(sincerity_level)
puts "#{character.name} says: \"#{character.respond}\""
break
elsif answer == 'no'
puts "You chose not to apologize."
break
else
puts "Please answer with 'yes' or 'no'."
end
end
end
def select_sincerity
puts "How sincere do you want to be? (1-3)"
puts "1. Slightly"
puts "2. Very"
puts "3. Heartfelt"
loop do
input = gets.chomp
if input =~ /^[1-3]$/
return input.to_i
else
puts "Please enter a number between 1 and 3."
end
end
end
def conclude
puts "\nGame over! You gave #{@player.apologies_given} apologies today."
puts "Thanks for playing, #{@player.name}!"
end
end
# Start the game
game = Game.new
game.start
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment