summaryrefslogtreecommitdiffstats
path: root/labb4/mainwindow.h
blob: 1ebbb7d11863190e90c3a79a84f7c400e05a99eb (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
/**
 * TDDD86 Robots
 * This file contains the declaration of the mainwindow class.
 * See mainwindow.cpp for implementation of each member.
 */

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QLabel>
#include <QKeyEvent>
#include "qgameoverwindow.h"
#include "constants.h"
#include "GameState.h"

class MainWindow : public QWidget {
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

signals:

protected:
    void keyPressEvent(QKeyEvent *k);

public slots:
    void resetGame();

private:
    QVBoxLayout* mainLayout = nullptr;         // main layout
    QHBoxLayout* labelLayout = nullptr;        // label layout
    QGraphicsView* view = nullptr;             // playing field widget
    QGraphicsScene* scene = nullptr;           // scene for playing field
    QLabel* scoreLabel = nullptr;              // score widget
    QLabel* levelLabel = nullptr;              // level widget
    QGameOverWindow gameOverWindow;  // game over widget

    int score = 0;                                   // current score
    int level = 1;                                   // current level
    int numberOfRobots = MIN_ROBOTS;                 // current no. of robots
    GameState gameState = GameState(numberOfRobots); // current state of game
    bool gameOver = false;

    // private helpers
    bool tryMove(Hero hero, const Point &point);
    void processMove(bool waiting);
    bool outsideBorder(const Point &point) const;
    void displayScore() const;
    void displayLevel() const;
};

#endif // MAINWINDOW_H