#include "interfaceconsole.h" #include "smlnode.h" #include "gamestate.h" #include "situation.h" #include "command.h" #include #include #include "smlrenderervt100.h" #include #include #include #include PluginInterface3( plugin_interface_console, console, InterfaceConsole, Interface, "Mike Buland", 1, 0 ); using namespace Bu; InterfaceConsole::InterfaceConsole() { } InterfaceConsole::~InterfaceConsole() { } void InterfaceConsole::run( Game *pGame ) { GameState gs( pGame, this ); gs.init(); int iStep = 0; while( gs.isRunning() ) { char buf[1024]; switch( gs.getCurSituation()->getInputType() ) { case Situation::inputCommand: sio << sio.nl << "command> " << sio.flush; fgets( buf, 1024, stdin ); gs.execCommand( buf ); break; case Situation::inputOption: sio << sio.nl; { const CommandSet::CommandList &cl = gs.getCurSituation()->getCommandSet().getCommandList(); int j = 1; for( CommandSet::CommandList::const_iterator i = cl.begin(); i; i++ ) { sio << " " << j << ") " << (*i)->getRoot() << sio.nl; j++; } sio << "Enter your selection: " << sio.flush; fgets( buf, 1024, stdin ); if( buf[0] < '1' || buf[0] > '9' ) j = -1; else j = strtol( buf, NULL, 10 ); if( j < 1 || j > cl.getSize() ) { sio << "Invalid selection, try again." << sio.nl; } else { gs.execOption( j-1 ); } } break; } } } void InterfaceConsole::display( const class SmlNode *pSml ) { SmlRendererVt100 rend; rend.render( sio, pSml ); }