Exemplo n.º 1
0
QRegion TCacheResource::download(TTile &tile)
{
	if (!checkTile(tile))
		return QRegion();

	return download(TPoint(tile.m_pos.x, tile.m_pos.y), tile.getRaster());
}
Exemplo n.º 2
0
bool TCacheResource::downloadAll(TTile &tile)
{
	if (!checkTile(tile))
		return false;

	return downloadAll(TPoint(tile.m_pos.x, tile.m_pos.y), tile.getRaster());
}
Exemplo n.º 3
0
void Explosion::create(int _id) {
	if(id[_id] == -1) return;

	Explosion *newExplosion = nullptr;

	checkTile(ptr, id[_id], LayerType::LAYER_EXPLOSIONS, &Explosion::explosion);

	if(checkTile(ptr, id[_id], LayerType::LAYER_STONES, &Explosion::stone) || checkTile(ptr, id[_id], LayerType::LAYER_BOMBS, &Explosion::bomb))
		newExplosion = new Explosion(ptr, id[_id], delay + Constants::Explosion::DELAY, position[_id], explosionLength - 1, Directions::none);

	else if(!checkTile(ptr, id[_id], LayerType::LAYER_BLOCKS, &Explosion::block))
		newExplosion = new Explosion(ptr, id[_id], delay + Constants::Explosion::DELAY, position[_id], explosionLength - 1, Directions(_id));

	if(newExplosion != nullptr)
		ptr->world[ id[_id] ].insert( std::make_pair(LayerType::LAYER_EXPLOSIONS, newExplosion) );
}
Exemplo n.º 4
0
bool TCacheResource::upload(const TTile &tile)
{
	if (!checkTile(tile))
		return false;

	return upload(TPoint(tile.m_pos.x, tile.m_pos.y), tile.getRaster());
}
void  Handle_2048::update(const float &t)
{
  for (auto &it : m_move_tiles)
    it->update(t, m_move);
  if (m_move > 0.f) {
      m_move -= t;
      if (m_move <= 0.f) {
          m_move = -0.1f;
          int z;
          for (z = 0; z < 16 && m_move_tiles[z]->value; ++z) {
              Tile *ti = m_move_tiles[z];
              Tile *tt = m_tiles[ti->y][ti->x];

              if (tt->value) {
                  std::string ts = m_score->getText();
                  int sc = Utility::getValueFromString<int>(Utility::replace<std::string>(ts, "score : ", ""));
                  m_score->setText("score : " + Utility::toString<int>(sc + tt->value + tt->value));
                  tt->m_unzoom = MAX_UNZOOM;
                }
              tt->setValue(ti->value + tt->value);
              tt->m_zoom = 1.f;
              if (tt->value == 2048 && !m_win) {
                  m_end = true;
                  m_win = true;
                  m_msg->setText("You win !\nPress C to continue\nPress R to restart");
                }
              ti->setValue(0);
            }
          if (z) {
              create_new_number();

              int exist(0);
              for (auto &it : m_tiles)
                for (auto it2 : it)
                  if (!it2->value)
                    ++exist;
              if (!exist) {
                  bool end_loop = false;

                  for (auto &it : m_tiles)
                    if (!end_loop)
                      for (auto it2 : it)
                        if (checkTile(it2)) {
                            end_loop = true;
                            break;
                          }
                  m_end = !end_loop;
                  if (m_end) {
                      m_msg->setText("Defeat !\nPress any key to restart");
                      m_win = false;
                    }
                }
            }
        }
    }
  for (auto &it : m_tiles)
    for (auto it2 : it)
      it2->update(t, m_move);
}
Exemplo n.º 6
0
/**
* This method generates a map of every tile in the grid. Any point in this map
* can be traced back to start_tile which can be used to create a path.
*/
void Level::breadthFirstSearch(const SDL_Point& start_tile)
{
    this->start_tile = start_tile;
    std::queue<SDL_Point> frontier;
    frontier.push(this->start_tile);

    // If a this method has been run before, the map of paths has to be cleared so that it doesn't interfere with the
    // new map of paths.
    if (!came_from.empty())
    {
        came_from.clear();
    }

    // Every path found by the algorithm starts here, so we set it to itself.
    came_from[std::make_pair(this->start_tile.x, this->start_tile.y)] = std::make_pair(this->start_tile.x, this->start_tile.y);

    SDL_Point current;
    while (!frontier.empty())
    {
        current = frontier.front();

        // Check every tile above, below and to the sides of the current tile.
        checkTile(frontier, current.x + 1, current.y, current.x, current.y);
        checkTile(frontier, current.x - 1, current.y, current.x, current.y);
        checkTile(frontier, current.x, current.y + 1, current.x, current.y);
        checkTile(frontier, current.x, current.y - 1, current.x, current.y);

        // Check every tile diagonally to the current tile, to allow for diagonal pathfinding.
        checkTile(frontier, current.x + 1, current.y - 1, current.x, current.y);
        checkTile(frontier, current.x + 1, current.y + 1, current.x, current.y);
        checkTile(frontier, current.x - 1, current.y - 1, current.x, current.y);
        checkTile(frontier, current.x - 1, current.y + 1, current.x, current.y);

        frontier.pop();
    }
}
Exemplo n.º 7
0
//! Returns true if the passed tile is compatible, and it can be downloaded
//! entirely.
bool TCacheResource::canDownloadAll(const TTile &tile) const
{
	return checkTile(tile) && contains(m_region, getTileRect(tile));
}
Exemplo n.º 8
0
//! Returns true if the passed tile is compatible with the complex, and some
//! part of it is downloadable.
bool TCacheResource::canDownloadSome(const TTile &tile) const
{
	return checkTile(tile) && m_region.intersects(toQRect(getTileRect(tile)));
}
Exemplo n.º 9
0
bool TCacheResource::canUpload(const TTile &tile) const
{
	int tileType;
	return checkTile(tile) && checkRasterType(tile.getRaster(), tileType);
}