class MorganGemTest::GameController
Constants
- OPTIONS
Public Class Methods
new()
click to toggle source
# File lib/morgan_gem_test/game_controller.rb, line 5 def initialize prompt_for_mode play end
Public Instance Methods
compare_moves(first, second)
click to toggle source
# File lib/morgan_gem_test/game_controller.rb, line 32 def compare_moves(first, second) if OPTIONS[first.move] == second.move puts 'Congrats first player wins!' abort elsif OPTIONS[second.move] == first.move puts 'Congrats second player wins!' abort else puts 'It was a tie!' abort end end
play()
click to toggle source
# File lib/morgan_gem_test/game_controller.rb, line 10 def play @player_one.ask_move @player_two.ask_move compare_moves(@player_one, @player_two) end
prompt_for_mode()
click to toggle source
# File lib/morgan_gem_test/game_controller.rb, line 16 def prompt_for_mode puts 'Which mode would you like to play: "one player" "two player" ' set_players(gets.chomp) end
set_players(mode)
click to toggle source
# File lib/morgan_gem_test/game_controller.rb, line 21 def set_players(mode) case mode when 'one player' @player_one = PlayerView.new(gets.chomp) @player_two = PlayerView.new(:computer) when 'two player' @player_one = PlayerView.new(gets.chomp) @player_two = PlayerView.new(gets.chomp) end end