class Testownik::RPSGame
Constants
- FULLNAMES
Attributes
player_one_choice[R]
player_two_choice[R]
Public Class Methods
new()
click to toggle source
# File lib/testownik/RPSGame.rb, line 15 def initialize puts "Hello and welcome in Rock Paper Scissors Game" @player_one = HumanPlayer.new end
Public Instance Methods
check_draw(player_one_choice, player_two_choice)
click to toggle source
# File lib/testownik/RPSGame.rb, line 73 def check_draw(player_one_choice, player_two_choice) if player_one_choice == player_two_choice puts "Bummer, you've drawn..." true else false end end
check_victory(player_one_choice, player_two_choice)
click to toggle source
# File lib/testownik/RPSGame.rb, line 54 def check_victory(player_one_choice, player_two_choice) if player_one_choice == "p" && player_two_choice == "r" ||player_one_choice == "r" && player_two_choice == "p" puts "Paper Wins!!!" true elsif player_one_choice == "p" && player_two_choice == "s" ||player_one_choice == "s" && player_two_choice == "p" puts "Scissors Wins!!!" true elsif player_one_choice == "s" && player_two_choice == "r" ||player_one_choice == "r" && player_two_choice == "s" puts "Rock Wins!!!" true end end
ending_game()
click to toggle source
# File lib/testownik/RPSGame.rb, line 67 def ending_game puts "Would you like to play again? Please type 'y' to try again / or any other key to exit the game" gets.chomp end
get_opponent()
click to toggle source
# File lib/testownik/RPSGame.rb, line 20 def get_opponent loop do puts "Press 1 to play against computer, or 2 to play with another player" opponent_select = gets.chomp.to_i if opponent_select == 2 @player_two = HumanPlayer.new break elsif opponent_select == 1 @player_two = ComputerPlayer.new break else puts "We do not understand your selection. \ Please read instruction clearly." end end end
play()
click to toggle source
# File lib/testownik/RPSGame.rb, line 37 def play get_opponent loop do player_one_choice = @player_one.get_decision player_two_choice = @player_two.get_decision puts "So player's One choice is #{FULLNAMES[player_one_choice]}" puts "and player's Two choice is #{FULLNAMES[player_two_choice]}" check_victory(player_one_choice, player_two_choice) check_draw(player_one_choice, player_two_choice) break if ending_game != "y" end end