15Slide
CommandUI Class Reference

A UI for commands from the terminal for 15Slide. More...

#include <CommandUI.h>

Public Types

enum  command {
  command::invalid, command::help, command::demo, command::newgame,
  command::slide, command::print, command::save, command::load,
  command::options, command::enable, command::disable, command::about,
  command::licence, command::exit, command::debug
}
 Possible commands. More...
 

Public Member Functions

void start (Grid15::Grid &grid)
 The main loop for the CommandUI. More...
 
void handleCommand (const std::string &inputtedLine, Grid15::Grid &grid)
 Handles a command from the user and does something acordingly. More...
 

Static Public Member Functions

static void printGrid (Grid15::Grid::gridArray_t grid)
 Prints a grid array. More...
 
static void printGrid (const Grid15::Grid &grid)
 Prints a Grid. More...
 

Private Member Functions

void handleOptions (const std::string &option, bool optionSetting)
 Handles an option string and sets the appropriate option. More...
 
void handleDebug (const std::string &inputtedLine)
 Handles the debug commands. Only avaliable if ProgramStuff::Build::DEBUG equals true. More...
 
void saveGame (const std::string &saveFile, const Grid15::Grid &grid)
 Saves the game. More...
 
void loadGame (const std::string &saveFile, Grid15::Grid &grid)
 Loads the game. More...
 
void swapTile (const std::int64_t tile, Grid15::Grid &grid)
 Swaps a tile. More...
 

Static Private Member Functions

static void runDemo ()
 The 15Slide demo. More...
 
static void displayHelp ()
 List commands to user. More...
 
static void displayAbout ()
 About 15Slide. More...
 
static void displayLicence ()
 Licence information for 15Slide and other libraries. More...
 
static void displayOptions ()
 List options to user. More...
 

Private Attributes

bool autoSave {ProgramStuff::AUTOSAVE_ON_SLIDE_DEFAULT}
 Autosave to last savefile. More...
 
bool autoGrid {true}
 Autoprint the grid. More...
 
bool autoExit {false}
 Exit the game on win automatically. More...
 
bool easySlide {true}
 Slide a tile without having to type "slide" first. More...
 
std::string defaultSaveFile {""}
 The savefile to use for autoSaving, found during CommandUI::saveGame or CommandUI::loadGame. More...
 
bool wantsToExit {false}
 Whether the user wants to exit or not; used internally to exit CommandUI::start. More...
 

Static Private Attributes

static const std::unordered_map< std::string, CommandUI::commandcommandMap
 A map from std::string to CommandUI::command for input parsing. More...
 

Detailed Description

A UI for commands from the terminal for 15Slide.

Valid Commands

Command Function
help Displays a list of valid commands
demo Walks you through the game
newgame Ends the current game and starts a new one
slide num Slides the tile with the number given
print str Prints the current "grid" or the "goal" grid
save str Saves the game to the specified file
load str Loads the game from the specified file
options Displays a list of valid options
enable str Enables the specified option
disable str Disables the specified option
about Cool stuff about 15Slide
licence Licence information for 15Slide and other libraries
exit Exit 15Slide
Author
John Jekel
Date
2017-2018

Member Enumeration Documentation

◆ command

enum CommandUI::command
strong

Possible commands.

Enumerator
invalid 
help 
demo 
newgame 
slide 
print 
save 
load 
options 
enable 
disable 
about 
licence 
exit 
debug 

Member Function Documentation

◆ displayAbout()

void CommandUI::displayAbout ( )
staticprivate

About 15Slide.

◆ displayHelp()

void CommandUI::displayHelp ( )
staticprivate

List commands to user.

◆ displayLicence()

void CommandUI::displayLicence ( )
staticprivate

Licence information for 15Slide and other libraries.

◆ displayOptions()

void CommandUI::displayOptions ( )
staticprivate

List options to user.

◆ handleCommand()

void CommandUI::handleCommand ( const std::string &  inputtedLine,
Grid15::Grid grid 
)

Handles a command from the user and does something acordingly.

Parameters
inputtedLineThe line to parse
gridThe Grid to change

◆ handleDebug()

void CommandUI::handleDebug ( const std::string &  inputtedLine)
private

Handles the debug commands. Only avaliable if ProgramStuff::Build::DEBUG equals true.

Parameters
inputtedLineThe arguments to parse
Exceptions
std::runtime_errorIf the user uses the "crash" command

◆ handleOptions()

void CommandUI::handleOptions ( const std::string &  option,
bool  optionSetting 
)
private

Handles an option string and sets the appropriate option.

Parameters
optionThe option string to set
optionSettingTurn it on or off

◆ loadGame()

void CommandUI::loadGame ( const std::string &  saveFile,
Grid15::Grid grid 
)
private

Loads the game.

Parameters
saveFileThe file to load from
gridThe Grid to load to

◆ printGrid() [1/2]

void CommandUI::printGrid ( Grid15::Grid::gridArray_t  grid)
static

Prints a grid array.

Parameters
gridThe grid array to print

◆ printGrid() [2/2]

void CommandUI::printGrid ( const Grid15::Grid grid)
static

Prints a Grid.

Parameters
gridThe Grid to print

◆ runDemo()

void CommandUI::runDemo ( )
staticprivate

The 15Slide demo.

◆ saveGame()

void CommandUI::saveGame ( const std::string &  saveFile,
const Grid15::Grid grid 
)
private

Saves the game.

Parameters
saveFileThe file to save to
gridThe Grid to save

◆ start()

void CommandUI::start ( Grid15::Grid grid)

The main loop for the CommandUI.

Parameters
gridA Grid to use

◆ swapTile()

void CommandUI::swapTile ( const std::int64_t  tile,
Grid15::Grid grid 
)
private

Swaps a tile.

Parameters
tileThe tile to swap
gridThe Grid to use

Member Data Documentation

◆ autoExit

bool CommandUI::autoExit {false}
private

Exit the game on win automatically.

◆ autoGrid

bool CommandUI::autoGrid {true}
private

Autoprint the grid.

◆ autoSave

bool CommandUI::autoSave {ProgramStuff::AUTOSAVE_ON_SLIDE_DEFAULT}
private

Autosave to last savefile.

◆ commandMap

const std::unordered_map< std::string, CommandUI::command > CommandUI::commandMap
staticprivate
Initial value:

A map from std::string to CommandUI::command for input parsing.

◆ defaultSaveFile

std::string CommandUI::defaultSaveFile {""}
private

The savefile to use for autoSaving, found during CommandUI::saveGame or CommandUI::loadGame.

◆ easySlide

bool CommandUI::easySlide {true}
private

Slide a tile without having to type "slide" first.

◆ wantsToExit

bool CommandUI::wantsToExit {false}
private

Whether the user wants to exit or not; used internally to exit CommandUI::start.


The documentation for this class was generated from the following files: