Example #1
0
void BombField::determinateCells(int fieldLength, int fieldWidth, int bombCount)
{
	BombField::bombCount = bombCount;
	length = fieldLength;
	width = fieldWidth;
	test = new CCell *[length];
	for (int i = 0; i < length; i++)
		test[i] = new CCell[width];
	// determine coordinates of all cells
	int y = 65, x;
	for (int i = 0; i < length; i++)
	{
		x = 15;
		for (int j = 0; j < width; j++)
		{
			test[i][j].leftup.x = x;
			test[i][j].leftup.y = y;
			test[i][j].rightlow.x = x + 40;
			test[i][j].rightlow.y = y + 24;
			test[i][j].isOpened = false;
			test[i][j].isBomb = false;
			x += 33;
		}
		y += 24;
	}
	int i;

	srand((unsigned)time(NULL));
	for (i = 0; i < bombCount; i++)
	{
		setBomb();
	}
}
Example #2
0
void BombField::setBomb()
{
	int rndString = (double)rand() / (RAND_MAX + 1) * (length - 0)
		+ 0;

	int rndColumn = (double)rand() / (RAND_MAX + 1) * (width - 0)
		+ 0;

	if (test[rndString][rndColumn].isBomb == true)
	{
		setBomb();
		
	}else
	{
		test[rndString][rndColumn].isBomb = true;
	}
	
}
Example #3
0
 void PlayerCommand::execute() {
     if (command == MSG_MOVE) {
         move();
     } else if (command == MSG_IGNITE) {
         tileMap->explodeBomb();
     } else if (command == MSG_SETBOMB) {
         setBomb();
     } else if (command == MSG_EXTRA_BOMB) {
         if (arguments.empty()) {
             arguments.push_back("1");
         }
         
         int ammount;
         if (arguments.size() == 1 && StringUtils::tryParseInt(arguments[0], ammount)) {
             for (int n =  0; n < ammount; ++n) {
                 player->addItem(Item::EXTRA_BOMB);
             }
         } else {
             Log::get() << "Command \"" << OBJ_PLAYER << "." << MSG_EXTRA_BOMB << "(int) requires one optional integer argument." << LogLevel::warning;
         }
     } else if (command == MSG_INCREASE_RANGE) {
         player->addItem(Item::INCREASE_RANGE);
     } else if (command == MSG_IVINCIBLE) {
         if (arguments.size() == 1 && (arguments[0] == BOOL_TRUE || arguments[0] == BOOL_FALSE)) {
             player->setInvincibility(BOOL_TRUE == arguments[0]);
         } else {
             Log::get() << "Command \"" << OBJ_PLAYER << "." << MSG_IVINCIBLE << "(bool) requires one boolean argument." << LogLevel::error;
         }
     } else if (command == MSG_REMOTE) {
         if (arguments.size() == 1 && (arguments[0] == BOOL_TRUE || arguments[0] == BOOL_FALSE)) {
             player->setRemote(BOOL_TRUE == arguments[0]);
         } else {
             Log::get() << "Command \"" << OBJ_PLAYER << "." << MSG_REMOTE << "(bool) requires one boolean argument." << LogLevel::error;
         }
     } else {
         Log::get() << "Invalid command \"" << OBJ_PLAYER << "." << command << "()\"." << LogLevel::error;
     }
     
     _finished = true;
 }
void Bomb::init() {
    setBomb();
}