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;
bool Save(void);
void SetNameOnCurrentLevel(const char *);
void AddNewLevelAtCurrentPosition(void);
+ static void GetSizeAndCorner(Level *, Point &, Point &);
private:
+ void CountBoxesAndSpots(int &, int &);
void ShiftLevel(int, int);
- void GetSizeAndCorner(Level *, Point &, Point &);
void ResizeGrid(void);
void Pause(int);
down = new QPushButton("v");
add = new QPushButton("+");
remove = new QPushButton("-");
+ play = new QPushButton(">");
editor = new EditorWidget(parent);
list->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
buttonBox->addWidget(down);
buttonBox->addWidget(add);
buttonBox->addWidget(remove);
+ buttonBox->addWidget(play);
listBox->addWidget(list);
listBox->addLayout(buttonBox);
connect(down, SIGNAL(clicked()), this, SLOT(MoveLevelDown()));
connect(add, SIGNAL(clicked()), this, SLOT(AddLevel()));
connect(remove, SIGNAL(clicked()), this, SLOT(DeleteLevel()));
+ connect(play, SIGNAL(clicked()), this, SLOT(PlayLevel()));
}
SetEditorLevel(currentRow);
}
+
+void EditorWindow::PlayLevel(void)
+{
+ emit SetupLevel(&(editor->levelStorage[editor->currentLevel]));
+}
+
#include <QtGui>
class EditorWidget;
+class Level;
class EditorWindow: public QWidget
{
EditorWindow(QWidget * parent = 0);
~EditorWindow();
+ signals:
+ void SetupLevel(Level *);
+
private slots:
void SetEditorLevel(int);
void SetNewName(QWidget *, QAbstractItemDelegate::EndEditHint);
void MoveLevelDown(void);
void AddLevel(void);
void DeleteLevel(void);
+ void PlayLevel(void);
private:
QListWidget * list;
- QPushButton * up, * down, * add, * remove;
+ QPushButton * up, * down, * add, * remove, * play;
EditorWidget * editor;
};
#include <string.h>
//#include <stdio.h> // for printf()
#include "boards.h"
+#include "editorwidget.h" // for Level
GameBoard::GameBoard(int boardNumber)
}
+GameBoard::GameBoard(Level * level)
+{
+ Point size, corner;
+
+ EditorWidget::GetSizeAndCorner(level, size, corner);
+
+ width = size.x;
+ height = size.y;
+ boardLength = width * height;
+ board = new char[boardLength];
+ initialBoard = new char[boardLength];
+ name = level->name;
+
+ int current = 0;
+
+ for(int y=0; y<size.y; y++)
+ {
+ for(int x=0; x<size.x; x++)
+ {
+ uint8_t tile = level->board[corner.x + x][corner.y + y];
+
+ if (tile & GTMan)
+ {
+ initialX = x;
+ initialY = y;
+ tile &= ~GTMan;
+ }
+
+ initialBoard[current++] = tile;
+ }
+ }
+
+ ResetGame();
+}
+
+
GameBoard::~GameBoard()
{
if (board)
int dx, dy, type;
};
+class Level;
+
class GameBoard
{
public:
GameBoard(int);//, int, int, int);
+ GameBoard(Level *);
~GameBoard();
protected:
}
+void GameWidget::HandlePlayGameFromEditor(Level * l)
+{
+// level++;
+ delete gameBoard;
+ gameBoard = new GameBoard(l);
+ ResizeGrid();
+ update();
+}
+
+
void GameWidget::ResizeGrid(void)
{
QSize s = size();
#include <QtGui>
class GameBoard;
+class Level;
class GameWidget: public QWidget
{
void UpdateScore(int);
void GameWasWon(void);
+ public slots:
+ void HandlePlayGameFromEditor(Level *);
+
public:
void CreateBackground(void);
void NextLevel(void);
// connect(gameBoard, SIGNAL(UpdateScore(int)), this, SLOT(OnUpdateScore(int)));
connect(gameWidget, SIGNAL(GameWasWon()), this, SLOT(WeHaveAWinner()));
+ // Connect editor to game widget...
+ connect(editorWindow, SIGNAL(SetupLevel(Level *)), gameWidget,
+ SLOT(HandlePlayGameFromEditor(Level *)));
+
+
QMenu * menu = menuBar()->addMenu(tr("&Game"));
menu->addAction(newGame);
menu->addSeparator();