Skip to content

Commit

Permalink
add occupancy demo
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodCoder666 committed Dec 18, 2024
1 parent 3094606 commit c10772e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/mapWidget/mapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ void MapWidget::paintEvent(QPaintEvent* event) {
cellHeight = defaultSize / height,
paddingW = cellWidth * paddingFactor, paddingH = cellHeight * paddingFactor;

static const QColor bg(220, 220, 220);
static const QColor playerColors[] = {
QColor(255, 0, 0),
QColor(255, 112, 16),
QColor(0, 128, 0),
QColor(16, 49, 255)
};

static QPixmap
pixmap_city(":/images/img/city.png"),
pixmap_general(":/images/img/crown.png"),
Expand All @@ -36,14 +44,15 @@ void MapWidget::paintEvent(QPaintEvent* event) {
const QPixmap pixmaps[] = { pixmap_city, pixmap_general, pixmap_desert, pixmap_lookout,
pixmap_mountain, pixmap_observatory, pixmap_obstacle, pixmap_swamp };

QRandomGenerator* rand = QRandomGenerator::global();

painter.setPen(QPen(Qt::black, 1));
for(int i = 0; i < width; ++i) {
for(int j = 0; j < height; ++j) {
QRectF cell(i * cellWidth, j * cellHeight, cellWidth, cellHeight);
painter.fillRect(cell, QColor(220, 220, 220));
painter.fillRect(cell, rand->bounded(2) == 0 ? bg : playerColors[rand->bounded(4)]);
painter.drawRect(cell);

int k = QRandomGenerator::global()->bounded(15);
int k = rand->bounded(15);
if(k < 8) {
QRectF imgRect(i * cellWidth + paddingW, j * cellHeight + paddingH,
cellWidth - paddingW * 2, cellHeight - paddingH * 2);
Expand Down

0 comments on commit c10772e

Please sign in to comment.