Class: Player

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

Overview

Create a new player, this will be the human-interaction portion.

Direct Known Subclasses

Computer, Human

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlayer

Initialize, get number of wins



9
10
11
# File 'lib/rps_telwell/player.rb', line 9

def initialize
  @wins = 0
end

Instance Attribute Details

#winsObject

Instead of this could have another method which just increments wins



6
7
8
# File 'lib/rps_telwell/player.rb', line 6

def wins
  @wins
end

Instance Method Details

#valid_move?(move) ⇒ Boolean

Validate move

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rps_telwell/player.rb', line 14

def valid_move?(move)
  # Make sure input is an integer
  if move.class == Fixnum

    # Make sure move is 1-3
    if (1..3).to_a.include?(move)
      true
    else
      false
    end
  else
    false
  end
end