painter.setBrush(Qt::transparent);
painter.setPen(Qt::darkGreen);
painter.drawEllipse((x * GRIDSIZE) + 4, (y * GRIDSIZE) + 4, GRIDSIZE - 8, GRIDSIZE - 8);
+
+ char s[256];
+ int boxes, spots;
+ CountBoxesAndSpots(boxes, spots);
+
+ if (boxes == spots)
+ sprintf(s, "Boxes = Spots");
+ else if (boxes < spots)
+ sprintf(s, "Need %i more box%s", spots - boxes, (spots - boxes == 1 ? "" : "es"));
+ else if (spots < boxes)
+ sprintf(s, "Need %i more spot%s", boxes - spots, (boxes - spots == 1 ? "" : "s"));
+
+ painter.setPen(Qt::blue);
+ painter.drawText(0, 0, clientArea.width(), clientArea.height(),
+ Qt::AlignRight | Qt::AlignBottom, QString(s));
}
}
else if (key == Qt::Key_Period)
{
- level.board[cursor.x][cursor.y] ^= GTBoxSpot;
+ if (!(level.board[cursor.x][cursor.y] & (GTWall | GTNull)))
+ level.board[cursor.x][cursor.y] ^= GTBoxSpot;
}
else if (key == Qt::Key_B)
{
- level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTBox);
- level.board[cursor.x][cursor.y] |= GTBox;
+ level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTNull);
+ level.board[cursor.x][cursor.y] ^= GTBox;
}
else if (key == Qt::Key_W)
{
- level.board[cursor.x][cursor.y] = GTWall;
+ // If it's not a wall, just stick one in; otherwise, toggle it off
+ if (level.board[cursor.x][cursor.y] != GTWall)
+ level.board[cursor.x][cursor.y] = GTWall;
+ else
+ level.board[cursor.x][cursor.y] = GTSpace;
}
else if (key == Qt::Key_Space)
{
- level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTBox);
+ level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTBox | GTNull);
level.board[cursor.x][cursor.y] |= GTSpace;
}
else if (key == Qt::Key_O)
}
else if (key == Qt::Key_V)
{
- level.board[cursor.x][cursor.y] = GTNull;
+ // If it's not a void, just stick one in; otherwise, toggle it off
+ if (level.board[cursor.x][cursor.y] != GTNull)
+ level.board[cursor.x][cursor.y] = GTNull;
+ else
+ level.board[cursor.x][cursor.y] = GTSpace;
}
else
return; // Only update screen if keypress was recognized
}
+void EditorWidget::CountBoxesAndSpots(int & boxes, int & spots)
+{
+ Level & level = levelStorage[currentLevel];
+ boxes = spots = 0;
+
+ for(int x=0; x<BOARDSIZE; x++)
+ {
+ for(int y=0; y<BOARDSIZE; y++)
+ {
+ if (level.board[x][y] & GTBox)
+ boxes++;
+
+ if (level.board[x][y] & GTBoxSpot)
+ spots++;
+ }
+ }
+}
+
+
// Note: Only one parameter can be non-zero if you want expected behavior!
void EditorWidget::ShiftLevel(int dx, int dy)
{
}
-void EditorWidget::GetSizeAndCorner(Level * level, Point & size, Point & corner)
+/*static*/ void EditorWidget::GetSizeAndCorner(Level * level, Point & size, Point & corner)
{
size.x = size.y = corner.x = corner.y = 0;
Point min, max;