Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/paper_rocks_scissors/game.rb
Overview
Rock, Paper, Scissors
Instance Method Summary collapse
- #get_comp_select ⇒ Object
- #get_player_select(input) ⇒ Object
- #initiliaze ⇒ Object
- #play ⇒ Object
- #valid_input(input = "") ⇒ Object
Instance Method Details
#get_comp_select ⇒ Object
14 15 16 17 |
# File 'lib/paper_rocks_scissors/game.rb', line 14 def get_comp_select selection = rand(3) selection end |
#get_player_select(input) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/paper_rocks_scissors/game.rb', line 19 def get_player_select(input) if input.downcase == "scissors" value = 0 elsif input.downcase == "paper" value = 1 elsif input.downcase == "rock" value = 2 end value end |
#initiliaze ⇒ Object
3 4 |
# File 'lib/paper_rocks_scissors/game.rb', line 3 def initiliaze end |
#play ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/paper_rocks_scissors/game.rb', line 30 def play puts "Please choose between Rock, Paper, or Scissors" input = gets.chomp if valid_input(input) comp_select = get_comp_select player_select = get_player_select(input) action, msg = "", "" if comp_select + player_select == 1 action = "Scissors cut Paper!" elsif comp_select + player_select == 2 action = "Rock crushes Scissors!" elsif comp_select + player_select == 3 action = "Paper covers Rock!" end if player_select - comp_select == -1 or player_select - comp_select == 2 msg = "Player Wins" elsif comp_select == player_select msg = "It's a tie" else msg = "The Computer Wins" end comp_str = ["scissors", "paper", "rock"][comp_select] player_str = ["scissors", "paper", "rock"][player_select] puts "Player chooses #{player_str}, the Computer chooses #{comp_str}" puts action puts msg puts else Game.new.play end end |
#valid_input(input = "") ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/paper_rocks_scissors/game.rb', line 6 def valid_input(input="") = ["scissors", "paper", "rock"] if input == "q" exit end .include? input.downcase end |