// JLH 03/03/2014 Created this file
//
+#include "boards.h"
+
+
+// Level storage...
+std::vector<Level> levelStorage;
+
+
//
// We use anonymous structs to create these, to keep things simple. :-)
//
#ifndef __BOARDS_H__
#define __BOARDS_H__
+#include <vector>
+#include <stdint.h>
+
// Okay, this is ugly but works and I can't think of any better way to handle
// this. So what we do when we pass the anonymous structs into a function is
// pass them as a (void *) and then cast them as type (Board *) in order to
unsigned char state[]; // Board data
};
+#define BOARDSIZE 128
+
+struct Point
+{
+ Point(int xx = 0, int yy = 0) { x = xx; y = yy; }
+ int x, y;
+};
+
+struct Level
+{
+ uint8_t board[BOARDSIZE][BOARDSIZE];
+ char name[41];
+ Point corner; // Corner dimensions on screen
+ Point cursor; // Cursor location
+};
+
#define NUMBER_OF_BOARDS 42
extern const void * boards[];
+extern std::vector<Level> levelStorage;
#endif // __BOARDS_H__
#include <QtGui>
#include <stdint.h>
-#include <vector>
-
-#define BOARDSIZE 128
-
-struct Point
-{
- Point(int xx = 0, int yy = 0) { x = xx; y = yy; }
- int x, y;
-};
-
-struct Level
-{
- uint8_t board[BOARDSIZE][BOARDSIZE];
- char name[41];
- Point corner; // Corner dimensions on screen
- Point cursor; // Cursor location
-// This stuff will go into the save file, but we don't need it here...
-// Point size; // Actual dimensions of the level
-// Point boardCorner; // Where on the gird the UL corner of the level is
-};
+#include "boards.h"
class EditorWidget: public QWidget
{
void Pause(int);
public:
- std::vector<Level> levelStorage;
uint32_t currentLevel;
private:
// editor->setFocus(); //DISNOWOK
// editor->Load();
- for(unsigned int i=0; i<editor->levelStorage.size(); i++)
+ for(unsigned int i=0; i<levelStorage.size(); i++)
{
- list->addItem(QString(editor->levelStorage[i].name));
+ list->addItem(QString(levelStorage[i].name));
QListWidgetItem * item = list->item(i);
item->setFlags(item->flags() | Qt::ItemIsEditable);
}
if (level == 0)
up->setDisabled(true);
- else if ((unsigned int)level == (editor->levelStorage.size() - 1))
+ else if ((unsigned int)level == (levelStorage.size() - 1))
down->setDisabled(true);
else
{
{
// Swap in the vector...
int n = editor->currentLevel;
- std::swap(editor->levelStorage[n], editor->levelStorage[n - 1]);
+ std::swap(levelStorage[n], levelStorage[n - 1]);
// Swap in the QListWidget too...
int currentRow = list->currentRow();
void EditorWindow::MoveLevelDown(void)
{
int n = editor->currentLevel;
- std::swap(editor->levelStorage[n], editor->levelStorage[n + 1]);
+ std::swap(levelStorage[n], levelStorage[n + 1]);
int currentRow = list->currentRow();
QListWidgetItem * currentItem = list->takeItem(currentRow);
void EditorWindow::DeleteLevel(void)
{
//printf("DeleteLevel: Erasing level from levelStorage...\n");
- editor->levelStorage.erase(editor->levelStorage.begin() + editor->currentLevel);
+ levelStorage.erase(levelStorage.begin() + editor->currentLevel);
//printf("DeleteLevel: Erasing level from list...\n");
int currentRow = list->currentRow();
void EditorWindow::PlayLevel(void)
{
- emit SetupLevel(&(editor->levelStorage[editor->currentLevel]));
+ emit SetupLevel(&(levelStorage[editor->currentLevel]));
}
#include "gamewidget.h"
#include <unistd.h> // for usleep()
+#include "boards.h"
#include "gameboard.h"
GameWidget::GameWidget(QWidget * parent/*= 0*/): QWidget(parent),
- level(1), gameBoard(new GameBoard(level)),
+// level(1), gameBoard(new GameBoard(level)),
+ level(1), gameBoard(new GameBoard(&(levelStorage[level - 1]))),
animating(false), boxMoving(false)
// score(new QLabel)
{
else if ((tileType == GTBox)
&& (!(boxMoving && (movingBoxPositionX == x) && (movingBoxPositionY == y))))
{
- painter.setBrush(QBrush(tile & GTBoxSpot ? Qt::green : Qt::red));
+ painter.setBrush(QBrush(tile & GTBoxSpot ? Qt::darkRed : Qt::red));
painter.drawRect(x * maxLength, y * maxLength, maxLength, maxLength);
}
else if ((tileType == GTSpace)
{
level++;
delete gameBoard;
- gameBoard = new GameBoard(level);
+// gameBoard = new GameBoard(level);
+ gameBoard = new GameBoard(&(levelStorage[level - 1]));
ResizeGrid();
update();
}
MainWin::MainWin()
{
+ // We create the EditorWindow 1st because the GameWidget will crash if there
+ // is no level data loaded...
+ editorWindow = new EditorWindow(this);
gameWidget = new GameWidget(this);
setCentralWidget(gameWidget);
gameWidget->setFocusPolicy(Qt::StrongFocus); // Without this, it gets no keys
setWindowTitle("Warehouse Man Deluxe");
setWindowIcon(QIcon(":/wmd-icon.png"));
-// editor = new QWindow(this);
- editorWindow = new EditorWindow(this);
-// editor->setCentralWidget(editorWidget);
-// editorWidget->setFocusPolicy(Qt::StrongFocus); // Without this, it gets no keys
editorWindow->show();
newGame = CreateAction(tr("&New"), tr("New Game"), tr("Start a new game of Warehouse Man Deluxe"), QIcon(), QKeySequence(tr("ctrl+n")));
-// connect(newGame, SIGNAL(triggered()), this, SLOT(OnNewGame()));
+ connect(newGame, SIGNAL(triggered()), this, SLOT(HandleNewGame()));
undoAction = CreateAction(tr("&Undo"), tr(""), tr(""), QIcon(), QKeySequence(tr("ctrl+z")));
connect(undoAction, SIGNAL(triggered()), this, SLOT(HandleUndo()));
}
+void MainWin::HandleNewGame(void)
+{
+// ResetGame();
+ gameWidget->level = 0;
+ gameWidget->NextLevel();
+}
+
+
void MainWin::AboutGame(void)
{
- QMessageBox::about(this, tr("About Warehouse Man Deluxe"), tr("Warehouse Man Deluxe Version 1.0\n\nCopyright (C) 2014 Underground Software\n\nWritten by James L. Hammons"));
+ QMessageBox::about(this, tr("About Warehouse Man Deluxe"), tr("Warehouse Man Deluxe Version 1.0\n\nCopyright (C) 2014 Underground Software\n\nWritten by James Hammons"));
}
protected slots:
void closeEvent(QCloseEvent * event);
+ void HandleNewGame(void);
void AboutGame(void);
void WeHaveAWinner(void);
void HandleReset(void);