The Emperor has commissioned you to build a Gladiator Arena. You will do so using your knowledge of object-oriented Ruby.
You can run your code by using ruby script.rb
and interacting with the console.
Create a Gladiator
class that has the following properties...
- a
name
- a
weapon
(one of Spear, Club, Trident)
Once defined, you should be able to do the following...
max = Gladiator.new("Maximus", "Trident")
puts(max.name) # "Maximus"
puts(max.weapon) # "Trident"
Make it so that you cannot assign a Gladiator an invalid weapon (i.e., anything aside from Spear, Club or Trident. That means running code like Gladiator.new("Jesse", "Taco")
would throw an error
Create an Arena
class that meets the following criteria...
colosseum = Arena.new("Colosseum")
puts(colosseum.name) # => Colosseum
colosseum = Arena.new("megalopolis")
puts(colosseum.name) # => Megalopolis
colosseum = Arena.new("Colosseum")
puts(colosseum.gladiators) # => []
max = Gladiator.new("Maximus","Trident")
colosseum = Arena.new("Colosseum")
colosseum.add_gladiator(max)
puts(colosseum.gladiators) # => [Gladiator]
max = Gladiator.new("Maximus","Trident")
titus = Gladiator.new("Titus","Club")
andronicus = Gladiator.new("Andronicus","Spear")
colosseum = Arena.new("Colosseum")
colosseum.add_gladiator(max)
colosseum.add_gladiator(titus)
colosseum.add_gladiator(andronicus)
puts(colosseum.gladiators.length) # => 2
If there are two gladiators in the arena, you can call a fight
method that results in the elimination of one of the gladiators from the arena.
Winning conditions
- Trident beats Spear
- Spear beats Club
- Club beats Trident
- If the two gladiators have the same weapon, they are both eliminated.
max = Gladiator.new("Maximus","Trident")
titus = Gladiator.new("Titus","Spear")
colosseum = Arena.new("Colosseum")
colosseum.add_gladiator(max)
colosseum.add_gladiator(titus)
colosseum.fight()
puts(colosseum.gladiators) # => [max]
- Add a method to remove gladiators from the arena by name
- Update your winning conditions so that if the gladiator named "Maximus" is in the fight, he wins.
- Add a method to check to see if the crowd is entertained (
.entertained?
). The crowd is only entertained if Maximus is in the arena. - Before a losing gladiator is eliminated, the user should be prompted to put their thumbs up or down. If user votes down, the losing gladiator is removed. If the user votes up, the gladiator stays in the arena and his opponent is removed. (Life isn't fair.)