Class: TicTacToe::TUI::Board
- Inherits:
-
Object
- Object
- TicTacToe::TUI::Board
- Defined in:
- lib/tic_tac_toe/tui/board.rb
Constant Summary collapse
- SYMBOL_COLORS =
{ "x" => Curses::COLOR_RED, "○" => Curses::COLOR_BLUE, "△" => Curses::COLOR_YELLOW, "□" => Curses::COLOR_GREEN, "◇" => Curses::COLOR_MAGENTA, }
- COLOR_GRAY =
8
Instance Attribute Summary collapse
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
-
#initialize(board) ⇒ Board
constructor
A new instance of Board.
- #update(board) ⇒ Object
Constructor Details
#initialize(board) ⇒ Board
Returns a new instance of Board.
17 18 19 20 |
# File 'lib/tic_tac_toe/tui/board.rb', line 17 def initialize(board) @window = new_window(board) update(board) end |
Instance Attribute Details
#window ⇒ Object (readonly)
Returns the value of attribute window.
15 16 17 |
# File 'lib/tic_tac_toe/tui/board.rb', line 15 def window @window end |
Instance Method Details
#update(board) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tic_tac_toe/tui/board.rb', line 22 def update(board) symbols = SYMBOL_COLORS.keys scanner = StringScanner.new(board) redraw do loop do box_part = scanner.scan_until(/(?=#{Regexp.union(*symbols, /\Z/)})/) write_box(box_part) break if scanner.eos? symbol = scanner.getch write_symbol(symbol, SYMBOL_COLORS.fetch(symbol)) end end end |