Class: PlayGOT::RockPaperScissors

Inherits:
Object
  • Object
show all
Defined in:
lib/play_GOT/rock_paper_scissors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRockPaperScissors

Returns a new instance of RockPaperScissors.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/play_GOT/rock_paper_scissors.rb', line 4

def initialize
  puts "This is a simple game of Rock, Paper, Scissors. Best 3 out of 5."
  @your_score = 0 
  @enemy_score = 0 
  @round = 1 
  
  until @your_score == 3 || @enemy_score == 3
    
    rock_paper_scissors
    
    puts "Your move: #{@your_move.light_green}\nEnemy move: #{@enemy_move.light_green}"
    
    if @your_move == "Rock" && @enemy_move == "Scissors" || @your_move == "Paper" && @enemy_move == "rock" || @your_move == "Scissors" && @enemy_move == "Paper"
      @your_score += 1 
      puts "You win!\nYour Score: #{@your_score.to_s.light_green}\nEnemy Score:#{@enemy_score.to_s.light_green}"
    
    elsif @your_move == @enemy_move 
      puts "Draw! No point is awarded."
    
    else 
      @enemy_score += 1 
      puts "You lose!\nYour Score: #{your_score.to_s.light_green}\nEnemy Score:#{enemy_score.to_s.light_green}"
    end 
    
    @round += 1 
  
  end 
end

Instance Attribute Details

#enemy_moveObject

Returns the value of attribute enemy_move.



2
3
4
# File 'lib/play_GOT/rock_paper_scissors.rb', line 2

def enemy_move
  @enemy_move
end

#enemy_scoreObject

Returns the value of attribute enemy_score.



2
3
4
# File 'lib/play_GOT/rock_paper_scissors.rb', line 2

def enemy_score
  @enemy_score
end

#roundObject

Returns the value of attribute round.



2
3
4
# File 'lib/play_GOT/rock_paper_scissors.rb', line 2

def round
  @round
end

#your_moveObject

Returns the value of attribute your_move.



2
3
4
# File 'lib/play_GOT/rock_paper_scissors.rb', line 2

def your_move
  @your_move
end

#your_scoreObject

Returns the value of attribute your_score.



2
3
4
# File 'lib/play_GOT/rock_paper_scissors.rb', line 2

def your_score
  @your_score
end

Instance Method Details

#rock_paper_scissorsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/play_GOT/rock_paper_scissors.rb', line 34

def rock_paper_scissors
  puts "Round #{@round.to_s.light_green} - Choose your move: Rock, Paper or Scissors?"
  puts "1 - Rock\n2 - Paper\n3 - Scissors".blue
    
  input = gets.strip
  @enemy_move = ["Rock", "Paper", "Scissors"].sample
  
  case input 
  when "1"
    @your_move = "Rock"
  when "2"
    @your_move = "Paper"
  when "3"
    @your_move = "Scissors"
  else 
    puts "You've spoken something mystical that I don't understand.".light_red
    rock_paper_scissors
  end 
end