Skip to content

Commit

Permalink
v1.2 (2009-10-06) - Created a chime for when it's a human player's tu…
Browse files Browse the repository at this point in the history
…rn but

  the last turn was started over 6 seconds ago. There is currently no way to
  disable it, wait for 1.2.1!
  • Loading branch information
audiodude committed Oct 6, 2009
1 parent ed091a4 commit 828915e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README
Expand Up @@ -16,6 +16,9 @@ THANKS:
permission for anyone to code it!

CHANGES:
1.2 (2009-10-06) - Created a chime for when it's a human player's turn but
the last turn was started over 6 seconds ago. There is currently no way to
disable it, wait for 1.2.1!

1.1 (2009-10-01) - Visual refresh. White pieces are now white, and all
pieces are bigger. Red dot on the last placed piece.
Expand Down
11 changes: 10 additions & 1 deletion main_controller.rb
Expand Up @@ -26,14 +26,15 @@ class MainController
# The controller observes the gameboard, and everyone else observes the controller
include Observable

attr_reader :roots
attr_reader :roots, :last_turn_time
attr_accessor :player1, :player2

RUN = 1
PAUSE = 0
STOP = nil

BOARD_READY_EVENT = -33
TURN_CHANGE_READY_EVENT = -58

def initialize
@run_mutex = Mutex.new
Expand All @@ -45,6 +46,8 @@ def initialize
def reset!
# The game board is a 19x19 2D grid of intersections (a Go board)
@gameboard = TanboBoard.new

@last_turn_time = 0

@gameboard.add_observer(self)

Expand Down Expand Up @@ -98,8 +101,14 @@ def start!
next
end

changed
notify_observers(TURN_CHANGE_READY_EVENT)
if @gameboard.turn == TanboBoard::BLACK
start_time = Time.new.to_f
next_move = @player1.move(@gameboard, last_move)
end_time = Time.new.to_f

@last_turn_time = end_time - start_time
else
next_move = @player2.move(@gameboard, last_move)
end
Expand Down
15 changes: 15 additions & 0 deletions main_frame.rb
Expand Up @@ -40,6 +40,8 @@ def initialize(controller)

self.set_min_size([450,550])

@snd_your_turn = Sound.new('./resources/your_turn.wav')

@sizer = Wx::BoxSizer.new(VERTICAL)

@board = BoardPanel.new(self, @controller)
Expand Down Expand Up @@ -159,6 +161,19 @@ def update(event)
@waiting_to_select_ai = false
end
end
when MainController::TURN_CHANGE_READY_EVENT
if ( # See if it is now a human's turn
( @controller.get_board.turn == TanboBoard::BLACK &&
@player1.is_a?(HumanPlayer) ) ||
( @controller.get_board.turn == TanboBoard::WHITE &&
@player2.is_a?(HumanPlayer) )
)
if @controller.last_turn_time > 6 # We've waited more than 6 seconds
@snd_your_turn.play(SOUND_ASYNC) if @snd_your_turn.is_ok
else
puts @controller.last_turn_time
end
end
end
end

Expand Down
Binary file added resources/your_turn.wav
Binary file not shown.

0 comments on commit 828915e

Please sign in to comment.