Class: Process::Roulette::Controller::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/process/roulette/controller/driver.rb

Overview

Encapsulates both the controller and spectator behavior. If the password is nil, the controller is considered a spectator, allowed to watch the bout, but not to control it.

It’s state machine works as follows:

CONNECT
  - connects to croupier, performs handshake
  - advances to COMMAND
COMMAND
  - waits for input from terminal (unless spectator)
    * "GO" => sends "GO" to croupier
    * "EXIT" => sends "EXIT" to croupier
  - listens for commands from croupier
    * "GO" => advances to GAME
    * "EXIT" => advances to FINISH
GAME
  - listens for updates from croupier
    # "GO" => begins next round
    * "UPDATE" => print update from croupier
    * "DONE" => advances to DONE
DONE
  - diplays final scoreboard
  - advances to COMMAND
FINISH
  - closes sockets, terminates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, password = nil) ⇒ Driver

Returns a new instance of Driver.



38
39
40
41
42
# File 'lib/process/roulette/controller/driver.rb', line 38

def initialize(host, port, password = nil)
  @host = host
  @port = port
  @password = password
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



35
36
37
# File 'lib/process/roulette/controller/driver.rb', line 35

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



35
36
37
# File 'lib/process/roulette/controller/driver.rb', line 35

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



35
36
37
# File 'lib/process/roulette/controller/driver.rb', line 35

def port
  @port
end

#socketObject

Returns the value of attribute socket.



36
37
38
# File 'lib/process/roulette/controller/driver.rb', line 36

def socket
  @socket
end

Instance Method Details

#runObject



48
49
50
51
# File 'lib/process/roulette/controller/driver.rb', line 48

def run
  handler = Controller::ConnectHandler
  handler = handler.new(self).run while handler
end

#spectator?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/process/roulette/controller/driver.rb', line 44

def spectator?
  password.nil?
end