Class: Round

Inherits:
Object
  • Object
show all
Defined in:
lib/models/round.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRound

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_inputObject (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_selectionObject

Returns the value of attribute ai_selection.



41
42
43
# File 'lib/models/round.rb', line 41

def ai_selection
  @ai_selection
end

#idObject

Returns the value of attribute id.



41
42
43
# File 'lib/models/round.rb', line 41

def id
  @id
end

#player_inputObject

Returns the value of attribute player_input.



41
42
43
# File 'lib/models/round.rb', line 41

def player_input
  @player_input
end

#player_selectionObject

Returns the value of attribute player_selection.



41
42
43
# File 'lib/models/round.rb', line 41

def player_selection
  @player_selection
end

#resultObject

Returns the value of attribute result.



41
42
43
# File 'lib/models/round.rb', line 41

def result
  @result
end

Class Method Details

.clear_roundsObject



22
23
24
# File 'lib/models/round.rb', line 22

def clear_rounds
    @rounds.clear
end

.count_drawsObject



18
19
20
# File 'lib/models/round.rb', line 18

def count_draws
    @rounds.count {|x| x.result == "drew"}
end

.count_winsObject



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_idObject



30
31
32
# File 'lib/models/round.rb', line 30

def next_id
    @rounds.length + 1
end

.num_roundsObject



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_resultObject



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