// hmm does it look thread-safe? // NO :( void GameGrid::addCell(int x, int y, Team team) { if(isAlive(x, y)) return; mutex->lock(); gridPoints[x][y] = team; gridCells.append(GameCell(x, y, team)); mutex->unlock(); }
GameGrid::GameGrid(int w, int h) { drive_tex.loadFromFile("drive.png"); drive.setTexture(drive_tex); border_size = 1.0f; bgColor = { 0,0,0 }; borderColor = { 100, 0 , 0 }; numCells = { w, h }; selected = sf::Vector2i{ -1, -1 }; cellData.resize(w*h); for (auto& c : cellData) { c = GameCell(); } RebuildVerts(); }
void GameBoard::init(CellStatus s, bool genseed) { cells_.clear(); qDeleteAll(ships_); ships_.clear(); for (int i = 0; i < 100; ++i) { cells_.append(GameCell(s)); if (genseed) cells_[i].seed = genSeed(32); } ships_.append(new GameShip(5, QString(), this)); ships_.append(new GameShip(4, QString(), this)); ships_.append(new GameShip(3, QString(), this)); ships_.append(new GameShip(2, QString(), this)); ships_.append(new GameShip(2, QString(), this)); ships_.append(new GameShip(1, QString(), this)); ships_.append(new GameShip(1, QString(), this)); }