class Mastermind::PlayGame
Attributes
command[RW]
instream[RW]
interact[RW]
outstream[RW]
Public Class Methods
new(instream, outstream, interact)
click to toggle source
# File lib/mastermind/play_game.rb, line 9 def initialize(instream, outstream, interact) @instream = instream @outstream = outstream @interact = interact @command = "" end
Public Instance Methods
get_command()
click to toggle source
# File lib/mastermind/play_game.rb, line 26 def get_command outstream.print interact.command_prompt self.command = instream.gets.strip.upcase end
get_name(player_no)
click to toggle source
# File lib/mastermind/play_game.rb, line 57 def get_name(player_no) name = "" until valid_name?(name) outstream.print interact.name_prompt(player_no) name = instream.gets.strip end name end
player_gen(num_players)
click to toggle source
# File lib/mastermind/play_game.rb, line 47 def player_gen(num_players) players = [] outstream.puts interact.print_player_intro num_players.times do |i| name = get_name(i+1) players << Player.new(name) end players end
process_command()
click to toggle source
# File lib/mastermind/play_game.rb, line 31 def process_command case when command == "S" players = player_gen(1) Mastermind::GameRound.new(instream, outstream, interact, players).play self.command = "Q" when command == "M" players = player_gen(2) Mastermind::GameRound.new(instream, outstream, interact, players).play self.command = "Q" when command == "I" puts "play-game" else outstream.puts interact.print_invalid(command) end end
quit?()
click to toggle source
# File lib/mastermind/play_game.rb, line 70 def quit? command == "Q" || command == "QUIT" end
run()
click to toggle source
# File lib/mastermind/play_game.rb, line 16 def run outstream.puts interact.print_game_info outstream.puts interact.print_game_options until quit? get_command process_command end outstream.puts interact.print_intro end
valid_name?(name)
click to toggle source
# File lib/mastermind/play_game.rb, line 66 def valid_name?(name) name.length > 0 && name.length < 12 end