コード例 #1
0
ファイル: Game.cpp プロジェクト: Commnets/QGAMES
// ---
void DragonWindGame::initialize ()
{
	QGAMES::ArcadeGame::initialize ();

	// Sets the icon of the game...
	mainScreen () -> setIcon (formBuilder () -> form (__DRAGONWINDICON__));

	// Add to the world its different world...
	// Initially none of them is active!
	addWorld (__DRAGONSELECTIONWORLD);
	addWorld (__DRAGONTRAININGWORLD);

	// Add to the game its different states...
	addState (new DragonWindPauseState (this), std::string (__DRAGONSTATEPAUSENAME));
	addState (new DragonWindInitialState (this), std::string (__DRAGONSTATEINITIALNAME));
	addState (new DragonWindIntroductionState (this), std::string (__DRAGONSTATEINTRODUCTIONNAME));
	addState (new DragonWindSelectionState (this), std::string (__DRAGONSTATESELECTONNAME));
	addState (new DragonWindInstructionsState (this), std::string (__DRAGONSTATEINSTRUCTIONSNAME));
	addState (new DragonWindTrainingState (this), std::string (__DRAGONSTATETRAININGNAME));
	addState (new DragonWindCountingDownState (this), std::string (__DRAGONSTATECOUNTDOWNNAME));
	addState (new DragonWindPlayingState (this), std::string (__DRAGONSTATEPLAYINGNAME));
	addState (new DragonWindEndState (this), std::string (__DRAGONSTATEENDNAME));
	addState (new DragonWindWinState (this), std::string (__DRAGONSTATEWINNAME));

	// Add to the game its different artists
	// Their visibility will depend on the world and scene the main players are in
	addArtist (_DRAGONNINJAARTIST); // The main character of the game...
	addArtist (_DRAGONNINJAARTISTB); 
	// The other main character of the game...this last one is only used during presentations!

	// The initial state...
	setState (std::string (__DRAGONSTATEINTRODUCTIONNAME));
}
コード例 #2
0
ファイル: TabletServer.cpp プロジェクト: dtbinh/dviz
void TabletServer::dispatch(QTcpSocket *socket, const QStringList &path, const QStringMap &query)
{
    QString pathStr = path.join("/");
    //qDebug() << "TabletServer::dispatch(): path: "<<path;

    if(pathStr.startsWith("data/")   ||
            pathStr.startsWith(":/data/") ||
            pathStr.startsWith("www/")    ||
            pathStr.startsWith(":/data/www/"))
    {
        serveFile(socket,pathStr);
    }
    else if(pathStr.startsWith("favicon.ico"))
    {
        serveFile(socket,":/data/http/favicon.ico");
    }
    else
    {
        mainScreen(socket,path,query);
    }

// 	else
// 	{
// 		Http_Send_404(socket)
// 			<< "<h1>Oops!</h1>\n"
// 			<< "Hey, my bad! I can't find \"<code>"<<toPathString(path,query)<<"</code>\"! Sorry!";
// 	}

}
コード例 #3
0
ファイル: SampleApp.c プロジェクト: henio180/PracaMagisterska
void mainControler(){
	while(1){
		switch(screenNR){
		case 1:
			mainScreen();
			break;
		case 2:
			smartMirror();
			break;
		}
	}
}
コード例 #4
0
void StaffList::mainScreen() {
	//readFile(input_text_file, usth_staff_list, stu_list_size);
	//StaffList l("USTH_staff_list.txt");
	for(;;) {
		cout << endl << endl;
		cout << "USTHStaffManager v7.0" << endl;
		cout << "1. Search." << endl;
		cout << "2. Change staff member info." << endl;
	  cout << "3. Remove staff member." << endl;
	  cout << "4. Add a staff member." << endl;
	  cout << "0. Back." << endl;
	  
	  cout << "What do you want to do, choose one option: ";
	  
	  // Verify a command if it is integer and belong to {0..4}
	  int command;  
		while (true) {
			cin >> command;
			if (cin && (command < 5) && (command > -1)) break;
			cout << "Invalid command!" << endl;
			cin.clear();
			cin.ignore(256,'\n');
		} 
		//////////////////////////////////////////////////////////
		
	  switch (command) {
	  	case 1: mainSearch();
	  					break;
	  					//mainScreen();
	  	case 2: mainChangeStaffInfo();
	  					//mainScreen();
	  					break;
	  	case 3: mainRemoveStaff();
	  					//mainScreen();
	  					break;
	  	case 4: mainAddStaff();
	  					//mainScreen(); 					
	  					break;
	  	case 0: return;
	  	default: 
	  		cout << "Invalid command!" << endl;
	  		mainScreen();
	  		
	  }
	}
}
コード例 #5
0
void LecturerList::mainScreen() {
	//readFile(input_text_file, usth_lecturer_list, stu_list_size);
	//LecturerList l("USTH_lecturer_list.txt");
	for(;;) {
		cout << endl << endl;
		cout << "USTHLecturerManager v6.0" << endl;
		cout << "1. Search." << endl;
		cout << "2. Change lecturer info." << endl;
	  cout << "3. Remove lecturer." << endl;
	  cout << "4. Add a lecturer." << endl;
	  cout << "0. Back." << endl;
	  
	  cout << "Enter a number: ";
	  
	  // Verify a command if it is integer and belong to {0..4}
	  int command;  
		while (true) {
			cin >> command;
			if (cin && (command < 5) && (command > -1)) break;
			cout << "Invalid command!" << endl;
			cin.clear();
			cin.ignore(256,'\n');
		} 
		//////////////////////////////////////////////////////////
		
	  switch (command) {
	  	case 1: mainSearch();
	  					break;
	  					//mainScreen();
	  	case 2: mainChangeLecturerInfo();
	  					//mainScreen();
	  					break;
	  	case 3: mainRemoveLecturer();
	  					//mainScreen();
	  					break;
	  	case 4: mainAddLecturer();
	  					//mainScreen(); 					
	  					break;
	  	case 0: return;
	  	default: 
	  		cout << "Invalid command!" << endl;
	  		mainScreen();
	  		
	  }
	}
}
コード例 #6
0
ファイル: Game.cpp プロジェクト: Commnets/QGAMES
// ---
void PacmanGame::updatePositions ()
{
	// If the game has been stopped for a while,
	// Not actualization is done...
	// Normally the game is stopped when a monster has been eaten!
	// It has to be done before any other thing happens...
	if (_gameStopped)
	{
		if (++_counterStopped >= (1 * framesPerSecond ()))
		{
			_gameStopped = false;
			_counterStopped = 0;
		}

		return;
	}

	// Now first do what the parents says to do...
	QGAMES::ArcadeGame::updatePositions ();

	QGAMES::Screen* scr = mainScreen ();
	if (scr -> fix () != NULL)
		scr -> setFix (NULL); 
	// When the status is not playing, there is nothing to follow...
	// Any case, this is just in case...

	// When the game is not going on...
	// Nothing of the rest makes sense...
	if (_currentGameState -> type () != __GAMESTATEPLAYING)
		return;

	// Otherwhise....
	// Has the fruit to be shown?
	++_counterToFruit;
	if (_counterToFruit == (_secondForFruit * framesPerSecond ()))
	{
		// The counter is not set to 0 again because only one fruit is allowed per round...
		// The fruit shown depends on the level...
		((WorldPacman*) _activeWorld) -> 
			showFruit ((int) General::_e._variables [_level][__VARBONUSSYMBOL]);
		_fruitShown = true;
	}

	// If the fruit is on the screen
	// The counter is still counting to remove it...
	// The fruit is 5 seconds on the screen always (independent on the level)
	if (_fruitShown)
	{
		if (_counterToFruit == ((_secondForFruit + 5) * framesPerSecond ()))
		{
			// The counter is not set to 0 again because only one fruit is allowed per round...
			((WorldPacman*) _activeWorld) -> showFruit (__FRUITFRAMEEMPTY);
			_fruitShown = false;
			_counterToFruit = 0;
		}
	}

	// Look after the frightening status...
	// The number of seconds the frightening ststus lasts depends on the level...
	if (_mode == PacmanGame::_FRIGHTENING)
	{
		_counterFrigthening++;
		if (_counterFrigthening >= 
				((int) (General::_e._variables [_level][__VARFRIGHTTIME] * framesPerSecond ())))
		{
			setMode (PacmanGame::_SEMIFRIGHTENING);
			_counterFrigthening = 0;
		}
	}

	// Look after the semifrightening status...
	// The game is turning back to the normal situation...
	// The number of seconds in the new flashing situation also depends on the level...
	if (_mode == PacmanGame::_SEMIFRIGHTENING)
	{
		_counterFrigthening++;
		if (_counterFrigthening >= 
				((int) (General::_e._variables [_level][__VARNUMBERFLASHES] * framesPerSecond ())))
		{
			setMode (PacmanGame::_NORMAL);
			_counterFrigthening = 0;
		}
	}
}
コード例 #7
0
ファイル: Game.cpp プロジェクト: Commnets/QGAMES
// ---
void PacmanGame::initialize ()
{
	QGAMES::ArcadeGame::initialize ();

	// Sets the icon to the window...
	mainScreen () -> setIcon (formBuilder () -> form (__PACMANICOFORM));

	// Clean up everything...
	_artists.clear ();
	_gameStates.clear ();
	_worlds.clear ();

	// The main artist of the game, if they have not been created and inserted before...
	// The command entity creates the entities and observe them...
	_pacman = (Pacman*) entity (__ENTITYPACMAN);
	_artists.insert (QGAMES::Entities::value_type (__ENTITYPACMAN, _pacman));

	// The monsters...
	// Blinky
	_blinky = (Blinky*) entity (__ENTITYBLINKY);
	_blinky -> setMyTarget (_pacman); // Target?
	_monsters.push_back (_blinky);
	_artists.insert (QGAMES::Entities::value_type (__ENTITYBLINKY, _blinky));

	// Pinky
	_pinky = (Pinky*) entity (__ENTITYPINKY);
	_pinky -> setMyTarget (_pacman);
	_monsters.push_back (_pinky);
	_artists.insert (QGAMES::Entities::value_type (__ENTITYPINKY, _pinky));

	// Inky
	_inky = (Inky*) entity (__ENTITYINKY);
	_inky -> setMyTarget (_pacman);
	_monsters.push_back (_inky);
	_artists.insert (QGAMES::Entities::value_type (__ENTITYINKY, _inky));

	// Clyde
	_clyde = (Clyde*) entity (__ENTITYCLYDE);
	_clyde -> setMyTarget (_pacman);
	_monsters.push_back (_clyde);
	_artists.insert (QGAMES::Entities::value_type (__ENTITYCLYDE, _clyde));

	// Assign the collegues...
	_blinky -> setCollegues (_monsters);
	_pinky -> setCollegues (_monsters);
	_inky -> setCollegues (_monsters);
	_clyde -> setCollegues (_monsters);

	// Load the states...
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATELOADINGNAME), new PacmanGameStateLoading (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEINITIALNAME), new GameStateInitial (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEPRELUDENAME), new GameStatePrelude (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEPRELUDESHORTNAME), new GameStatePreludeShort (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEPLAYINGNAME), new GameStatePlaying (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEMAZECLEANNAME), new GameStateMazeClean (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEPACMANDIESNAME), new GameStatePacmanDies (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEROUNDENDNAME), new GameStateRoundEnd (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEENDNAME), new GameStateEnd (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATEINTROLETTERSNAME), new GameStateIntroLetters (this)));
	_gameStates.insert (QGAMES::GameStates::value_type 
		(std::string (__GAMESTATESEESCORESNAME), new GameStateSeeScore (this)));

	// When the game starts, the list of the most famous player is loaded
	// The list is something really simple to read
	_scores.clear ();
	std::ifstream scoreFile ("scores.txt");
	if (scoreFile)
	{
		std::string usr, score;
		while (!scoreFile.eof ())
		{
			scoreFile >> score >> usr;
			_scores.insert (std::pair <int, std::string> (atoi (score.c_str ()), usr));
		}

		scoreFile.close ();
	}

	// The initial state...
	setState (std::string (__GAMESTATELOADINGNAME));

	// Load the world...
	_worlds.insert (QGAMES::Worlds::value_type (__WORLDPACMAN,
		_worldBuilder -> world (__WORLDPACMAN)));

	// Sets the first level...
	setLevel (0);
}
コード例 #8
0
ファイル: Game.cpp プロジェクト: Commnets/QGAMES
// ---
QGAMES::FormBuilder* PacmanGame::createFormBuilder ()
{ 
	return (new SDL2DSpriteBuilder (std::string (__FORMSFILE__), 
		(SDLScreen*) mainScreen ())); 
}
コード例 #9
0
ファイル: main.C プロジェクト: Methuselas/btbuilder
int main(int argc, char *argv[])
{
 char opt;
 static struct option long_options[] =
 {
  {"item", 0, 0, 'i'},
  {"monster", 0, 0, 'm'},
  {"spell", 0, 0, 's'},
  {"map", 1, 0, 'p'},
  {"editmap", 1, 0, 'e'},
  {"ascii", 0, 0, 'a'},
  {"xml", 1, 0, 'x'},
  {"multiplier", 1, 0, 'u'},
  {0, 0, 0, 0}
 };

 bool utf8 = true;
 int mode = MODE_STANDARD;
 char *mapFile = NULL;
 char *xmlFile = NULL;
 int multiplier = 0;
 std::string libDir(TOSTRING(BTBUILDERDIR));
 while ((opt = getopt_long(argc,argv,"imsap:x:e:l:u:", long_options, NULL)) != EOF)
 {
  switch (opt)
  {
   case 'i':
    mode = MODE_ITEM;
    break;
   case 'm':
    mode = MODE_MONSTER;
    break;
   case 's':
    mode = MODE_SPELL;
    break;
   case 'p':
    mode = MODE_MAP;
    if (optarg)
    {
     mapFile = strdup(optarg);
    }
    break;
   case 'e':
    mode = MODE_EDITMAP;
    if (optarg)
    {
     mapFile = strdup(optarg);
    }
    break;
   case 'l':
    if (optarg)
    {
     libDir = optarg;
    }
    break;
   case 'a':
    utf8 = false;
    break;
   case 'x':
    if (optarg)
    {
     xmlFile = strdup(optarg);
    }
    break;
   case 'u':
    if (optarg)
    {
     multiplier = atol(optarg);
    }
    break;
   default:
    break;
  }
 }

 BTMainScreen mainScreen(argv[0], libDir, multiplier);
 if (optind >= argc)
 {
  if (mode != MODE_STANDARD)
   return 0;
  mainScreen.run();
  return 0;
 }
 else if (mode == MODE_STANDARD)
 {
  std::string moduleFile("module/");
  moduleFile += argv[optind];
  moduleFile += ".xml";
  mainScreen.runModule(moduleFile);
  return 0;
 }
 else if (mode == MODE_EDITMAP)
 {
  std::string moduleFile("module/");
  moduleFile += argv[optind];
  moduleFile += ".xml";
  mainScreen.editModule(moduleFile, mapFile);
  return 0;
 }
 std::string moduleFile("module/");
 moduleFile += argv[optind];
 moduleFile += ".xml";
 BTModule module;
 mainScreen.loadModule(moduleFile, module);
 BTGame game(&module);
 BTFactory<BTMonster> &monList(game.getMonsterList());
 BTFactory<BTItem> &itmList(game.getItemList());
 BTFactory<BTSpell, BTSpell1> &splList(game.getSpellList());
 int i;
 if (mode == MODE_MONSTER)
 {
  if (xmlFile)
  {
   monList.save(xmlFile);
  }
  else
  {
   for (i = 0; i < monList.size(); i++)
   {
    BTMonster &mon(monList[i]);
    printf("Name: %s\n", mon.getName().c_str());
    printf("Illusion: %s   Base armor class: %d\n",
      (mon.isIllusion() ? "Yes" : "No"), (mon.getAc() - 10) * -1);
    printf("Level: %d   Thaumaturgical resistance: %d\n", mon.getLevel(),
      mon.getMagicResistance());
    printf("Starting distance (*10'): %d   Moves per round: %d\n",
      mon.getStartDistance(), mon.getMove());
    printf("Hit points: %dd%d   Combat options: ", mon.getHp().getNumber(),
      mon.getHp().getType());
    IShort combatAction = mon.getCombatAction(0);
    for (int a = 1; a < 4; ++a)
     if (combatAction != mon.getCombatAction(a))
      combatAction = -1;
    if (-1 == combatAction)
     printf("Multiple\n");
    else
     printf("%s\n", combatActions[combatAction]);
    printf("Rate of attacks: %d   Damage dice: %dd%d\n",
      mon.getRateAttacks(), mon.getMeleeDamage().getNumber(),
      mon.getMeleeDamage().getType());
    printf("Extra damage: %s\n", extraDamage[mon.getMeleeExtra()]);
    printf("Attack message: <monster> %s <opponent>\n", mon.getMeleeMessage());
    printf("Extra ranged attack information -\n");
    printf("   Type: %s", rangedTypes[mon.getRangedType()]);
    switch (mon.getRangedType())
    {
     case BTRANGEDTYPE_MAGIC:
      printf(": %s", splList[mon.getRangedSpell()].getCode());
     case BTRANGEDTYPE_FOE:
     case BTRANGEDTYPE_GROUP:
      printf("   Message: <monster> %s <opponent>\n", mon.getRangedMessage());
      printf("   Damage: %dd%d   Extra damage: %s   Range: %d",
        mon.getRangedDamage().getNumber(),  mon.getRangedDamage().getType(),
        extraDamage[mon.getRangedExtra()], mon.getRange());
      break;
     default:
      break;
    }
    printf("\n");
    printf("Upper limit appearing: %d  Gold: %dd%d   Picture number: %d\n",
      mon.getMaxAppearing(), mon.getGold().getNumber(),
      mon.getGold().getType(), mon.getPicture());
    printf("\n");
   }
  }
 }
 else if (mode == MODE_SPELL)
 {
  if (xmlFile)
  {
   splList.save(xmlFile);
  }
  else
  {
   BTSpellListCompare compare;
   BTSortedFactory<BTSpell, BTSpell1> sortedSplList(&splList, &compare);
   IShort caster = -1;
   IShort level = -1;
   for (i = 0; i < sortedSplList.size(); i++)
   {
    BTSpell &mon(sortedSplList[i]);
    if ((caster != mon.getCaster()) || (level != mon.getLevel()))
    {
     if (caster != mon.getCaster())
     {
      caster = mon.getCaster();
      BTJobList& jobList = BTGame::getGame()->getJobList();
      int j;
      for (j = 0; j < jobList.size(); ++j)
      {
       if (jobList[j]->getSkill(caster) != NULL)
        break;
      }
      printf("Class:  %s\n", ((j < jobList.size()) ? BTGame::getGame()->getJobList()[j]->name : "Unknown"));
     }
     level = mon.getLevel();
     printf("Level: %d\n\n", level);
    }
    printf("Name: %s\n", mon.getName().c_str());
    printf("Code: %s\n", mon.getCode());
    printf("Points: %d   Range: %d   Extra range: %s\n", mon.getSp(),
      mon.getRange() * 10, effectiveRanges[mon.getEffectiveRange()]);
    printf("Target: %s\n", areaEffect[mon.getArea()]);
    printf("Effect: %s <target>\n", mon.getEffect());
    printf("Duration: %s\n", durations[mon.getDuration()]);
    printf("%s", mon.describeManifest().data());
/*    printf("Type: %s", spellTypes[mon.getType()]);
    switch (mon.getType())
    {
     case BTSPELLTYPE_SUMMONILLUSION:
     case BTSPELLTYPE_SUMMONMONSTER:
      printf("   Name: %s", monList[mon.getExtra()].getName().c_str());
      break;
     case BTSPELLTYPE_ARMORBONUS:
     case BTSPELLTYPE_HITBONUS:
      printf("   Bonus: %d", mon.getExtra());
      break;
     case BTSPELLTYPE_PUSH:
      printf("   Distance: %d", mon.getExtra());
      break;
     case BTSPELLTYPE_REGENBARD:
      printf("   Amount: %d", mon.getExtra());
      break;
     default:
      break;
    }
    printf("\nDice: %dd%d   Duration: %s\n", mon.getDice().getNumber(),
      mon.getDice().getType(), durations[mon.getDuration()]);
*/    printf("\n");
   }
  }
 }
 else if (mode == MODE_ITEM)
 {
  if (xmlFile)
  {
   itmList.save(xmlFile);
  }
  else
  {
   for (i = 0; i < itmList.size(); i++)
   {
    BTItem &mon(itmList[i]);
    printf("Name: %s\n", mon.getName().c_str());
    printf("Type: %s\n", itemTypes[mon.getType()]);
    printf("Price: %d   User class: Multiple\n", mon.getPrice());
    printf("Armor bonus: %d   Hit bonus: %d\n", mon.getArmorPlus(),
      mon.getHitPlus());
    printf("Damage dice: %dd%d\n", mon.getDamage().getNumber(),
      mon.getDamage().getType());
    printf("Extra special damage: %s   Special damage likelihood: %d%%\n",
      extraDamage[mon.getXSpecial()], mon.getChanceXSpecial());
    if (BTTIMESUSABLE_UNLIMITED == mon.getTimesUsable())
     printf("Times useable: (unlimited)");
    else
     printf("Times useable: %d", mon.getTimesUsable());
    printf("   Spell cast: %s\n",
      ((mon.getSpellCast() == BTITEMCAST_NONE) ? "(none)" :
      splList[mon.getSpellCast()].getName().c_str()));
    printf("Cause: <member> %s <opponent>\n", mon.getCause());
    printf("Effect: %s <damage>\n", mon.getEffect());
    printf("\n");
   }
  }
 }
 else if (mode == MODE_MAP)
 {
  int x, y;
  IShort index;
  if (mapFile)
   game.loadMap(mapFile);
  BTMap &gameMap = *game.getMap();
  if (xmlFile)
  {
   XMLSerializer parser;
   parser.add("map", &gameMap);
   parser.write(xmlFile, true);
  }
  else
  {
   printf("Name: %s\n", gameMap.getName());
   printf("Type: %s   Level: %d\n", game.getPsuedo3DConfigList().getName(gameMap.getType()).c_str(), gameMap.getLevel());
   printf("Monster difficulty: %d   Chance of encounter: %d%%\n", gameMap.getMonsterLevel(), gameMap.getMonsterChance());
   printf("File: %s\n\n", gameMap.getFilename());
   for (y = 0; y < gameMap.getYSize(); y++)
   {
    printf(" ");
    for (x = 0; x < gameMap.getXSize(); x++)
    {
     index = 0;
     if ((y > 0) && (gameMap.getSquare(y - 1, x).getWall(BTDIRECTION_WEST) > 0))
     {
      index += 1 << BTDIRECTION_NORTH;
     }
     if ((x > 0) && (gameMap.getSquare(y, x - 1).getWall(BTDIRECTION_NORTH) > 0))
     {
      index += 1 << BTDIRECTION_WEST;
     }
     if (gameMap.getSquare(y, x).getWall(BTDIRECTION_NORTH) > 0)
     {
      index += 1 << BTDIRECTION_EAST;
     }
     if (gameMap.getSquare(y, x).getWall(BTDIRECTION_WEST) > 0)
     {
      index += 1 << BTDIRECTION_SOUTH;
     }
     if (utf8)
      printf("%s%s", cornerWallsUTF8[index], upperWallsUTF8[gameMap.getSquare(y, x).getWall(BTDIRECTION_NORTH)]);
     else
      printf("%c%c", cornerWalls[index], upperWalls[gameMap.getSquare(y, x).getWall(BTDIRECTION_NORTH)]);
    }
    index = 0;
    if ((y > 0) && (gameMap.getSquare(y - 1, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST) > 0))
    {
     index += 1 << BTDIRECTION_NORTH;
    }
    if (gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_NORTH) > 0)
    {
     index += 1 << BTDIRECTION_WEST;
    }
    if (gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST) > 0)
    {
     index += 1 << BTDIRECTION_SOUTH;
    }
    if (utf8)
     printf("%s \n", cornerWallsUTF8[index]);
    else
     printf("%c \n", cornerWalls[index]);
    printf(" ");
    for (x = 0; x < gameMap.getXSize(); x++)
    {
     index = gameMap.getSquare(y, x).getSpecial();
     if (utf8)
      printf("%s%c", sideWallsUTF8[gameMap.getSquare(y, x).getWall(BTDIRECTION_WEST)],
        (index < 0 ) ? ' ' : ((index < 26) ? 'A' + index : 'a' - 26 + index));
     else
      printf("%c%c", sideWalls[gameMap.getSquare(y, x).getWall(BTDIRECTION_WEST)],
        (index < 0 ) ? ' ' : ((index < 26) ? 'A' + index : 'a' - 26 + index));
    }
    if (utf8)
     printf("%s \n", sideWallsUTF8[gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST)]);
    else
     printf("%c \n", sideWalls[gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST)]);
   }
   printf(" ");
   for (x = 0; x < gameMap.getXSize(); x++)
   {
    index = 0;
    if (gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_WEST) > 0)
    {
     index += 1 << BTDIRECTION_NORTH;
    }
    if ((x > 0) && (gameMap.getSquare(gameMap.getYSize() - 1, x - 1).getWall(BTDIRECTION_SOUTH) > 0))
    {
     index += 1 << BTDIRECTION_WEST;
    }
    if (gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_SOUTH) > 0)
    {
     index += 1 << BTDIRECTION_EAST;
    }
    if (utf8)
     printf("%s%s", cornerWallsUTF8[index], upperWallsUTF8[gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_SOUTH)]);
    else
     printf("%c%c", cornerWalls[index], upperWalls[gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_SOUTH)]);
   }
   index = 0;
   if (gameMap.getSquare(gameMap.getYSize() - 1, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST) > 0)
   {
    index += 1 << BTDIRECTION_NORTH;
   }
   if (gameMap.getSquare(gameMap.getYSize() - 1, gameMap.getXSize() - 1).getWall(BTDIRECTION_SOUTH) > 0)
   {
    index += 1 << BTDIRECTION_WEST;
   }
   if (utf8)
    printf("%s \n", cornerWallsUTF8[index]);
   else
    printf("%c \n", cornerWalls[index]);
   printf("\nDefined special squares:\n\n\n");
   for (int i = 0; i < 30; i++)
   {
    const BTSpecial *sp = gameMap.getSpecial(i);
    if (NULL != sp)
    {
     printf("%c. ", (i < 26) ? 'A' + i : 'a' - 26 + i);
     sp->print(stdout);
     printf("\n");
    }
   }
  }
 }
 PHYSFS_deinit();
 return 0;
}
コード例 #10
0
ファイル: nsIconChannel.cpp プロジェクト: lofter2011/Icefox
nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBlocking)
{
  nsXPIDLCString contentType;
  nsCAutoString filePath;
  nsCAutoString fileExtension;
  nsCOMPtr<nsIFile> localFile; // File we want an icon for
  PRUint32 desiredImageSize;
  nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, contentType, fileExtension);
  NS_ENSURE_SUCCESS(rv, rv);

  PRUint32 iconSize = 16;
  if (desiredImageSize > 16)
    iconSize = 32;

  PRUint32 alphaBytesPerRow = (iconSize / 8);
  if (iconSize % 32 != 0)
    alphaBytesPerRow = ((iconSize / 32) + 1) * 4;
    
  PRBool fileExists = PR_FALSE;
  if (localFile)
  {
    localFile->GetNativePath(filePath);
    localFile->Exists(&fileExists);
  }
  
  // Get the native icon.
  // 1) If it is for an actual local file, BNodeInfo::GetTrackerIcon.
  // 2) If the local file does not exist, use the content type 
  //    and BMimeType::GetIcon
  BBitmap nativeIcon(BRect(0, 0, iconSize - 1, iconSize - 1), B_CMAP8);
  if (!nativeIcon.IsValid())
    return NS_ERROR_OUT_OF_MEMORY;

  PRBool gotBitmap = PR_FALSE;
  if (fileExists)
  {
    BNode localNode(filePath.get());
    // BeOS doesn't MIME type foreign files immediately - 
    // If there is no type attribute then we can force an identify
    if (localNode.ReadAttr("BEOS:TYPE", B_STRING_TYPE, 0, NULL, 0) != B_OK)
    	update_mime_info(filePath.get(), 0, 1, 1);

    BNodeInfo localNodeInfo(&localNode);
    if (iconSize == 16)
    {
      if (localNodeInfo.GetTrackerIcon(&nativeIcon, B_MINI_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
    else
    {
      if (localNodeInfo.GetTrackerIcon(&nativeIcon, B_LARGE_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
  }

  // If we haven't got a bitmap yet, use the content type
  if (!gotBitmap)    
  {
    // If no content type specified, use mozilla's mime service to guess a mime type
    if (contentType.IsEmpty())
    {
      nsCOMPtr<nsIMIMEService> mimeService (do_GetService("@mozilla.org/mime;1", &rv));
      if (NS_SUCCEEDED(rv))
        mimeService->GetTypeFromExtension(fileExtension, contentType);
      // If unrecognised extension - set to generic file
      if (contentType.IsEmpty())
        contentType = "application/octet-stream";
    }
    // Create BeOS-Native MIME type info - if unheard of, set to generic file
    BMimeType mimeType(contentType.get());
    if (!mimeType.IsInstalled())
    	mimeType.SetTo("application/octet-stream");
    if (iconSize == 16)
    {
      if (mimeType.GetIcon(&nativeIcon, B_MINI_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
    else
    {
      if (mimeType.GetIcon(&nativeIcon, B_LARGE_ICON) == B_OK)
        gotBitmap = PR_TRUE;
    }
  }
  
  if (!gotBitmap)
    return NS_ERROR_NOT_AVAILABLE;

  BScreen mainScreen(B_MAIN_SCREEN_ID);
  if (!mainScreen.IsValid())
    return NS_ERROR_NOT_AVAILABLE;

  // Got a bitmap and color space info - convert data to mozilla's icon format
  PRUint32 iconLength = 2 + iconSize * iconSize * 4;
  uint8 *buffer = new uint8[iconLength];
  if (!buffer)
    return NS_ERROR_OUT_OF_MEMORY;

  uint8* destByte = buffer;
  *(destByte++) = iconSize;
  *(destByte++) = iconSize;

  // RGB data
  uint8* sourceByte = (uint8*)nativeIcon.Bits();
  for(PRUint32 iconRow = 0; iconRow < iconSize; iconRow++)
  {
    sourceByte = (uint8*)nativeIcon.Bits() + nativeIcon.BytesPerRow() * iconRow;
    for(PRUint32 iconCol = 0; iconCol < iconSize; iconCol++)
    {
      if (*sourceByte != B_TRANSPARENT_MAGIC_CMAP8)
      {
        rgb_color colorVal = mainScreen.ColorForIndex(*sourceByte);
#ifdef IS_LITTLE_ENDIAN
        *(destByte++) = colorVal.blue;
        *(destByte++) = colorVal.green;
        *(destByte++) = colorVal.red;
        *(destByte++) = uint8(255);
#else
        *(destByte++) = uint8(255);
        *(destByte++) = colorVal.red;
        *(destByte++) = colorVal.green;
        *(destByte++) = colorVal.blue;
#endif
      }
      else
      {
        *destByte++ = 0;
        *destByte++ = 0;
        *destByte++ = 0;
        *destByte++ = 0;
      }
      // original code had a conditional here:
      // if (iconCol < iconSize - 1) 
      // Leaving this comment in case complications arise later
      sourceByte++;
    }
  }

  NS_ASSERTION(buffer + iconLength == destByte, "size miscalculation");
  
  // Now, create a pipe and stuff our data into it
  nsCOMPtr<nsIInputStream> inStream;
  nsCOMPtr<nsIOutputStream> outStream;
  rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(outStream),
                  iconLength, iconLength, nonBlocking);
  if (NS_SUCCEEDED(rv))
  {
    PRUint32 written;
    rv = outStream->Write((char*)buffer, iconLength, &written);
    if (NS_SUCCEEDED(rv))
      NS_ADDREF(*_retval = inStream);
  }
  delete [] buffer;
  
  return rv;
}