class Rockpapsciss::Game
Public Class Methods
new()
click to toggle source
# File lib/rockpapsciss.rb, line 43 def initialize @player1 = Player.new("Player 1") @player2 = Player.new("Player 2") @turn = true @win = false end
Public Instance Methods
compare_moves(p1_move, p2_move)
click to toggle source
compares moves between players
# File lib/rockpapsciss.rb, line 106 def compare_moves(p1_move, p2_move) if p1_move[0] == p2_move[0] puts "It's a tie, try again..." @player1.move = nil @player2.move = nil elsif p1_move[0] == "R" if p2_move[0] == "S" puts "Player 1 wins!" @win = true else puts "#{@player2.name} wins!" @win = true end elsif p1_move[0] == "P" if p2_move[0] == "S" puts "#{@player2.name} wins!" @win = true else puts "Player 1 wins!" @win = true end else p1_move[0] == "S" if p2_move[0] == "R" puts "#{@player2.name} wins!" @win = true else puts "Player 1 wins!" @win = true end end end
game_loop()
click to toggle source
runs game logic
# File lib/rockpapsciss.rb, line 79 def game_loop print_welcome print_instructions options until @win if @turn puts "Player 1's Turn: " @player1.get_move @turn = false else puts "#{@player2.name}'s Turn: " @player2.get_move @turn = true end if @player1.move && @player2.move compare_moves(@player1.move, @player2.move) end end end
options()
click to toggle source
determine human player vs computer
# File lib/rockpapsciss.rb, line 65 def options puts "To choose your opponent, type 'human' or 'computer': " input = gets.chomp.upcase if input == 'COMPUTER' @player2 = Computer.new("Computer") elsif input == "HUMAN" else puts "Input is invalid." options end end
print_instructions()
click to toggle source
print instructions
# File lib/rockpapsciss.rb, line 60 def print_instructions print "Type your selection (ie., 'rock' or 'r'). Options include: (R)ock, (P)aper, (S)cissors\n" end
print_welcome()
click to toggle source
prints welcome
# File lib/rockpapsciss.rb, line 55 def print_welcome print "Welcome to RPSE!!!! Rock Paper Scissors Extreme!!!\n" end