]> Shamusworld >> Repos - warehouse-man-deluxe/commitdiff
Moved level storage to global location.
authorShamus Hammons <jlhamm@acm.org>
Tue, 5 Aug 2014 15:17:56 +0000 (10:17 -0500)
committerShamus Hammons <jlhamm@acm.org>
Tue, 5 Aug 2014 15:17:56 +0000 (10:17 -0500)
src/boards.cpp
src/boards.h
src/editorwidget.h
src/editorwindow.cpp
src/gamewidget.cpp
src/mainwin.cpp
src/mainwin.h

index 8cf5ed7bf385e4dd741220005c6754b77cbc114a..8a2fbbe0df4a5ced9df75d27b3dc23bb22fe8c40 100644 (file)
 // 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. :-)
 //
index e14b564e950d92b478f048747615e55128a1d94d..4c01320b54f2cb6ad631cffd8326b9469bd6bde1 100644 (file)
@@ -1,6 +1,9 @@
 #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
@@ -12,8 +15,25 @@ struct Board {
        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__
 
index 87ab02fda3d1aa97299c951ebbadb05fe4e4b836..01781fa201cae89c6c5570629108f77537d2804c 100644 (file)
@@ -3,26 +3,7 @@
 
 #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
 {
@@ -62,7 +43,6 @@ class EditorWidget: public QWidget
                void Pause(int);
 
        public:
-               std::vector<Level> levelStorage;
                uint32_t currentLevel;
 
        private:
index df7743676812ec9b3118e12502343872fc154d6d..ab49a8c22642948a66e73d57d597324067d6a90c 100644 (file)
@@ -36,9 +36,9 @@ EditorWindow::EditorWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
 //     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);
        }
@@ -93,7 +93,7 @@ void EditorWindow::SetEditorLevel(int level)
 
        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
        {
@@ -114,7 +114,7 @@ void EditorWindow::MoveLevelUp(void)
 {
        // 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();
@@ -127,7 +127,7 @@ void EditorWindow::MoveLevelUp(void)
 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);
@@ -152,7 +152,7 @@ void EditorWindow::AddLevel(void)
 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();
@@ -172,6 +172,6 @@ void EditorWindow::DeleteLevel(void)
 
 void EditorWindow::PlayLevel(void)
 {
-       emit SetupLevel(&(editor->levelStorage[editor->currentLevel]));
+       emit SetupLevel(&(levelStorage[editor->currentLevel]));
 }
 
index f66cd588e80ff3cb112f36409c831f3201ef4330..21dda8b9db12565aafd0edb4a9f01d0ff98f336a 100644 (file)
 
 #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)
 {
@@ -61,7 +63,7 @@ void GameWidget::paintEvent(QPaintEvent * /*event*/)
                        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)
@@ -300,7 +302,8 @@ void GameWidget::NextLevel(void)
 {
        level++;
        delete gameBoard;
-       gameBoard = new GameBoard(level);
+//     gameBoard = new GameBoard(level);
+       gameBoard = new GameBoard(&(levelStorage[level - 1]));
        ResizeGrid();
        update();
 }
index 3c37a7bc4f5342cd005338dde6304820e5bcf478..c71e89728d8b0fd3557d52d452219c7aa9aeee29 100644 (file)
 
 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()));
@@ -283,9 +282,17 @@ void MainWin::ResetGame(void)
 }
 
 
+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"));
 }
 
 
index 51b4548b65d568efee538eeb5d76cf29ed9cde3e..2deb6e6ebbacc8ab198725c3697ae0f36330ded6 100644 (file)
@@ -26,6 +26,7 @@ class MainWin: public QMainWindow
        protected slots:
                void closeEvent(QCloseEvent * event);
 
+               void HandleNewGame(void);
                void AboutGame(void);
                void WeHaveAWinner(void);
                void HandleReset(void);