Class: TicTacToe
- Inherits:
-
Object
- Object
- TicTacToe
- Includes:
- Glimmer
- Defined in:
- lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb,
lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe/cell.rb,
lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe/board.rb
Defined Under Namespace
Instance Method Summary collapse
- #display_draw_message ⇒ Object
- #display_game_over_message(message_text) ⇒ Object
- #display_win_message ⇒ Object
-
#initialize ⇒ TicTacToe
constructor
A new instance of TicTacToe.
- #open ⇒ Object
Constructor Details
#initialize ⇒ TicTacToe
Returns a new instance of TicTacToe.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 6 def initialize @tic_tac_toe_board = Board.new @shell = shell { text "Tic-Tac-Toe" composite { grid_layout 3, true (1..3).each { |row| (1..3).each { |column| { layout_data :fill, :fill, true, true text bind(@tic_tac_toe_board[row, column], :sign) enabled bind(@tic_tac_toe_board[row, column], :empty) { @tic_tac_toe_board.mark(row, column) } } } } } } observe(@tic_tac_toe_board, :game_status) { |game_status| if game_status == Board::WIN if game_status == Board::DRAW } end |
Instance Method Details
#display_draw_message ⇒ Object
36 37 38 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 36 def ("Draw!") end |
#display_game_over_message(message_text) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 40 def () (@shell) { text 'Game Over' }.open @tic_tac_toe_board.reset end |
#display_win_message ⇒ Object
32 33 34 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 32 def ("Player #{@tic_tac_toe_board.winning_sign} has won!") end |
#open ⇒ Object
48 49 50 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 48 def open @shell.open end |