class Round
Attributes
ai_input[R]
ai_selection[RW]
id[RW]
player_input[RW]
player_selection[RW]
result[RW]
Public Class Methods
clear_rounds()
click to toggle source
# File lib/models/round.rb, line 22 def clear_rounds @rounds.clear end
count_draws()
click to toggle source
# File lib/models/round.rb, line 18 def count_draws @rounds.count {|x| x.result == "drew"} end
count_wins()
click to toggle source
# File lib/models/round.rb, line 14 def count_wins @rounds.count {|x| x.result == "won!"} end
get_sound(result)
click to toggle source
# File lib/models/round.rb, line 26 def get_sound(result) @round_result_sounds[result] end
new()
click to toggle source
# File lib/models/round.rb, line 43 def initialize @id = nil @player_input = nil @player_selection = nil @ai_input = rand(3) @ai_selection = self.selections(@ai_input) @result = nil end
next_id()
click to toggle source
# File lib/models/round.rb, line 30 def next_id @rounds.length + 1 end
num_rounds()
click to toggle source
# File lib/models/round.rb, line 10 def num_rounds @rounds.length + 1 end
save(round)
click to toggle source
# File lib/models/round.rb, line 34 def save(round) round.id = next_id @rounds << round end
Public Instance Methods
determine_result()
click to toggle source
# File lib/models/round.rb, line 57 def determine_result math_check = @player_input - @ai_input case math_check when 0 @result = "drew" when 1, -2 @result = "won!" when -1, 2 @result = "lost" end end
save!()
click to toggle source
# File lib/models/round.rb, line 69 def save! self.class.save(self) end
selections(choice)
click to toggle source
# File lib/models/round.rb, line 52 def selections(choice) select_from = ["Sith".colorize(:light_red), "Jedi".colorize(:light_cyan), "Ewok".colorize(:light_green)] select_from[choice] end