Class: Kaibaibo::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/kaibaibo/game.rb

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



4
5
# File 'lib/kaibaibo/game.rb', line 4

def initialize
end

Instance Method Details

#assign_playersObject



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_winnerObject



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

#playObject



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


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