Impl() : gstate(), gv(0), tree(0), paw(new PieceAppearanceWidget), sidebar(0) { QDir pdir = qboard::persistenceDir( persistanceClass ); QString fn = pdir.canonicalPath() + "/" + fileName; try { if( ! paw->s11nLoad(fn) ) { paw->setupDefaultTemplates(); } } catch(...) { paw->setupDefaultTemplates(); } gstate.board().loadPixmap(":/QBoard/images/SplashScreen.jpg"); }
void BonusManager::update(GameState& state) { static unsigned int step1 = 0; if (step1++ < steps_delay) { return; } step1 = 0; auto get_pos = [this] { return Vec2(position_picker(generator), position_picker(generator)); }; auto check_player = [&](const Vec2 & where) { bool hit = false; for (auto & player : state.players()) { hit = hit || player->pos == where; } return hit; }; auto& board = state.board(); if (target_checkpoints > checkpoints.size()) { auto pos = get_pos(); bool flag = true; while (flag){ while (board[pos].pBonus || check_player(pos)) { pos = get_pos(); } bool isInside = false; for (auto& checkpoint : checkpoints) { if (abs(checkpoint->cell.x - pos.x) < 2 && abs(checkpoint->cell.y - pos.y) < 2){ isInside = true; pos = get_pos(); break; } } if (!isInside){ flag = false; } } checkpoints.push_back(BonusPtr(new Checkpoint(board[pos]))); board[pos].pBonus = checkpoints.back().get(); } static unsigned int step2 = 0; if (step2++ < steps_delay) { return; } step2 = 0; if (max_bonuses > bonuses.size()) { auto pos = get_pos(); while (board[pos].pBonus || check_player(pos)) { pos = get_pos(); } Bonus * bonus = nullptr; switch (bonus_picker(generator)) { case 0: case 1: case 2: bonus = new Arrow(board[pos]); break; } bonuses.push_back(BonusPtr(bonus)); board[pos].pBonus = bonus; } }