class PirateGame::MasterApp

Public Class Methods

new() click to toggle source
# File lib/pirate_game/master_app.rb, line 8
def initialize
  @game_master = nil
end
run() click to toggle source
# File lib/pirate_game/master_app.rb, line 4
def self.run
  new.run
end

Public Instance Methods

detect_stage_status_change() { || ... } click to toggle source

If the stage status has changed, yields to the block

# File lib/pirate_game/master_app.rb, line 90
def detect_stage_status_change
  return unless @game_master.stage
  return if @stage_status == @game_master.stage.status

  @stage_status = @game_master.stage.status

  yield
end
detect_state_change() { || ... } click to toggle source

If the game_master.state has changed, yields to the block.

# File lib/pirate_game/master_app.rb, line 80
def detect_state_change
  return if @state == @game_master.state

  @state = @game_master.state

  yield
end
display_screen() click to toggle source
# File lib/pirate_game/master_app.rb, line 31
def display_screen
  @game_master.update

  clear do
    background Boot::COLORS[:light]

    stack :margin => 20 do
      title "Game #{@game_master.name}", stroke: Boot::COLORS[:dark]

      @button_stack = stack
      @registrations = para stroke: Boot::COLORS[:dark]
      @stage_info = para stroke: Boot::COLORS[:dark]
      @game_info = para stroke: Boot::COLORS[:dark]
    end

    animate(5) {
      detect_state_change {
        update_button_stack
      }

      detect_stage_status_change {
        @game_master.send_stage_info_to_clients
      }

      @registrations.replace @game_master.registrations_text
      @stage_info.replace @game_master.stage_info
      @game_info.replace @game_master.game_info
    }
  end
end
launch_screen() click to toggle source
# File lib/pirate_game/master_app.rb, line 15
def launch_screen
  clear do
    background Boot::COLORS[:dark]
    stack margin: 20 do
      title "Start Game", stroke: Boot::COLORS[:light]
      edit_line text: 'Name' do |s|
        @name = s.text
      end
      button('launch') {
        @game_master = GameMaster.new(name: @name)
        display_screen
      }
    end
  end
end
run() click to toggle source
# File lib/pirate_game/master_app.rb, line 12
def run
  Shoes.app width: 360, height: 360, resizeable: false, title: 'Game Master' do

    def launch_screen
      clear do
        background Boot::COLORS[:dark]
        stack margin: 20 do
          title "Start Game", stroke: Boot::COLORS[:light]
          edit_line text: 'Name' do |s|
            @name = s.text
          end
          button('launch') {
            @game_master = GameMaster.new(name: @name)
            display_screen
          }
        end
      end
    end

    def display_screen
      @game_master.update

      clear do
        background Boot::COLORS[:light]

        stack :margin => 20 do
          title "Game #{@game_master.name}", stroke: Boot::COLORS[:dark]

          @button_stack = stack
          @registrations = para stroke: Boot::COLORS[:dark]
          @stage_info = para stroke: Boot::COLORS[:dark]
          @game_info = para stroke: Boot::COLORS[:dark]
        end

        animate(5) {
          detect_state_change {
            update_button_stack
          }

          detect_stage_status_change {
            @game_master.send_stage_info_to_clients
          }

          @registrations.replace @game_master.registrations_text
          @stage_info.replace @game_master.stage_info
          @game_info.replace @game_master.game_info
        }
      end
    end

    ##
    # Responsible for updating the display of the START button

    def update_button_stack
      @button_stack.clear do

        case @state
        when :startable
          button('START') {
            @game_master.start
          }
        end
      end
    end

    ##
    # If the game_master.state has changed, yields to the block.

    def detect_state_change
      return if @state == @game_master.state

      @state = @game_master.state

      yield
    end

    ##
    # If the stage status has changed, yields to the block
    def detect_stage_status_change
      return unless @game_master.stage
      return if @stage_status == @game_master.stage.status

      @stage_status = @game_master.stage.status

      yield
    end

    launch_screen
  end
end
update_button_stack() click to toggle source

Responsible for updating the display of the START button

# File lib/pirate_game/master_app.rb, line 65
def update_button_stack
  @button_stack.clear do

    case @state
    when :startable
      button('START') {
        @game_master.start
      }
    end
  end
end