class C4::App
Attributes
game[R]
viewer[R]
Public Class Methods
new()
click to toggle source
# File lib/c4.rb, line 15 def initialize @game = C4::Model::Game.new @viewer = C4::View::Cli.new(game) end
Public Instance Methods
run()
click to toggle source
# File lib/c4.rb, line 20 def run start finish end
Private Instance Methods
finish()
click to toggle source
# File lib/c4.rb, line 45 def finish return puts("Player \"#{game.winner}\" won!") if game.winner return puts('No more moves possible. Game over.') if game.impasse? end
play()
click to toggle source
# File lib/c4.rb, line 36 def play puts "Player \"#{game.current_player}\" - choose column (type a number from 0 to #{C4::Model::Game::COLUMNS}): " column = STDIN.gets.chomp.to_i game.play!(column) rescue C4::Model::ColumnFullError, C4::Model::InvalidColumnError => e puts e.message retry end
start()
click to toggle source
# File lib/c4.rb, line 27 def start until game.winner || game.impasse? viewer.print play end viewer.print end