Class: Kaibaibo::Game
- Inherits:
-
Object
- Object
- Kaibaibo::Game
- Defined in:
- lib/kaibaibo/game.rb
Instance Method Summary collapse
- #assign_players ⇒ Object
- #determine_winner ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #play ⇒ Object
- #print_choices ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
4 5 |
# File 'lib/kaibaibo/game.rb', line 4 def initialize end |
Instance Method Details
#assign_players ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kaibaibo/game.rb', line 26 def assign_players num_of_human_players = nil until num_of_human_players puts "How many human players?" num_of_human_players = gets.chomp.to_i if num_of_human_players == 1 @player_one = Player.new(Player.get_name) @player_two = CompPlayer.new elsif num_of_human_players == 2 @player_one = Player.new(Player.get_name) @player_two = Player.new(Player.get_name) end end end |
#determine_winner ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kaibaibo/game.rb', line 41 def determine_winner winners = {:rock => :scissors, :paper => :rock, :scissors => :paper} if winners[@player_one.status] == @player_two.status puts "#{@player_one.name} wins!" elsif winners[@player_two.status] == @player_one.status puts "#{@player_two.name} wins!" else puts "It was a tie!" end end |
#play ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kaibaibo/game.rb', line 7 def play assign_players quit = false until quit @player_one.gather_choice @player_two.gather_choice print_choices determine_winner puts "Play again?" choice = gets.chomp if choice.downcase != "yes" quit = true end end end |
#print_choices ⇒ Object
52 53 54 55 |
# File 'lib/kaibaibo/game.rb', line 52 def print_choices puts "#{@player_one.name} chose: #{@player_one.status.to_s}." puts "#{@player_two.name} chose: #{@player_two.status.to_s}." end |