void GameArena::setMap(MapClient *newMap) { clear(); map = newMap; width = map->getWidth(); height = map->getHeight(); maxNbPlayers = map->getMaxNbPlayers(); squaresItem = new QGraphicsSquareItem*[width * height]; for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { initCase(i,j); getCase(i,j)->setItem(pixmaps.getPixmap(map->getType(i,j))); if(map->getOption(i,j) != BlockMapProperty::none) { //add this option on the map. It won't be removed or changed during the game. QGraphicsSquareItem* optItem = new QGraphicsSquareItem(i * squareSize,j * squareSize,squareSize); optItem->setItem(pixmaps.getPixmap(map->getOption(i,j), map->getOptionDirection(i,j))); scene->addItem(optItem); optionsItems << optItem; } } } qint16 x,y; for(int i = 0; i < map->getNbPlayers(); i++) { map->getPlayerPosition(i,x,y); QPlayer *p = new QPlayer(i); playersItem.append(p); p->setPos(x-squareSize/2,y-squareSize/2,squareSize); scene->addItem(p); emit sigNewPlayerGraphic(i,*p->getPlayerPixmap()); } connect(map, SIGNAL(sigBlockChanged(int)), this, SLOT(blockChanged(int))); connect(map, SIGNAL(sigBlockChanged(int,int)), this, SLOT(blockChanged(int,int))); connect(map, SIGNAL(sigHeartbeatUpdated(qint32)), this, SLOT(slotHearbeatUpdated(qint32))); connect(map, SIGNAL(sigMovePlayer(int, int, int, int)), this, SLOT(movePlayer(int, int, int, int))); connect(map, SIGNAL(sigPlayerSickChanged(int, bool)), this, SLOT(slotPlayerSickChanged(int, bool))); connect(map, SIGNAL(sigKillPlayer(int)), this, SLOT(killPlayer(int))); connect(map, SIGNAL(sigAddBonus(Bonus::Bonus_t,qint16,qint16)), this, SLOT(slotAddBonus(Bonus::Bonus_t,qint16,qint16))); connect(map, SIGNAL(sigRemoveBonus(qint16,qint16)), this, SLOT(slotRemoveBonus(qint16,qint16))); connect(map, SIGNAL(sigAddBomb(int)), this, SLOT(slotAddBomb(int)), Qt::DirectConnection); connect(map, SIGNAL(sigMovedBomb(int)), this, SLOT(slotMovedBomb(int)), Qt::DirectConnection); connect(map, SIGNAL(sigFlyingBomb(int,qint32)), this, SLOT(slotFlyingBomb(int,qint32)), Qt::DirectConnection); connect(map, SIGNAL(sigRemoveBomb(int)), this, SLOT(slotRemoveBomb(int)), Qt::DirectConnection); connect(map, SIGNAL(sigRemoveBombRC(int)), this, SLOT(slotRemoveBombRC(int)), Qt::DirectConnection); connect(map, SIGNAL(sigAddFlame(int,qint16,qint16)), this, SLOT(slotAddFlame(int,qint16,qint16))); connect(map, SIGNAL(sigRemoveFlame(int)), this, SLOT(slotRemoveFlame(int))); createGraphics(); }
int main(){ freopen("input.txt", "r", stdin); Case = 0; while (2 == scanf("%d %d", &W, &H) && W && H) { Case++; initCase(); readCase(); solveCase(); sortResult(); printCase(); } return 0; }
void MapParser::parseAndInit(const std::string& cheminZone, unsigned int width, unsigned int height) { unsigned int nouvNumZone = Modeles::m_royaume.m_zones.size(); sf::Image grid; grid.loadFromFile(cheminZone + "/" + "grid.png"); unsigned x = width / 2; unsigned y = height / 2; unsigned nLine = grid.getSize().x / width; unsigned nColumn = grid.getSize().y / height; Zone* zone = new Zone(nLine, nColumn); for(unsigned j=0; j<nColumn; ++j) { for(unsigned i=0; i<nLine; ++i) { sf::Color color = grid.getPixel(x + i*width, y + j*height); sf::Uint32 colorCode = color.toInteger(); std::map<sf::Uint32, MapParser::CaseType>::const_iterator it = code.find(colorCode); if(it != code.end()) { CaseType caseType = it->second; initCase(zone, caseType, i, j); } else { //std::cout << "Couleur de portail (" << (int)color.r << ", " << (int)color.g << ", " << (int)color.b << ")" << std::endl; initCasePortail(zone, colorCode, i, j); } } } Modeles::m_royaume.ajouterZone(zone); Vues::m_zoneViews.push_back(ZoneView()); Vues::m_zoneViews.at(nouvNumZone).init(cheminZone); Vues::m_personnagesViewParZone.push_back(new PersonnagesView()); Vues::m_personnagesViewParZone.at(nouvNumZone)->init(zone); }
Common::Error MohawkEngine_CSTime::run() { MohawkEngine::run(); _console = new CSTimeConsole(this); _gfx = new CSTimeGraphics(this); _cursor = new DefaultCursorManager(this, ID_CURS); _interface = new CSTimeInterface(this); _view = new CSTimeView(this); _view->setupView(); _view->setModule(new CSTimeModule(this)); while (!shouldQuit()) { switch (_state) { case kCSTStateStartup: // We just jump straight to the case for now. _state = kCSTStateNewCase; break; case kCSTStateNewCase: initCase(); _state = kCSTStateNewScene; break; case kCSTStateNewScene: nextScene(); _state = kCSTStateNormal; break; case kCSTStateNormal: update(); break; } } return Common::kNoError; }