Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/bender.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module PlanetExpress
class Bender
attr_accessor :name, :horde
def initialize(game)
@name = "Bender"
@horde = 50
@game = game
end
end
end
12 changes: 12 additions & 0 deletions lib/fry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module PlanetExpress
class Fry

attr_accessor :name, :thirst

def initialize(game)
@name = "Fry"
@thirst = 50

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to put a constant for this starting variable in the module, and then each class that is inside this module could utilize that constant.

@game = game
end
end
end
192 changes: 192 additions & 0 deletions lib/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
module PlanetExpress
class Game

def initialize
@bender = PlanetExpress::Bender.new(self)
@fry = PlanetExpress::Fry.new(self)
@hermes = PlanetExpress::Hermes.new(self)
@leela = PlanetExpress::Leela.new(self)
@zoidberg = PlanetExpress::Zoidberg.new(self)
@stable = true
end

def play_game
loop do
@bender = PlanetExpress::Bender.new(self)
@fry = PlanetExpress::Fry.new(self)
@hermes = PlanetExpress::Hermes.new(self)
@leela = PlanetExpress::Leela.new(self)
@zoidberg = PlanetExpress::Zoidberg.new(self)
@stable = true
do_play_game

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd that there is a play_game and do_play_game method. How could you rename for clarity?

puts "Do you want to play again? (y/n)"
break unless gets.chomp == "y"
end
end

def do_play_game

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is the method that should handle all of the game flow, so I don't quite understand why there are check and prompt method calls scattered around other locations. Consider refactoring so the main code flow all happens in this method.

while @stable
prompt
end
end

def make_choice
choice = gets.chomp.to_i
if choice == 1
steal
elsif choice == 2
drink
elsif choice == 3
account
elsif choice == 4
deliver
elsif choice == 5
hunger
else
puts "Please make a valid selection"
prompt
end
end

def score
bender_horde = @bender.horde
fry_thirst = @fry.thirst
hermes_receipts = @hermes.receipts
leela_work = @leela.work
zoidberg_hunger = @zoidberg.hunger
puts "Crew Status:"
# puts "Bender has #{bender_horde} items in his horde."
# puts "Fry has #{fry_thirst} units of thirst."
# puts "Hermes has #{hermes_receipts} receipts to enter."
# puts "Leela has #{leela_work} unfulfilled work orders."
# puts "Zoidberg has #{zoidberg_hunger} units of hunger."

total_score = bender_horde + fry_thirst + hermes_receipts + leela_work + zoidberg_hunger

puts "Horde score for Bender (you want this to be high): #{bender_horde}"
puts "Thirst score for Fry (you want this to be low): #{fry_thirst}"
puts "Receipts score for Hermes (you want this to be high): #{hermes_receipts}"
puts "Work Order score for Leela (you want this to be low): #{leela_work}"
puts "Hunger score for Zoidberg (you want this to be low): #{zoidberg_hunger}"
puts "Total score: #{total_score}"
end

def drink
check
if @fry.thirst <= 0
check
@fry.thirst = 0
else
@fry.thirst -= 10
end

if @leela.work <= 99
check
@leela.work += 3
elsif @leela.work >= 100
@leela.work = 100
end


prompt
end

def deliver
check
if @leela.work <= 0
@leela.work = 0
else
@leela.work -= 3
end

if @hermes.receipts >= 100
@hermes.receipts = 100
else
@hermes.receipts += 3
end
check
prompt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the prompt method is also being called on line 49 in the conditional. Does it need to be called twice?

end

def steal
if @leela.work >= 100
@leela.work = 100
else
@leela.work += 7
end

if @bender.horde >= 100
@bender.horde = 100
else
@bender.horde += 7
end
check
prompt
end

def hunger
check
if @zoidberg.hunger <= 0
@zoidberg.hunger = 0
else
@zoidberg.hunger -= 12
end

if @leela.work <= 99
check
@leela.work += 5
elsif @leela.work >= 100
@leela.work = 100
end

prompt
end

def account
check
if @hermes.receipts < 0
check
@hermes.receipts = 0
else
@hermes.receipts -= 9
end

if @bender.horde <= 0
check
@bender.horde -= 9
elsif @bender.horde < 0
@bender.horde = 0
else

end
check
prompt
end

def prompt
puts "You are the new captain of the Planet Express."
puts "Its crew: Bender, Fry, Hermes, Leela, and Zoidberg are at your command."
puts "Your direction is crucial to their survival."
puts "If Bender's horde isn't big enough, Fry is too thirsty, Hermes has too few receipts, Leela has too much work, or Zoidberg is too hungry, the mission will be over."
puts "Enter 1 to let Bender steal 7 things to add to his horde and create 7 more work orders for Leela."
puts "Enter 2 to give Fry a can of Slurm to reduce his thirst by 10 and create 3 more work orders for Leela."
puts "Enter 3 to give Hermes 9 receipts to keep track of Planet Express expenses and reduce Bender's horde by 9 items."
puts "Enter 4 to have Leela complete 3 work orders."
puts "Enter 5 to give Zoidberg a fish to eat to reduce his hunger by 12 and give Leela 5 more work orders."
score
puts "What is your choice?"
make_choice
end

def check
if ((@fry.thirst > 90 && @fry.thirst < 99) || (@leela.work > 90 && @leela.work < 99) || (@bender.horde < 10 && @bender.horde > 0) || (@zoidberg.hunger > 90 && @zoidberg.hunger < 99) || (@hermes.receipts < 10 && @hermes.receipts > 0))
puts "Your crew is close to failure"
prompt
elsif @fry.thirst == 100 || @leela.work == 100 || @bender.horde == 0 || @zoidberg.hunger == 10 || @hermes.receipts == 0
puts "Your crew is done for"
@stable = false
end
end

end
end
12 changes: 12 additions & 0 deletions lib/hermes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module PlanetExpress
class Hermes

attr_accessor :name, :receipts

def initialize(game)
@name = "Hermes"
@receipts = 50
@game = game
end
end
end
12 changes: 12 additions & 0 deletions lib/leela.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module PlanetExpress
class Leela

attr_accessor :name, :work

def initialize(game)
@name = "Leela"
@work = 50
@game = game
end
end
end
12 changes: 12 additions & 0 deletions lib/zoidberg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module PlanetExpress
class Zoidberg

attr_accessor :name, :hunger

def initialize(game)
@name = "Zoidberg"
@hunger = 50
@game = game
end
end
end
Empty file added planetexpress.py
Empty file.
9 changes: 9 additions & 0 deletions planetexpress.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "./lib/bender"
require "./lib/fry"
require "./lib/game"
require "./lib/hermes"
require "./lib/leela"
require "./lib/zoidberg"

game = PlanetExpress::Game.new
game.play_game
Empty file added pylib/bender.py
Empty file.
Empty file added pylib/fry.py
Empty file.
Empty file added pylib/hermes.py
Empty file.
Empty file added pylib/leela.py
Empty file.
Empty file added pylib/zoidberg.py
Empty file.