Class: ChessEngine::CLI

Inherits:
Object
  • Object
show all
Includes:
Input
Defined in:
lib/chess_engine/cli.rb

Overview

A Simple command line interface for the Chess Game

Instance Method Summary collapse

Methods included from Input

#get_input

Constructor Details

#initializeCLI

Starts a new game session



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chess_engine/cli.rb', line 18

def initialize
  begin
    mode = get_input("\nChoose the game mode:\n1. New game\n2. Continue\nEnter your choice (1 or 2): ", /^[12]$/)
    @game = mode == "1" ? Game.new : choose_game
  rescue NoGamesError => e
    puts "#{e.message}. Try again"
    retry
  end
  play
  save if save?
end