lib/mastermind/console/controller.rb in mastermind-game-0.0.1 vs lib/mastermind/console/controller.rb in mastermind-game-0.0.2
- old
+ new
@@ -1,14 +1,15 @@
module Mastermind
module Console
class Controller
def setup
puts View.introduction
- print "How many players will there be? "
+ print "How many human players will there be? "
number_of_players = Player::Human.get_input.to_i
- @player1 = get_player(1)
+ @player1 = get_player(1) if number_of_players > 0
+ @player1 ||= Player::Computer.new(name: "Computer (1)")
@player2 = get_player(2) if number_of_players > 1
@player2 ||= Player::Computer.new(name: "Computer")
end
def start_game
@@ -37,10 +38,10 @@
private
def get_player(number)
print "What is Player #{number}'s name? "
- Player::Human.new(name: Player::Human.get_input)
+ Player::Human.new(name: gets.chomp)
end
def get_codebreaker
puts "Who will be the code breaker?\n1. #{@player1.name}\n2. #{@player2.name}"
(selection = Player::Human.get_input.to_i) until (1..2) === selection