Top Level Namespace

Defined Under Namespace

Modules: Chess, Save

Instance Method Summary collapse

Instance Method Details

#enter_code(game) ⇒ void

This method returns an undefined value.

choice to start a game using FEN code

Chess::Display#prompt_enter_code is used for prompting user.

Parameters:



39
40
41
42
# File 'lib/chess/play_game.rb', line 39

def enter_code(game)
  fen_code = game.prompt_enter_code
  load_game_with_code(game, fen_code)
end

#load_game_with_code(game, fen_code) ⇒ void

This method returns an undefined value.

loads a game with given code

Parameters:

  • game (Chess::Game)
  • fen_code (String)

    Fen notation for chess board.



49
50
51
52
53
54
55
# File 'lib/chess/play_game.rb', line 49

def load_game_with_code(game, fen_code)
  board = Chess::Board.new(fen_code)
  system 'clear'
  game.display_board(board.data)
  game.display_buttons
  game.start_mouse_input(board)
end

#select_save(game) ⇒ void

This method returns an undefined value.

choice to resume a saved game.

Save#read is used to read the file data

Parameters:



29
30
31
32
# File 'lib/chess/play_game.rb', line 29

def select_save(game)
  fen_code = game.prompt_select_save(game.read)
  load_game_with_code(game, fen_code)
end

#start_gamevoid

This method returns an undefined value.

Starts a Chess Game

see Chess::Display#prompt_start_choices for start choices.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chess/play_game.rb', line 10

def start_game
  game = Chess::Game.new

  choice = game.prompt_start_choices
  case choice
  when 1 then load_game_with_code(
    game,
    'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
  ) # new game FEN code
  when 2 then select_save(game)
  when 3 then enter_code(game)
  else start_game end
end