Class: ConsoleShogi::GameHistory
- Inherits:
-
Object
- Object
- ConsoleShogi::GameHistory
- Defined in:
- lib/console_shogi/game_history.rb
Instance Method Summary collapse
-
#initialize(game_histories:) ⇒ GameHistory
constructor
A new instance of GameHistory.
- #start ⇒ Object
Constructor Details
#initialize(game_histories:) ⇒ GameHistory
Returns a new instance of GameHistory.
7 8 9 10 11 12 13 |
# File 'lib/console_shogi/game_history.rb', line 7 def initialize(game_histories:) @game_histories = game_histories # TODO game_count という名前は分かりづらいので変える @game_count = game_histories.count Terminal::Operator.print_start_history end |
Instance Method Details
#start ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 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 54 |
# File 'lib/console_shogi/game_history.rb', line 15 def start while key = STDIN.getch cursor = Terminal::Operator.cursor # NOTE Ctrl-C を押したら終了 if key == "\C-c" exit # NOTE 矢印キーを押したらカーソルを移動 elsif key == "\e" && STDIN.getch == "[" key = STDIN.getch cursor.move(key) elsif key == "\r" location = cursor.grid_position.location next unless location.history? if location.resume? Terminal::Operator.clear_scrren Terminal::Operator.print_board(board: game_histories.last[:board], sente_komadai: game_histories.last[:sente_komadai], gote_komadai: game_histories.last[:gote_komadai]) Terminal::Operator. return elsif location.back? next if game_count == 1 @game_count -= 1 Terminal::Operator.print_board(board: game_histories[game_count - 1][:board], sente_komadai: game_histories[game_count - 1][:sente_komadai], gote_komadai: game_histories[game_count - 1][:gote_komadai]) elsif location.forward? next if game_count == game_histories.count @game_count += 1 Terminal::Operator.print_board(board: game_histories[game_count - 1][:board], sente_komadai: game_histories[game_count - 1][:sente_komadai], gote_komadai: game_histories[game_count - 1][:gote_komadai]) end end end end |