Example #1
0
bool
menu( game_t ** game )
{
	options_t options;
	char str[MAX_COM_LEN];
	modeOption_t modeOption;

	clearError();

	modeOption = chooseMode();

	raiseErrorIf( errorCode() == NOERROR, errorCode(), true );

	switch( modeOption ){
		case MODE0:
		case MODE1:
		case MODE2:
			options = chooseOptions( (modus_t)modeOption );
			raiseErrorIf( errorCode() == NOERROR, errorCode(), true );
			*game = newGame( &options );
			return true;
		case READFROMFILE:
			drawText("Enter the name of the file:\n");
			*game = readGame( askString( str ) );
			return true;
		case QUIT:
		default:
			return false;
	}
}
Example #2
0
void _ELC_::Project :: loadIniConfig(_ELENA_::path_t path, bool root, bool requiered)
{
   ElcConfigFile config(true);
   _ELENA_::Path configPath;

   configPath.copySubPath(path);

   if (!config.load(path, getDefaultEncoding())) {
      raiseErrorIf(requiered, ELC_ERR_INVALID_PATH, (const char*)path);
      return;
   }

   loadGenericConfig(config, configPath.c_str(), root, requiered);
}
Example #3
0
void _ELC_::Project :: loadXMLConfig(_ELENA_::path_t path, bool root, bool requiered)
{
   ElcXmlConfigFile config;
   _ELENA_::Path configPath;

   configPath.copySubPath(path);

   if (!config.load(path, getDefaultEncoding())) {
      raiseErrorIf(requiered, ELC_ERR_INVALID_PATH, _ELENA_::IdentifierString(path));
      return;
   }

   loadGenericConfig(config, configPath.c_str(), root, requiered);
}
Example #4
0
static char *
askString( char * str )
{
	char c;
	static char error[MAX_ERR_LEN];
	static char buffer[MAX_COM_LEN];

	do{
		clearScreen();
		drawText( NULL );
		drawPanel( error );
		askCommand( buffer );
		raiseErrorIf( errorCode() == NOERROR, errorCode(), NULL );
		error[0] = 0;
		if( ( c = sscanf( buffer, " %s", str ) ) != 1 && buffer[0] != '\n' )
			sprintf( error, "Format error:\nMust be a string" );
	}while( c != 1 );
	return str;
}
Example #5
0
void _ELC_::Project :: loadGenericConfig(_ELENA_::_ConfigFile& config, _ELENA_::path_t configPath, bool root, bool requiered)
{
   // load template list
   if (root)
      loadCategory(config, _ELENA_::opTemplates, configPath);

   // load template
   _ELENA_::ident_t projectTemplate = config.getSetting(ELC_PROJECT_TEMPLATE);
   if (!_ELENA_::emptystr(projectTemplate)) {
      _ELENA_::ident_t templateFile = _settings.get(_ELENA_::opTemplates, projectTemplate, DEFAULT_STR);
      if (!_ELENA_::emptystr(templateFile)) {
         _ELENA_::Path templatePath(templateFile);

         loadConfig(templatePath.c_str(), false, false);
      }
      else raiseErrorIf(requiered, ELC_ERR_INVALID_TEMPLATE, projectTemplate);
   }

   loadConfig(config, configPath);
}
Example #6
0
static int
askInt( int a, int b )
{
	int sol;
	char c;
	static char error[MAX_ERR_LEN];
	static char buffer[MAX_COM_LEN];

	error[0] = 0;
	do{
		clearScreen();
		drawText( NULL );
		drawPanel( error );
		askCommand( buffer );
		raiseErrorIf( errorCode() == NOERROR, errorCode(), -1 );
		error[0] = 0;
		if ( ( c = sscanf( buffer, " %d %c ", &sol, &c ) ) != 1 && buffer[0] != '\n' )
			sprintf( error, "Format error:\nMust be an integer" );
	}while( c != 1 || !validateInt( a, sol, b+1, error ) );

	return sol;
}
Example #7
0
static options_t
chooseOptions( modus_t mode )
{
	options_t options;
	int h, w;

	options.mode = mode;
	if( options.mode == TIMEMODE ){
		drawText("Enter the time limit (in minutes):\n");
		options.initialSeconds = 60 * askInt( 1, MAX_MINUTES );
		raiseErrorIf( errorCode() == NOERROR, errorCode(), options );
	}

	drawText("Enter the dimensions of the board "
			"(rows and columns space separated):\n");
	ask2Int( MIN_TAB_DIM, &h, MAX_TAB_DIM, MIN_TAB_DIM, &w, MAX_TAB_DIM );
	raiseErrorIf( errorCode() == NOERROR, errorCode(), options );

	options.height = h;
	options.width = w;

	drawText("Enter the number of colors with which you wish to play:\n");
	options.numColors = askInt( MIN_COLORS, MAX_COLORS );
	raiseErrorIf( errorCode() == NOERROR, errorCode(), options );

	drawText("Enter the number of pieces that are initially on the board:\n");
	options.initialTokens = askInt(1, options.width * options.height );
	raiseErrorIf( errorCode() == NOERROR, errorCode(), options );

	drawText("Enter the number of pieces that make a line:\n");
	options.tokensPerLine = askInt( MIN_TOK_PER_LINE,
										min( options.width, options.height ) );
	raiseErrorIf( errorCode() == NOERROR, errorCode(), options );

	drawText("Enter the number of pieces that are added on each turn:\n");
	options.tokensPerTurn = askInt(1, options.width * options.height );
	raiseErrorIf( errorCode() == NOERROR, errorCode(), options );

	return options;
}