Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/rock_paper_scissors_cli/player.rb
Direct Known Subclasses
Constant Summary collapse
- WEAPONS =
['rock','paper','scissors']
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#total_losses ⇒ Object
readonly
Returns the value of attribute total_losses.
-
#total_ties ⇒ Object
readonly
Returns the value of attribute total_ties.
-
#total_wins ⇒ Object
readonly
Returns the value of attribute total_wins.
Instance Method Summary collapse
- #add_loss ⇒ Object
- #add_tie ⇒ Object
- #add_win ⇒ Object
-
#initialize(name) ⇒ Player
constructor
A new instance of Player.
- #render_selection ⇒ Object
- #render_stats ⇒ Object
- #select_weapon ⇒ Object
Constructor Details
#initialize(name) ⇒ Player
Returns a new instance of Player.
6 7 8 9 10 11 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 6 def initialize(name) @name = name || "Player" @total_wins = 0 @total_losses = 0 @total_ties = 0 end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
4 5 6 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 4 def item @item end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 4 def name @name end |
#total_losses ⇒ Object (readonly)
Returns the value of attribute total_losses.
4 5 6 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 4 def total_losses @total_losses end |
#total_ties ⇒ Object (readonly)
Returns the value of attribute total_ties.
4 5 6 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 4 def total_ties @total_ties end |
#total_wins ⇒ Object (readonly)
Returns the value of attribute total_wins.
4 5 6 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 4 def total_wins @total_wins end |
Instance Method Details
#add_loss ⇒ Object
43 44 45 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 43 def add_loss @total_losses += 1 end |
#add_tie ⇒ Object
39 40 41 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 39 def add_tie @total_ties += 1 end |
#add_win ⇒ Object
35 36 37 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 35 def add_win @total_wins += 1 end |
#render_selection ⇒ Object
17 18 19 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 17 def render_selection "#{@name}'s #{@item}" end |
#render_stats ⇒ Object
13 14 15 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 13 def render_stats puts "#{@name} - Total Wins: #{total_wins} Total Ties: #{total_ties} Total Losses: #{total_losses}" end |
#select_weapon ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rock_paper_scissors_cli/player.rb', line 22 def select_weapon loop do input = gets.strip.downcase if WEAPONS.include?(input) @item = input break else puts "--Invalid Weapon selection--" end end end |