Browse Source

Fix a parsing bug, reset the GUI after each game

master
Peter J. Jones 7 years ago
parent
commit
f3469da7ad
2 changed files with 17 additions and 11 deletions
  1. 1
    1
      lib/freeplay/client.rb
  2. 16
    10
      lib/freeplay/gui.rb

+ 1
- 1
lib/freeplay/client.rb View File

@@ -171,7 +171,7 @@ class Freeplay::Client < EM::Connection # :nodoc:
def game (info)
logger.info("game over")

if (data = info.split(/\s*,\s*/)).size == 3
if (data = info.split(/\s*,\s*/, 3)).size == 3
winner, white_live, black_live = data
logger.info("#{winner} won")
gui.live(parse_live(white_live), parse_live(black_live)) if gui

+ 16
- 10
lib/freeplay/gui.rb View File

@@ -22,12 +22,7 @@ class Freeplay::GUI #:nodoc:

##############################################################################
def initialize (&quit)
@board = Freeplay::Board.new(:white)

@counts = {white: 1, black: 1}
@score = {white: 0, black: 0}
@players = {white: "White Stones", black: "Black Stones"}

self.board = Freeplay::Board.new(:white)
@window = create_window(&quit)
@window.show_all
end
@@ -35,10 +30,14 @@ class Freeplay::GUI #:nodoc:
##############################################################################
def board= (board)
@board = board
@container.remove(@table)
@container.pack_start(@table = create_table, true)
@container.reorder_child(@table, 1)
@container.show_all
reset

if @table
@container.remove(@table)
@container.pack_start(@table = create_table, true)
@container.reorder_child(@table, 1)
@container.show_all
end
end

##############################################################################
@@ -86,6 +85,13 @@ class Freeplay::GUI #:nodoc:
##############################################################################
private

##############################################################################
def reset
@counts = {white: 1, black: 1}
@score = {white: 0, black: 0}
@players = {white: "White Stones", black: "Black Stones"}
end

##############################################################################
def create_window (&quit)
window = Gtk::Window.new

Loading…
Cancel
Save