Class: GitGameShow::GameServer
- Inherits:
-
Object
- Object
- GitGameShow::GameServer
- Defined in:
- lib/git_game_show/game_server.rb
Overview
Main Game Server class - now a lightweight coordinator of other components
Instance Attribute Summary collapse
-
#current_round ⇒ Object
readonly
Returns the value of attribute current_round.
-
#game_state ⇒ Object
readonly
Returns the value of attribute game_state.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#rounds ⇒ Object
readonly
Returns the value of attribute rounds.
Instance Method Summary collapse
- #draw_command_prompt ⇒ Object
- #draw_join_link ⇒ Object
- #draw_sidebar ⇒ Object
-
#draw_ui_frame ⇒ Object
Legacy method definitions for backwards compatibility.
- #draw_welcome_banner ⇒ Object
-
#initialize(port:, password:, rounds:, repo:) ⇒ GameServer
constructor
A new instance of GameServer.
- #log_message(message, color = :white) ⇒ Object
- #start ⇒ Object
- #start_with_ui(join_link = nil) ⇒ Object
- #update_player_list ⇒ Object
Constructor Details
#initialize(port:, password:, rounds:, repo:) ⇒ GameServer
Returns a new instance of GameServer.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/git_game_show/game_server.rb', line 6 def initialize(port:, password:, rounds:, repo:) @port = port @password = password @rounds = rounds @repo = repo # These are kept for backward compatibility but not used directly @players = {} @scores = {} @current_round = 0 @game_state = :lobby end |
Instance Attribute Details
#current_round ⇒ Object (readonly)
Returns the value of attribute current_round.
4 5 6 |
# File 'lib/git_game_show/game_server.rb', line 4 def current_round @current_round end |
#game_state ⇒ Object (readonly)
Returns the value of attribute game_state.
4 5 6 |
# File 'lib/git_game_show/game_server.rb', line 4 def game_state @game_state end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
4 5 6 |
# File 'lib/git_game_show/game_server.rb', line 4 def password @password end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
4 5 6 |
# File 'lib/git_game_show/game_server.rb', line 4 def players @players end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
4 5 6 |
# File 'lib/git_game_show/game_server.rb', line 4 def port @port end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
4 5 6 |
# File 'lib/git_game_show/game_server.rb', line 4 def repo @repo end |
#rounds ⇒ Object (readonly)
Returns the value of attribute rounds.
4 5 6 |
# File 'lib/git_game_show/game_server.rb', line 4 def rounds @rounds end |
Instance Method Details
#draw_command_prompt ⇒ Object
73 74 75 76 |
# File 'lib/git_game_show/game_server.rb', line 73 def draw_command_prompt # Forward to renderer @server_handler&.instance_variable_get(:@renderer)&.draw_command_prompt end |
#draw_join_link ⇒ Object
63 64 65 66 |
# File 'lib/git_game_show/game_server.rb', line 63 def draw_join_link # Forward to renderer @server_handler&.instance_variable_get(:@renderer)&.draw_join_link(@join_link) if @join_link end |
#draw_sidebar ⇒ Object
68 69 70 71 |
# File 'lib/git_game_show/game_server.rb', line 68 def # Forward to sidebar @server_handler&.instance_variable_get(:@sidebar)&.draw_header end |
#draw_ui_frame ⇒ Object
Legacy method definitions for backwards compatibility
53 54 55 56 |
# File 'lib/git_game_show/game_server.rb', line 53 def draw_ui_frame # Forward to renderer @server_handler&.instance_variable_get(:@renderer)&.draw_ui_frame end |
#draw_welcome_banner ⇒ Object
58 59 60 61 |
# File 'lib/git_game_show/game_server.rb', line 58 def # Forward to renderer @server_handler&.instance_variable_get(:@renderer)&. end |
#log_message(message, color = :white) ⇒ Object
78 79 80 81 |
# File 'lib/git_game_show/game_server.rb', line 78 def (, color = :white) # Forward to renderer @server_handler&.instance_variable_get(:@renderer)&.(, color) end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/git_game_show/game_server.rb', line 19 def start # Legacy method for starting the server without UI EM.run do server_handler = ServerHandler.new( port: @port, password: @password, rounds: @rounds, repo: @repo ) # Start server with minimal UI puts "Server running at ws://0.0.0.0:#{@port}".colorize(:green) server_handler.start_with_ui end end |
#start_with_ui(join_link = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/git_game_show/game_server.rb', line 35 def start_with_ui(join_link = nil) # Store the join_link @join_link = join_link # Initialize and start the server handler with UI @server_handler = ServerHandler.new( port: @port, password: @password, rounds: @rounds, repo: @repo ) # Start the server with UI @server_handler.start_with_ui(@join_link) end |
#update_player_list ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/git_game_show/game_server.rb', line 83 def update_player_list # Forward to sidebar player_manager = @server_handler&.instance_variable_get(:@player_manager) = @server_handler&.instance_variable_get(:@sidebar) if player_manager && .update_player_list(player_manager.player_names, player_manager.scores) end end |