Class: Round
- Inherits:
-
Object
- Object
- Round
- Defined in:
- lib/models/round.rb
Instance Attribute Summary collapse
-
#ai_input ⇒ Object
readonly
Returns the value of attribute ai_input.
-
#ai_selection ⇒ Object
Returns the value of attribute ai_selection.
-
#id ⇒ Object
Returns the value of attribute id.
-
#player_input ⇒ Object
Returns the value of attribute player_input.
-
#player_selection ⇒ Object
Returns the value of attribute player_selection.
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
- .clear_rounds ⇒ Object
- .count_draws ⇒ Object
- .count_wins ⇒ Object
- .get_sound(result) ⇒ Object
- .next_id ⇒ Object
- .num_rounds ⇒ Object
- .save(round) ⇒ Object
Instance Method Summary collapse
- #determine_result ⇒ Object
-
#initialize ⇒ Round
constructor
A new instance of Round.
- #save! ⇒ Object
- #selections(choice) ⇒ Object
Constructor Details
#initialize ⇒ Round
Returns a new instance of Round.
43 44 45 46 47 48 49 50 |
# 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 |
Instance Attribute Details
#ai_input ⇒ Object (readonly)
Returns the value of attribute ai_input.
40 41 42 |
# File 'lib/models/round.rb', line 40 def ai_input @ai_input end |
#ai_selection ⇒ Object
Returns the value of attribute ai_selection.
41 42 43 |
# File 'lib/models/round.rb', line 41 def ai_selection @ai_selection end |
#id ⇒ Object
Returns the value of attribute id.
41 42 43 |
# File 'lib/models/round.rb', line 41 def id @id end |
#player_input ⇒ Object
Returns the value of attribute player_input.
41 42 43 |
# File 'lib/models/round.rb', line 41 def player_input @player_input end |
#player_selection ⇒ Object
Returns the value of attribute player_selection.
41 42 43 |
# File 'lib/models/round.rb', line 41 def player_selection @player_selection end |
#result ⇒ Object
Returns the value of attribute result.
41 42 43 |
# File 'lib/models/round.rb', line 41 def result @result end |
Class Method Details
.clear_rounds ⇒ Object
22 23 24 |
# File 'lib/models/round.rb', line 22 def clear_rounds @rounds.clear end |
.count_draws ⇒ Object
18 19 20 |
# File 'lib/models/round.rb', line 18 def count_draws @rounds.count {|x| x.result == "drew"} end |
.count_wins ⇒ Object
14 15 16 |
# File 'lib/models/round.rb', line 14 def count_wins @rounds.count {|x| x.result == "won!"} end |
.get_sound(result) ⇒ Object
26 27 28 |
# File 'lib/models/round.rb', line 26 def get_sound(result) @round_result_sounds[result] end |
.next_id ⇒ Object
30 31 32 |
# File 'lib/models/round.rb', line 30 def next_id @rounds.length + 1 end |
.num_rounds ⇒ Object
10 11 12 |
# File 'lib/models/round.rb', line 10 def num_rounds @rounds.length + 1 end |
.save(round) ⇒ Object
34 35 36 37 |
# File 'lib/models/round.rb', line 34 def save(round) round.id = next_id @rounds << round end |
Instance Method Details
#determine_result ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# 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! ⇒ Object
69 70 71 |
# File 'lib/models/round.rb', line 69 def save! self.class.save(self) end |
#selections(choice) ⇒ Object
52 53 54 55 |
# 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 |