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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 27 def initialize @tic_tac_toe_board = Board.new @shell = shell { text "Tic-Tac-Toe" minimum_size 150, 178 composite { grid_layout 3, true (1..3).each { |row| (1..3).each { |column| { layout_data :fill, :fill, true, true text <= [@tic_tac_toe_board[row, column], :sign] enabled <= [@tic_tac_toe_board[row, column], :empty] font style: :bold, height: 20 { @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
59 60 61 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 59 def ("Draw!") end |
#display_game_over_message(message_text) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 63 def () { text 'Game Over' }.open @tic_tac_toe_board.reset end |
#display_win_message ⇒ Object
55 56 57 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 55 def ("Player #{@tic_tac_toe_board.winning_sign} has won!") end |
#open ⇒ Object
71 72 73 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb', line 71 def open @shell.open end |