Class: Runner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/software_challenge_client/runner.rb

Overview

Klasse zum Starten einer neue Verbindung zum Spielserver und Verarbeiten der Nachrichten des Servers.

Instance Method Summary collapse

Methods included from Logging

#logger, logger

Constructor Details

#initialize(host, port, client, reservation = nil) ⇒ Runner

Returns a new instance of Runner


10
11
12
13
14
15
16
17
18
# File 'lib/software_challenge_client/runner.rb', line 10

def initialize(host, port, client, reservation = nil)
  logger.info 'Software Challenge 2019'
  logger.info 'Ruby Client'
  logger.info "Host: #{host}"
  logger.info "Port: #{port}"

  board = Board.new
  @network = Network.new(host, port, board, client, reservation)
end

Instance Method Details

#startObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/software_challenge_client/runner.rb', line 20

def start
  @network.connect
  unless @network.connected
    logger.error 'Not connected'
    return
  end

  while @network.connected
    @network.processMessages
    sleep(0.01)
  end

  logger.info 'Program end...'
  @network.disconnect
end