Class: Termfront::Network::Client
- Inherits:
-
Object
- Object
- Termfront::Network::Client
- Defined in:
- lib/termfront/network/client.rb
Constant Summary collapse
- TEAM_SIZES =
[1, 2, 4].freeze
- ALLOWED_WEAPONS =
%w[pistol ar].freeze
- ALLY_PLAYER_FALLBACK =
Color.rgb_to_256(70, 210, 255)
- ENEMY_PLAYER_FALLBACK =
Color.rgb_to_256(255, 110, 80)
- ALLY_BAR_FILL =
Color.rgb_to_256(0, 180, 255)
- ENEMY_BAR_FILL =
Color.rgb_to_256(255, 80, 80)
- BAR_EMPTY =
Color.rgb_to_256(80, 20, 20)
- PROJ_SHOCK =
Color.rgb_to_256(80, 220, 255)
- PROJ_NORMAL =
Color.rgb_to_256(255, 210, 80)
Instance Method Summary collapse
-
#initialize(stdout) ⇒ Client
constructor
A new instance of Client.
- #run ⇒ Object
Constructor Details
#initialize(stdout) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 |
# File 'lib/termfront/network/client.rb', line 17 def initialize(stdout) @stdout = stdout @conn = Connection.new @input = Input.new @renderer = Renderer.new(stdout) @audio = AudioManager.new end |
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/termfront/network/client.rb', line 25 def run team_size = prompt_team_size return unless team_size host, port = Config::PVP_DEFAULT_ADDRESS.split(":", 2).then { |h, p| [h, p.to_i] } queue_msg = { t: "queue", team_size: team_size } token = ENV["TERMFRONT_PVP_TOKEN"] queue_msg[:token] = token if token && !token.empty? begin @conn.connect(host, port, ca_file: ENV["TERMFRONT_TLS_CA_FILE"]) @conn.send_msg(queue_msg) rescue StandardError => e show_error("Connection failed: #{e.}") return end begin unless wait_for_start(team_size) @conn.close return end run_game_loop rescue StandardError => e show_error("Error: #{e.}") ensure @audio.close @conn.close end end |