Class: Player

Inherits:
Object
  • Object
show all
Defined in:
lib/rock_paper_scissors_cli/player.rb

Direct Known Subclasses

Computer

Constant Summary collapse

WEAPONS =
['rock','paper','scissors']

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#itemObject (readonly)

Returns the value of attribute item.



4
5
6
# File 'lib/rock_paper_scissors_cli/player.rb', line 4

def item
  @item
end

#nameObject (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_lossesObject (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_tiesObject (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_winsObject (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_lossObject



43
44
45
# File 'lib/rock_paper_scissors_cli/player.rb', line 43

def add_loss
	@total_losses += 1
end

#add_tieObject



39
40
41
# File 'lib/rock_paper_scissors_cli/player.rb', line 39

def add_tie
	@total_ties += 1
end

#add_winObject



35
36
37
# File 'lib/rock_paper_scissors_cli/player.rb', line 35

def add_win
	@total_wins += 1
end

#render_selectionObject



17
18
19
# File 'lib/rock_paper_scissors_cli/player.rb', line 17

def render_selection
	"#{@name}'s #{@item}"
end

#render_statsObject



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_weaponObject



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