summaryrefslogtreecommitdiffstats
path: root/main.cpp
blob: 23c95d99d4af60a95386834cfd0946cf8d317476 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <QtGui>

#include "mazescene.h"

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    MazeScene *scene = new MazeScene;

    QGraphicsView view;
    view.resize(640, 480);
    view.setScene(scene);
    view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    view.show();

    const char *map =
        "########"
        "#      #"
        "# #### #"
        "#    # #"
        "# ##   #"
        "# ## # #"
        "#      #"
        "########";

    const int width = 8;
    const int height = 8;

    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < height; ++x) {
            if (map[y*width+x] != ' ')
                continue;

            if (map[(y-1)*width+x] != ' ')
                scene->addWall(QPointF(x, y), QPointF(x+1, y));
            if (map[(y+1)*width+x] != ' ')
                scene->addWall(QPointF(x+1, y+1), QPointF(x, y+1));
            if (map[y*width+x-1] != ' ')
                scene->addWall(QPointF(x, y+1), QPointF(x, y));
            if (map[y*width+x+1] != ' ')
                scene->addWall(QPointF(x+1, y), QPointF(x+1, y+1));
        }
    }

    view.scale(150, 150);
    return app.exec();
}