summaryrefslogtreecommitdiffstats
path: root/labb4
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-11-09 22:12:41 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-11-09 22:12:41 +0100
commit6a72f2f15c9f39b2a851b955b9b87abede8d0257 (patch)
tree53afef7ae52433d170fafd070941a5e57e6b44dc /labb4
parent209bc7540a97bb238e70b9f9e248a0a0c756a4c0 (diff)
downloadtddd86-6a72f2f15c9f39b2a851b955b9b87abede8d0257.tar.gz
initial work
Diffstat (limited to 'labb4')
-rw-r--r--labb4/GameState.cpp104
-rw-r--r--labb4/GameState.h82
-rw-r--r--labb4/Hero.cpp15
-rw-r--r--labb4/Hero.h22
-rw-r--r--labb4/Junk.cpp26
-rw-r--r--labb4/Junk.h29
-rw-r--r--labb4/Robot.cpp19
-rw-r--r--labb4/Robot.h20
-rw-r--r--labb4/Unit.cpp68
-rw-r--r--labb4/Unit.h60
-rw-r--r--labb4/constants.h32
-rw-r--r--labb4/mainwindow.cpp207
-rw-r--r--labb4/mainwindow.h58
-rw-r--r--labb4/moc_mainwindow.cpp119
-rw-r--r--labb4/moc_predefs.h385
-rw-r--r--labb4/moc_qgameoverwindow.cpp95
-rw-r--r--labb4/moc_qresetbutton.cpp134
-rw-r--r--labb4/qgameoverwindow.cpp42
-rw-r--r--labb4/qgameoverwindow.h35
-rw-r--r--labb4/qresetbutton.cpp18
-rw-r--r--labb4/qresetbutton.h28
-rw-r--r--labb4/robotsmain.cpp21
-rw-r--r--labb4/utilities.cpp18
-rw-r--r--labb4/utilities.h27
24 files changed, 1664 insertions, 0 deletions
diff --git a/labb4/GameState.cpp b/labb4/GameState.cpp
new file mode 100644
index 0000000..581d2f7
--- /dev/null
+++ b/labb4/GameState.cpp
@@ -0,0 +1,104 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#include "GameState.h"
+#include "utilities.h"
+#include "constants.h"
+
+GameState::GameState(){}
+
+GameState::GameState(int numberOfRobots) {
+ for (int i = 0; i < numberOfRobots; i++) {
+ Robot robot;
+ do {robot = Robot();}
+ while (!isEmpty (robot));
+ robots.push_back(robot);
+ }
+ teleportHero();
+}
+
+void GameState::draw(QGraphicsScene *scene) const {
+ scene->clear();
+ for (size_t i = 0; i < robots.size(); ++i)
+ robots[i].draw(scene);
+ for (size_t i = 0; i < junks.size(); ++i)
+ junks[i].draw(scene);
+ hero.draw(scene);
+}
+
+void GameState::teleportHero() {
+ do hero.teleport();
+ while (!isEmpty(hero));
+}
+
+void GameState::moveRobots() {
+ for (unsigned int i = 0; i < robots.size(); i++)
+ robots[i].moveTowards (hero);
+}
+
+int GameState::countCollisions() {
+ int numberDestroyed = 0;
+ unsigned int i = 0;
+ while (i < robots.size()) {
+ bool hitJunk = junkAt (robots[i]);
+ bool collision = (countRobotsAt (robots[i]) > 1);
+ if (hitJunk || collision) {
+ if (!hitJunk) junks.push_back (Junk(robots[i]));
+ robots[i] = robots[robots.size()-1];
+ robots.pop_back();
+ numberDestroyed++;
+ } else i++;
+ }
+ return numberDestroyed;
+}
+
+bool GameState::anyRobotsLeft() const {
+ return (robots.size() != 0);
+}
+
+bool GameState::heroDead() const {
+ return !isEmpty(hero);
+}
+
+bool GameState::isSafe(const Unit& unit) const {
+ for (unsigned int i = 0; i < robots.size(); i++)
+ if (robots[i].attacks(unit)) return false;
+ if (junkAt(unit)) return false;
+ return true;
+}
+
+void GameState::moveHeroTowards(const Unit& dir) {
+ hero.moveTowards(dir);
+}
+
+Hero GameState::getHero() const {return hero;}
+
+/*
+ * Free of robots and junk only
+ */
+bool GameState::isEmpty(const Unit& unit) const {
+ return (countRobotsAt(unit) == 0 && !junkAt(unit));
+}
+
+/*
+ * Is there junk at unit?
+ */
+bool GameState::junkAt(const Unit& unit) const {
+ for (size_t i = 0; i < junks.size(); ++i)
+ if (junks[i].at(unit)) return true;
+ return false;
+}
+
+/*
+ * How many robots are there at unit?
+ */
+int GameState::countRobotsAt(const Unit& unit) const {
+ int count = 0;
+ for (size_t i = 0; i < robots.size(); ++i) {
+ if (robots[i].at(unit))
+ count++;
+ }
+ return count;
+}
diff --git a/labb4/GameState.h b/labb4/GameState.h
new file mode 100644
index 0000000..2fe2212
--- /dev/null
+++ b/labb4/GameState.h
@@ -0,0 +1,82 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ *
+ * Maintains the game state: Location of all robots, junk and hero.
+ * Method isSafe() is used to keep Hero from moving stupidly.
+ */
+
+#ifndef GAMESTATE_H
+#define GAMESTATE_H
+
+#include <string>
+#include <vector>
+#include <QGraphicsScene>
+#include "Unit.h"
+#include "Robot.h"
+#include "Junk.h"
+#include "Hero.h"
+
+class GameState {
+public:
+ GameState();
+ GameState(int numberOfRobots);
+
+ /*
+ * Clear and redraw entire playing field
+ */
+ void draw(QGraphicsScene* scene) const; // Clear and redraw entire playing field
+
+ /*
+ * Teleport hero to random location
+ */
+ void teleportHero();
+
+ /*
+ * Move robots one step towards hero
+ */
+ void moveRobots();
+
+ /* Count colliding robots
+ * Also converts robots to junk while
+ * checking collisions
+ */
+ int countCollisions ();
+
+ /*
+ * Check if any robots are left on playing field
+ */
+ bool anyRobotsLeft () const;
+
+ /*
+ * Is hero in same place as robot or junk?
+ */
+ bool heroDead() const;
+
+ /*
+ * Can unit safely reside here?
+ */
+ bool isSafe (const Unit& unit) const; // Can unit safely reside here?
+
+ /*
+ * Move hero towards dir
+ */
+ void moveHeroTowards (const Unit& dir);
+
+ /*
+ * Return hero
+ */
+ Hero getHero () const;
+
+private:
+ std::vector<Robot> robots; // the robots and the junk combined
+ Hero hero; // the hero
+
+ // private helpers
+ bool isEmpty(const Unit& unit) const;
+ bool junkAt(const Unit& unit) const;
+ int countRobotsAt(const Unit& unit) const;
+
+};
+
+#endif // GAMESTATE_H
diff --git a/labb4/Hero.cpp b/labb4/Hero.cpp
new file mode 100644
index 0000000..2d3b12e
--- /dev/null
+++ b/labb4/Hero.cpp
@@ -0,0 +1,15 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#include "Hero.h"
+#include "constants.h"
+
+Hero::Hero() : Unit() {}
+
+void Hero::draw(QGraphicsScene *scene) const {
+ Point corner = asPoint();
+ scene->addRect(QRectF(corner.x * UNIT_WIDTH, corner.y * UNIT_HEIGHT,
+ UNIT_WIDTH, UNIT_HEIGHT), Qt::NoPen, QBrush(HERO_COLOR));
+}
diff --git a/labb4/Hero.h b/labb4/Hero.h
new file mode 100644
index 0000000..7750b19
--- /dev/null
+++ b/labb4/Hero.h
@@ -0,0 +1,22 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#ifndef HERO_H
+#define HERO_H
+
+#include "Unit.h"
+#include <QGraphicsScene>
+
+class Hero : public Unit {
+public:
+ Hero();
+
+ /*
+ * Draws this hero onto the given QGraphicsScene.
+ */
+ void draw(QGraphicsScene *scene) const;
+};
+
+#endif // HERO_H
diff --git a/labb4/Junk.cpp b/labb4/Junk.cpp
new file mode 100644
index 0000000..8686129
--- /dev/null
+++ b/labb4/Junk.cpp
@@ -0,0 +1,26 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#include "Junk.h"
+#include "constants.h"
+
+Junk::Junk() : Robot() {}
+Junk::Junk(Robot c) : Robot(c) {}
+
+void Junk::draw(QGraphicsScene *scene) const {
+ Point corner = asPoint();
+ scene->addEllipse(QRectF(corner.x * UNIT_WIDTH, corner.y * UNIT_HEIGHT,
+ JUNK_RADIUS, JUNK_RADIUS), QPen(), QBrush(JUNK_COLOR));
+}
+
+void Junk::moveTowards(const Unit& u) const {}
+
+bool Junk::attacks(const Unit& u) const {
+ return false;
+}
+
+unsigned int Junk::getCollisionCount() const {
+ return 1;
+};
diff --git a/labb4/Junk.h b/labb4/Junk.h
new file mode 100644
index 0000000..a4d6cca
--- /dev/null
+++ b/labb4/Junk.h
@@ -0,0 +1,29 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#ifndef JUNK_H
+#define JUNK_H
+
+#include "Robot.h"
+#include <QGraphicsScene>
+
+class Junk : public Robot {
+public:
+ Junk();
+ Junk(Robot c);
+
+ /*
+ * Draws this junk onto the given QGraphicsScene.
+ */
+ void draw(QGraphicsScene* scene) const;
+
+ void moveTowards(const Unit& u) const;
+
+ bool attacks(const Unit& u) const;
+
+ unsigned int getCollisionCount() const;
+};
+
+#endif // JUNK_H
diff --git a/labb4/Robot.cpp b/labb4/Robot.cpp
new file mode 100644
index 0000000..f7d96e0
--- /dev/null
+++ b/labb4/Robot.cpp
@@ -0,0 +1,19 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#include "Robot.h"
+#include "constants.h"
+
+Robot::Robot() : Unit() {}
+
+void Robot::draw(QGraphicsScene *scene) const {
+ Point corner = asPoint();
+ scene->addEllipse(QRectF(corner.x * UNIT_WIDTH, corner.y * UNIT_HEIGHT,
+ JUNK_RADIUS, JUNK_RADIUS), QPen(), QBrush(ROBOT_COLOR));
+}
+
+unsigned int Robot::getCollisionCount() const {
+ return 1;
+};
diff --git a/labb4/Robot.h b/labb4/Robot.h
new file mode 100644
index 0000000..9e2c075
--- /dev/null
+++ b/labb4/Robot.h
@@ -0,0 +1,20 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#ifndef ROBOT_H
+#define ROBOT_H
+
+#include "Unit.h"
+#include <QGraphicsScene>
+
+class Robot : public Unit {
+public:
+ Robot();
+ void draw(QGraphicsScene* scene) const;
+
+ virtual unsigned int getCollisionCount() const;
+};
+
+#endif // ROBOT_H
diff --git a/labb4/Unit.cpp b/labb4/Unit.cpp
new file mode 100644
index 0000000..f76ad9b
--- /dev/null
+++ b/labb4/Unit.cpp
@@ -0,0 +1,68 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#include "Unit.h"
+#include "constants.h"
+#include "utilities.h"
+#include <cstdlib>
+#include <cmath>
+
+Unit::Unit() {
+ teleport();
+}
+
+Unit::Unit(const Unit& u) {
+ x = u.x;
+ y = u.y;
+}
+
+Unit::Unit(const Point& p) {
+ x = p.x;
+ y = p.y;
+}
+
+Point Unit::asPoint() const {
+ return Point{x, y};
+}
+
+bool Unit::at(const Unit& u) const {
+ return (x == u.x && y == u.y);
+}
+
+bool Unit::attacks(const Unit& u) const {
+ return (abs(x - u.x) <= 1 &&
+ abs(y - u.y) <= 1);
+}
+
+void Unit::moveTowards(const Unit& u) {
+ if (x > u.x) x--;
+ if (x < u.x) x++;
+ if (y > u.y) y--;
+ if (y < u.y) y++;
+ checkBounds();
+}
+
+void Unit::draw() const {}
+
+void Unit::teleport() {
+ x = rand_int (MIN_X, MAX_X);
+ y = rand_int (MIN_Y, MAX_Y);
+}
+
+double Unit::distanceTo(const Unit& u) const {
+ double dx = u.x - x;
+ double dy = u.y - y;
+ return sqrt(dx * dx + dy * dy);
+}
+
+/*
+ * Put this unit inside playing field if outside
+ */
+void Unit::checkBounds() {
+ if (x < MIN_X) x = MIN_X;
+ if (x > MAX_X) x = MAX_X;
+ if (y < MIN_Y) y = MIN_Y;
+ if (y > MAX_Y) y = MAX_Y;
+}
diff --git a/labb4/Unit.h b/labb4/Unit.h
new file mode 100644
index 0000000..8c3a7a8
--- /dev/null
+++ b/labb4/Unit.h
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#ifndef UNIT_H
+#define UNIT_H
+
+#include "utilities.h"
+
+/* Root class for all pieces on the board.
+ * Subclasses are Robot, Hero and Junk.
+ */
+class Unit {
+public:
+ Unit();
+ Unit(const Unit& u);
+ Unit(const Point& p);
+
+ /*
+ * Return Point representation of Unit
+ */
+ Point asPoint() const;
+
+ /*
+ * Am I in the same square as u?
+ */
+ bool at(const Unit& u) const;
+
+ /*
+ * Can I catch u in one move?
+ */
+ virtual bool attacks(const Unit& u) const;
+
+ /*
+ * Take one step closer to u
+ */
+ virtual void moveTowards(const Unit& u);
+
+ //TODO comment
+ virtual void draw() const;
+
+ /*
+ * Teleport. Does not check for collision
+ */
+ void teleport();
+
+ /*
+ * Euclidean distance to u
+ */
+ double distanceTo(const Unit& u) const;
+private:
+ int x; // x position of this unit
+ int y; // y position of this unit
+
+ // private helpers
+ void checkBounds();
+};
+
+#endif // UNIT_H
diff --git a/labb4/constants.h b/labb4/constants.h
new file mode 100644
index 0000000..b6e4f8c
--- /dev/null
+++ b/labb4/constants.h
@@ -0,0 +1,32 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#ifndef CONSTANTS_H
+#define CONSTANTS_H
+
+#include <QColor>
+
+// GUI constants
+const int MIN_X = 0;
+const int MIN_Y = 0;
+const int MAX_X = 39;
+const int MAX_Y = 39;
+const int UNIT_WIDTH = 10;
+const int UNIT_HEIGHT = 10;
+static const int SCENE_WIDTH = 400;
+static const int SCENE_HEIGHT = 400;
+const int JUNK_RADIUS = 9;
+const QColor JUNK_COLOR = QColor(0, 0, 0);
+const QColor ROBOT_COLOR = QColor(245, 95, 60);
+const QColor HERO_COLOR = QColor(237, 207, 114);
+
+// game constants
+const int MIN_ROBOTS = 10;
+const int MAX_ROBOTS = 80;
+const int ROBOTS_INC = 5; // Additional robots per round
+const int POINTS_PER_ROBOT = 10;
+const int WAIT_BONUS = 20; // Per robot
+
+#endif // CONSTANTS_H
diff --git a/labb4/mainwindow.cpp b/labb4/mainwindow.cpp
new file mode 100644
index 0000000..1d3f5e0
--- /dev/null
+++ b/labb4/mainwindow.cpp
@@ -0,0 +1,207 @@
+/**
+ * TDDD86 Robots
+ * This file contains the implementation of the mainwindow class.
+ * See mainwindow.h for comments about each member.
+ */
+
+#include <algorithm>
+#include "mainwindow.h"
+#include "Hero.h"
+#include "Robot.h"
+#include "Junk.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+ QWidget(parent) {
+ // set default size and color
+ scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
+ scene->setBackgroundBrush(QBrush(QColor(204, 192, 179)));
+ view = new QGraphicsView(scene);
+
+ // create the main layout
+ mainLayout = new QVBoxLayout();
+ setLayout(mainLayout);
+
+ // add game board to layout
+ mainLayout->insertWidget(0, view);
+
+ // start new game and draw state
+ gameState.draw(scene);
+
+ // create label layout
+ labelLayout = new QHBoxLayout();
+
+ // create the score widget
+ scoreLabel = new QLabel(QString("SCORE: %1").arg(score));
+ scoreLabel->setStyleSheet("QLabel { color: rgb(235,224,214); font: 16pt; }");
+ scoreLabel->setFixedHeight(35);
+
+ // create the level widget
+ levelLabel = new QLabel(QString("LEVEL: %1").arg(level));
+ levelLabel->setStyleSheet("QLabel { color: rgb(235,224,214); font: 16pt; }");
+ levelLabel->setFixedHeight(35);
+
+ // add score and level widgets to board
+ labelLayout->insertWidget(0, levelLabel, 0, Qt::AlignLeft);
+ labelLayout->insertWidget(1, scoreLabel, 0, Qt::AlignRight);
+ mainLayout->insertLayout(1, labelLayout);
+
+ // style sheet of the game board
+ setStyleSheet("MainWindow { background-color: rgb(187,173,160) }");
+
+ // no resizing of game window
+ setFixedSize(sizeHint());
+
+ connect(gameOverWindow.getResetBtn(), SIGNAL(clicked()), this, SLOT(resetGame()));
+}
+
+MainWindow::~MainWindow() {
+ delete scoreLabel;
+ delete levelLabel;
+ delete labelLayout;
+ delete scene;
+ delete view;
+ delete mainLayout;
+}
+
+/*
+ * Listens to key press events from the graphical subsystem,
+ * and handles the events appropriately:
+ * - '[n]' moves hero in direction [n],
+ * where n = 1, 2, 3, 4, 6, 7, 8, 9 on the numeric keypad
+ * - '5' on the numeric keypad makes the hero wait one turn
+ * - 'T' teleports hero
+ */
+void MainWindow::keyPressEvent(QKeyEvent *e)
+{
+ if (!gameOver) { // only process key presses while game is not over
+ Hero hero = gameState.getHero();
+ Point pt = hero.asPoint();
+ bool actionTaken = false;
+ bool waiting = false;
+
+ if ((e->modifiers() == Qt::NoModifier) || (e->modifiers() == Qt::KeypadModifier)) {
+ switch (e->key()) {
+ case Qt::Key_Z:
+ case Qt::Key_1:
+ actionTaken = tryMove(hero, Point{pt.x - 1, pt.y + 1});
+ break;
+ case Qt::Key_X:
+ case Qt::Key_2:
+ actionTaken = tryMove(hero, Point{pt.x, pt.y + 1});
+ break;
+ case Qt::Key_C:
+ case Qt::Key_3:
+ actionTaken = tryMove(hero, Point{pt.x + 1, pt.y + 1});
+ break;
+ case Qt::Key_A:
+ case Qt::Key_4:
+ actionTaken = tryMove(hero, Point{pt.x - 1, pt.y});
+ break;
+ case Qt::Key_D:
+ case Qt::Key_6:
+ actionTaken = tryMove(hero, Point{pt.x + 1, pt.y});
+ break;
+ case Qt::Key_Q:
+ case Qt::Key_7:
+ actionTaken = tryMove(hero, Point{pt.x - 1, pt.y - 1});
+ break;
+ case Qt::Key_W:
+ case Qt::Key_8:
+ actionTaken = tryMove(hero, Point{pt.x, pt.y - 1});
+ break;
+ case Qt::Key_E:
+ case Qt::Key_9:
+ actionTaken = tryMove(hero, Point{pt.x + 1, pt.y - 1});
+ break;
+ case Qt::Key_S:
+ case Qt::Key_5:
+ actionTaken = true;
+ waiting = true;
+ break;
+ case Qt::Key_T:
+ gameState.teleportHero();
+ actionTaken = true;
+ break;
+ default:
+ QWidget::keyPressEvent(e);
+ }
+ }
+
+ if (actionTaken) { // process results of viable move
+ processMove(waiting);
+ }
+ } else { // game is over - do not process key press
+ QWidget::keyPressEvent(e);
+ }
+}
+
+/*
+ * Try to move hero to unit
+ */
+bool MainWindow::tryMove(Hero hero, const Point& point) {
+ if (!outsideBorder(point)) {
+ hero.moveTowards(point);
+ if (gameState.isSafe(hero)) {
+ gameState.moveHeroTowards(point);
+ return true;
+ }
+ }
+ return false;
+}
+
+/*
+ * Process results of viable move
+ */
+void MainWindow::processMove(bool waiting) {
+ // GameState copy=gameState;
+ // copy.moveRobots();
+ // gameState=copy;
+
+ gameState.moveRobots();
+ score += gameState.countCollisions() * (POINTS_PER_ROBOT +
+ (waiting ? WAIT_BONUS : 0));
+ gameState.draw(scene);
+ displayScore();
+
+ if (!gameState.anyRobotsLeft()) { // won level
+ numberOfRobots = std::min(MAX_ROBOTS, numberOfRobots + ROBOTS_INC);
+ gameState = GameState(numberOfRobots);
+ gameState.draw(scene);
+ ++level;
+ displayLevel();
+ } else if (gameState.heroDead()) { // game over
+ gameOver = true;
+ gameOverWindow.show();
+ }
+}
+
+/*
+ * Is point outside of playing field?
+ */
+bool MainWindow::outsideBorder(Point const& point) const {
+ return point.x > MAX_X
+ || point.y > MAX_Y
+ || point.x < MIN_X
+ || point.y < MIN_Y;
+}
+
+
+void MainWindow::displayScore() const {
+ scoreLabel->setText(QString("SCORE: %1").arg(score));
+}
+
+void MainWindow::displayLevel() const {
+ levelLabel->setText(QString("LEVEL: %1").arg(level));
+}
+
+void MainWindow::resetGame() {
+ score = 0;
+ level = 1;
+ numberOfRobots = MIN_ROBOTS;
+ gameState = GameState(numberOfRobots);
+ gameState.draw(scene);
+ displayScore();
+ displayLevel();
+ gameOver = false;
+ gameOverWindow.hide();
+}
diff --git a/labb4/mainwindow.h b/labb4/mainwindow.h
new file mode 100644
index 0000000..1ebbb7d
--- /dev/null
+++ b/labb4/mainwindow.h
@@ -0,0 +1,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
diff --git a/labb4/moc_mainwindow.cpp b/labb4/moc_mainwindow.cpp
new file mode 100644
index 0000000..158921e
--- /dev/null
+++ b/labb4/moc_mainwindow.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+** Meta object code from reading C++ file 'mainwindow.h'
+**
+** Created by: The Qt Meta Object Compiler version 67 (Qt 5.15.1)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#include <memory>
+#include "mainwindow.h"
+#include <QtCore/qbytearray.h>
+#include <QtCore/qmetatype.h>
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'mainwindow.h' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 67
+#error "This file was generated using the moc from 5.15.1. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+QT_BEGIN_MOC_NAMESPACE
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+struct qt_meta_stringdata_MainWindow_t {
+ QByteArrayData data[3];
+ char stringdata0[22];
+};
+#define QT_MOC_LITERAL(idx, ofs, len) \
+ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
+ qptrdiff(offsetof(qt_meta_stringdata_MainWindow_t, stringdata0) + ofs \
+ - idx * sizeof(QByteArrayData)) \
+ )
+static const qt_meta_stringdata_MainWindow_t qt_meta_stringdata_MainWindow = {
+ {
+QT_MOC_LITERAL(0, 0, 10), // "MainWindow"
+QT_MOC_LITERAL(1, 11, 9), // "resetGame"
+QT_MOC_LITERAL(2, 21, 0) // ""
+
+ },
+ "MainWindow\0resetGame\0"
+};
+#undef QT_MOC_LITERAL
+
+static const uint qt_meta_data_MainWindow[] = {
+
+ // content:
+ 8, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 1, 14, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+ 0, // flags
+ 0, // signalCount
+
+ // slots: name, argc, parameters, tag, flags
+ 1, 0, 19, 2, 0x0a /* Public */,
+
+ // slots: parameters
+ QMetaType::Void,
+
+ 0 // eod
+};
+
+void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
+{
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ auto *_t = static_cast<MainWindow *>(_o);
+ Q_UNUSED(_t)
+ switch (_id) {
+ case 0: _t->resetGame(); break;
+ default: ;
+ }
+ }
+ Q_UNUSED(_a);
+}
+
+QT_INIT_METAOBJECT const QMetaObject MainWindow::staticMetaObject = { {
+ QMetaObject::SuperData::link<QWidget::staticMetaObject>(),
+ qt_meta_stringdata_MainWindow.data,
+ qt_meta_data_MainWindow,
+ qt_static_metacall,
+ nullptr,
+ nullptr
+} };
+
+
+const QMetaObject *MainWindow::metaObject() const
+{
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
+}
+
+void *MainWindow::qt_metacast(const char *_clname)
+{
+ if (!_clname) return nullptr;
+ if (!strcmp(_clname, qt_meta_stringdata_MainWindow.stringdata0))
+ return static_cast<void*>(this);
+ return QWidget::qt_metacast(_clname);
+}
+
+int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QWidget::qt_metacall(_c, _id, _a);
+ if (_id < 0)
+ return _id;
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ if (_id < 1)
+ qt_static_metacall(this, _c, _id, _a);
+ _id -= 1;
+ } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
+ if (_id < 1)
+ *reinterpret_cast<int*>(_a[0]) = -1;
+ _id -= 1;
+ }
+ return _id;
+}
+QT_WARNING_POP
+QT_END_MOC_NAMESPACE
diff --git a/labb4/moc_predefs.h b/labb4/moc_predefs.h
new file mode 100644
index 0000000..c5af862
--- /dev/null
+++ b/labb4/moc_predefs.h
@@ -0,0 +1,385 @@
+#define __SSP_STRONG__ 3
+#define __DBL_MIN_EXP__ (-1021)
+#define __cpp_attributes 200809L
+#define __UINT_LEAST16_MAX__ 0xffff
+#define __ATOMIC_ACQUIRE 2
+#define __FLT128_MAX_10_EXP__ 4932
+#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F
+#define __GCC_IEC_559_COMPLEX 2
+#define __UINT_LEAST8_TYPE__ unsigned char
+#define __SIZEOF_FLOAT80__ 16
+#define __INTMAX_C(c) c ## L
+#define __CHAR_BIT__ 8
+#define __UINT8_MAX__ 0xff
+#define __SCHAR_WIDTH__ 8
+#define __WINT_MAX__ 0xffffffffU
+#define __FLT32_MIN_EXP__ (-125)
+#define __cpp_static_assert 200410L
+#define __ORDER_LITTLE_ENDIAN__ 1234
+#define __SIZE_MAX__ 0xffffffffffffffffUL
+#define __WCHAR_MAX__ 0x7fffffff
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+#define __DBL_DENORM_MIN__ double(4.94065645841246544176568792868221372e-324L)
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
+#define __GCC_IEC_559 2
+#define __FLT32X_DECIMAL_DIG__ 17
+#define __FLT_EVAL_METHOD__ 0
+#define __cpp_binary_literals 201304L
+#define __FLT64_DECIMAL_DIG__ 17
+#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
+#define __cpp_variadic_templates 200704L
+#define __UINT_FAST64_MAX__ 0xffffffffffffffffUL
+#define __SIG_ATOMIC_TYPE__ int
+#define __DBL_MIN_10_EXP__ (-307)
+#define __FINITE_MATH_ONLY__ 0
+#define __FLT32X_MAX_EXP__ 1024
+#define __FLT32_HAS_DENORM__ 1
+#define __UINT_FAST8_MAX__ 0xff
+#define __cpp_rvalue_reference 200610L
+#define __FLT32_MAX_10_EXP__ 38
+#define __DEC64_MAX_EXP__ 385
+#define __INT8_C(c) c
+#define __INT_LEAST8_WIDTH__ 8
+#define __UINT_LEAST64_MAX__ 0xffffffffffffffffUL
+#define __SHRT_MAX__ 0x7fff
+#define __LDBL_MAX__ 1.18973149535723176502126385303097021e+4932L
+#define __FLT64X_MAX_10_EXP__ 4932
+#define __FLT64X_HAS_QUIET_NAN__ 1
+#define __UINT_LEAST8_MAX__ 0xff
+#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
+#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966F128
+#define __UINTMAX_TYPE__ long unsigned int
+#define __linux 1
+#define __DEC32_EPSILON__ 1E-6DF
+#define __FLT_EVAL_METHOD_TS_18661_3__ 0
+#define __OPTIMIZE__ 1
+#define __unix 1
+#define __UINT32_MAX__ 0xffffffffU
+#define __GXX_EXPERIMENTAL_CXX0X__ 1
+#define __FLT128_MIN_EXP__ (-16381)
+#define __WINT_MIN__ 0U
+#define __FLT128_MIN_10_EXP__ (-4931)
+#define __INT_LEAST16_WIDTH__ 16
+#define __SCHAR_MAX__ 0x7f
+#define __FLT128_MANT_DIG__ 113
+#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)
+#define __INT64_C(c) c ## L
+#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
+#define __FLT32X_MANT_DIG__ 53
+#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
+#define __USER_LABEL_PREFIX__
+#define __FLT64X_EPSILON__ 1.08420217248550443400745280086994171e-19F64x
+#define __STDC_HOSTED__ 1
+#define __DEC64_MIN_EXP__ (-382)
+#define __DBL_DIG__ 15
+#define __FLT32_DIG__ 6
+#define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F
+#define __GXX_WEAK__ 1
+#define __SHRT_WIDTH__ 16
+#define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
+#define __DEC32_MAX__ 9.999999E96DF
+#define __cpp_threadsafe_static_init 200806L
+#define __FLT64X_DENORM_MIN__ 3.64519953188247460252840593361941982e-4951F64x
+#define __FLT32X_HAS_INFINITY__ 1
+#define __INT32_MAX__ 0x7fffffff
+#define __unix__ 1
+#define __INT_WIDTH__ 32
+#define __SIZEOF_LONG__ 8
+#define __STDC_IEC_559__ 1
+#define __STDC_ISO_10646__ 201706L
+#define __UINT16_C(c) c
+#define __DECIMAL_DIG__ 21
+#define __STDC_IEC_559_COMPLEX__ 1
+#define __FLT64_EPSILON__ 2.22044604925031308084726333618164062e-16F64
+#define __gnu_linux__ 1
+#define __INT16_MAX__ 0x7fff
+#define __FLT64_MIN_EXP__ (-1021)
+#define __FLT64X_MIN_10_EXP__ (-4931)
+#define __LDBL_HAS_QUIET_NAN__ 1
+#define __FLT64_MANT_DIG__ 53
+#define __FLT64X_MANT_DIG__ 64
+#define __GNUC__ 10
+#define __GXX_RTTI 1
+#define __pie__ 2
+#define __MMX__ 1
+#define __FLT_HAS_DENORM__ 1
+#define __SIZEOF_LONG_DOUBLE__ 16
+#define __BIGGEST_ALIGNMENT__ 16
+#define __STDC_UTF_16__ 1
+#define __FLT64_MAX_10_EXP__ 308
+#define __cpp_delegating_constructors 200604L
+#define __FLT32_HAS_INFINITY__ 1
+#define __DBL_MAX__ double(1.79769313486231570814527423731704357e+308L)
+#define __cpp_raw_strings 200710L
+#define __INT_FAST32_MAX__ 0x7fffffffffffffffL
+#define __DBL_HAS_INFINITY__ 1
+#define __SIZEOF_FLOAT__ 4
+#define __HAVE_SPECULATION_SAFE_VALUE 1
+#define __DEC32_MIN_EXP__ (-94)
+#define __INTPTR_WIDTH__ 64
+#define __FLT64X_HAS_INFINITY__ 1
+#define __UINT_LEAST32_MAX__ 0xffffffffU
+#define __FLT32X_HAS_DENORM__ 1
+#define __INT_FAST16_TYPE__ long int
+#define __STRICT_ANSI__ 1
+#define __MMX_WITH_SSE__ 1
+#define __LDBL_HAS_DENORM__ 1
+#define __cplusplus 201103L
+#define __cpp_ref_qualifiers 200710L
+#define __DEC32_MIN__ 1E-95DF
+#define __DEPRECATED 1
+#define __cpp_rvalue_references 200610L
+#define __DBL_MAX_EXP__ 1024
+#define __WCHAR_WIDTH__ 32
+#define __FLT32_MAX__ 3.40282346638528859811704183484516925e+38F32
+#define __DEC128_EPSILON__ 1E-33DL
+#define __SSE2_MATH__ 1
+#define __ATOMIC_HLE_RELEASE 131072
+#define __PTRDIFF_MAX__ 0x7fffffffffffffffL
+#define __amd64 1
+#define __ATOMIC_HLE_ACQUIRE 65536
+#define __GNUG__ 10
+#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
+#define __SIZEOF_SIZE_T__ 8
+#define __cpp_nsdmi 200809L
+#define __FLT64X_MIN_EXP__ (-16381)
+#define __SIZEOF_WINT_T__ 4
+#define __LONG_LONG_WIDTH__ 64
+#define __cpp_initializer_lists 200806L
+#define __FLT32_MAX_EXP__ 128
+#define __cpp_hex_float 201603L
+#define __GXX_ABI_VERSION 1014
+#define __FLT128_HAS_INFINITY__ 1
+#define __FLT_MIN_EXP__ (-125)
+#define __GCC_HAVE_DWARF2_CFI_ASM 1
+#define __x86_64 1
+#define __cpp_lambdas 200907L
+#define __INT_FAST64_TYPE__ long int
+#define __FLT64_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F64
+#define __DBL_MIN__ double(2.22507385850720138309023271733240406e-308L)
+#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34F128
+#define __FLT64X_NORM_MAX__ 1.18973149535723176502126385303097021e+4932F64x
+#define __SIZEOF_POINTER__ 8
+#define __LP64__ 1
+#define __DBL_HAS_QUIET_NAN__ 1
+#define __FLT32X_EPSILON__ 2.22044604925031308084726333618164062e-16F32x
+#define __DECIMAL_BID_FORMAT__ 1
+#define __FLT64_MIN_10_EXP__ (-307)
+#define __FLT64X_DECIMAL_DIG__ 21
+#define __DEC128_MIN__ 1E-6143DL
+#define __REGISTER_PREFIX__
+#define __UINT16_MAX__ 0xffff
+#define __LDBL_HAS_INFINITY__ 1
+#define __FLT32_MIN__ 1.17549435082228750796873653722224568e-38F32
+#define __UINT8_TYPE__ unsigned char
+#define __FLT_DIG__ 6
+#define __DEC_EVAL_METHOD__ 2
+#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
+#define __FLT_MANT_DIG__ 24
+#define __LDBL_DECIMAL_DIG__ 21
+#define __VERSION__ "10.2.0"
+#define __UINT64_C(c) c ## UL
+#define __cpp_unicode_characters 200704L
+#define _STDC_PREDEF_H 1
+#define __INT_LEAST32_MAX__ 0x7fffffff
+#define __GCC_ATOMIC_INT_LOCK_FREE 2
+#define __FLT128_MAX_EXP__ 16384
+#define __FLT32_MANT_DIG__ 24
+#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __FLT128_HAS_DENORM__ 1
+#define __FLT32_DECIMAL_DIG__ 9
+#define __FLT128_DIG__ 33
+#define __INT32_C(c) c
+#define __DEC64_EPSILON__ 1E-15DD
+#define __ORDER_PDP_ENDIAN__ 3412
+#define __DEC128_MIN_EXP__ (-6142)
+#define __INT_FAST32_TYPE__ long int
+#define __UINT_LEAST16_TYPE__ short unsigned int
+#define __DBL_HAS_DENORM__ 1
+#define __cpp_rtti 199711L
+#define __SIZE_TYPE__ long unsigned int
+#define __UINT64_MAX__ 0xffffffffffffffffUL
+#define __FLT64X_DIG__ 18
+#define __INT8_TYPE__ signed char
+#define __ELF__ 1
+#define __GCC_ASM_FLAG_OUTPUTS__ 1
+#define __UINT32_TYPE__ unsigned int
+#define __FLT_RADIX__ 2
+#define __INT_LEAST16_TYPE__ short int
+#define __LDBL_EPSILON__ 1.08420217248550443400745280086994171e-19L
+#define __UINTMAX_C(c) c ## UL
+#define __k8 1
+#define __FLT32X_MIN__ 2.22507385850720138309023271733240406e-308F32x
+#define __SIG_ATOMIC_MAX__ 0x7fffffff
+#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
+#define __SIZEOF_PTRDIFF_T__ 8
+#define __LDBL_DIG__ 18
+#define __x86_64__ 1
+#define __FLT32X_MIN_EXP__ (-1021)
+#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
+#define __INT_FAST16_MAX__ 0x7fffffffffffffffL
+#define __FLT64_DIG__ 15
+#define __UINT_FAST32_MAX__ 0xffffffffffffffffUL
+#define __UINT_LEAST64_TYPE__ long unsigned int
+#define __FLT_HAS_QUIET_NAN__ 1
+#define __FLT_MAX_10_EXP__ 38
+#define __LONG_MAX__ 0x7fffffffffffffffL
+#define __FLT64X_HAS_DENORM__ 1
+#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
+#define __FLT_HAS_INFINITY__ 1
+#define __cpp_unicode_literals 200710L
+#define __UINT_FAST16_TYPE__ long unsigned int
+#define __DEC64_MAX__ 9.999999999999999E384DD
+#define __INT_FAST32_WIDTH__ 64
+#define __CHAR16_TYPE__ short unsigned int
+#define __PRAGMA_REDEFINE_EXTNAME 1
+#define __SIZE_WIDTH__ 64
+#define __SEG_FS 1
+#define __INT_LEAST16_MAX__ 0x7fff
+#define __DEC64_MANT_DIG__ 16
+#define __INT64_MAX__ 0x7fffffffffffffffL
+#define __SEG_GS 1
+#define __FLT32_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F32
+#define __SIG_ATOMIC_WIDTH__ 32
+#define __INT_LEAST64_TYPE__ long int
+#define __INT16_TYPE__ short int
+#define __INT_LEAST8_TYPE__ signed char
+#define __SIZEOF_INT__ 4
+#define __DEC32_MAX_EXP__ 97
+#define __INT_FAST8_MAX__ 0x7f
+#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932F128
+#define __INTPTR_MAX__ 0x7fffffffffffffffL
+#define __FLT64_HAS_QUIET_NAN__ 1
+#define __FLT32_MIN_10_EXP__ (-37)
+#define __EXCEPTIONS 1
+#define __PTRDIFF_WIDTH__ 64
+#define __LDBL_MANT_DIG__ 64
+#define __cpp_range_based_for 200907L
+#define __FLT64_HAS_INFINITY__ 1
+#define __FLT64X_MAX__ 1.18973149535723176502126385303097021e+4932F64x
+#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
+#define __code_model_small__ 1
+#define __GCC_ATOMIC_LONG_LOCK_FREE 2
+#define __DEC32_MANT_DIG__ 7
+#define __k8__ 1
+#define __INTPTR_TYPE__ long int
+#define __UINT16_TYPE__ short unsigned int
+#define __WCHAR_TYPE__ int
+#define __pic__ 2
+#define __UINTPTR_MAX__ 0xffffffffffffffffUL
+#define __INT_FAST64_WIDTH__ 64
+#define __cpp_decltype 200707L
+#define __INT_FAST64_MAX__ 0x7fffffffffffffffL
+#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+#define __FLT_NORM_MAX__ 3.40282346638528859811704183484516925e+38F
+#define __FLT64X_MAX_EXP__ 16384
+#define __UINT_FAST64_TYPE__ long unsigned int
+#define __INT_MAX__ 0x7fffffff
+#define __linux__ 1
+#define __INT64_TYPE__ long int
+#define __FLT_MAX_EXP__ 128
+#define __ORDER_BIG_ENDIAN__ 4321
+#define __DBL_MANT_DIG__ 53
+#define __cpp_inheriting_constructors 201511L
+#define __SIZEOF_FLOAT128__ 16
+#define __INT_LEAST64_MAX__ 0x7fffffffffffffffL
+#define __DEC64_MIN__ 1E-383DD
+#define __WINT_TYPE__ unsigned int
+#define __UINT_LEAST32_TYPE__ unsigned int
+#define __SIZEOF_SHORT__ 2
+#define __FLT32_NORM_MAX__ 3.40282346638528859811704183484516925e+38F32
+#define __SSE__ 1
+#define __LDBL_MIN_EXP__ (-16381)
+#define __FLT64_MAX__ 1.79769313486231570814527423731704357e+308F64
+#define __amd64__ 1
+#define __WINT_WIDTH__ 32
+#define __INT_LEAST8_MAX__ 0x7f
+#define __INT_LEAST64_WIDTH__ 64
+#define __LDBL_MAX_EXP__ 16384
+#define __FLT32X_MAX_10_EXP__ 308
+#define __SIZEOF_INT128__ 16
+#define __LDBL_MAX_10_EXP__ 4932
+#define __ATOMIC_RELAXED 0
+#define __DBL_EPSILON__ double(2.22044604925031308084726333618164062e-16L)
+#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932F128
+#define _LP64 1
+#define __UINT8_C(c) c
+#define __FLT64_MAX_EXP__ 1024
+#define __INT_LEAST32_TYPE__ int
+#define __SIZEOF_WCHAR_T__ 4
+#define __GNUC_PATCHLEVEL__ 0
+#define __FLT128_NORM_MAX__ 1.18973149535723176508575932662800702e+4932F128
+#define __FLT64_NORM_MAX__ 1.79769313486231570814527423731704357e+308F64
+#define __FLT128_HAS_QUIET_NAN__ 1
+#define __INTMAX_MAX__ 0x7fffffffffffffffL
+#define __INT_FAST8_TYPE__ signed char
+#define __FLT64X_MIN__ 3.36210314311209350626267781732175260e-4932F64x
+#define __GNUC_STDC_INLINE__ 1
+#define __FLT64_HAS_DENORM__ 1
+#define __FLT32_EPSILON__ 1.19209289550781250000000000000000000e-7F32
+#define __DBL_DECIMAL_DIG__ 17
+#define __STDC_UTF_32__ 1
+#define __INT_FAST8_WIDTH__ 8
+#define __FXSR__ 1
+#define __FLT32X_MAX__ 1.79769313486231570814527423731704357e+308F32x
+#define __DBL_NORM_MAX__ double(1.79769313486231570814527423731704357e+308L)
+#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __INTMAX_WIDTH__ 64
+#define __cpp_runtime_arrays 198712L
+#define __UINT64_TYPE__ long unsigned int
+#define __UINT32_C(c) c ## U
+#define __cpp_alias_templates 200704L
+#define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F
+#define __INT8_MAX__ 0x7f
+#define __LONG_WIDTH__ 64
+#define __PIC__ 2
+#define __UINT_FAST32_TYPE__ long unsigned int
+#define __FLT32X_NORM_MAX__ 1.79769313486231570814527423731704357e+308F32x
+#define __CHAR32_TYPE__ unsigned int
+#define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F
+#define __cpp_constexpr 200704L
+#define __SSE2__ 1
+#define __INT32_TYPE__ int
+#define __SIZEOF_DOUBLE__ 8
+#define __cpp_exceptions 199711L
+#define __FLT_MIN_10_EXP__ (-37)
+#define __FLT64_MIN__ 2.22507385850720138309023271733240406e-308F64
+#define __INT_LEAST32_WIDTH__ 32
+#define __INTMAX_TYPE__ long int
+#define __DEC128_MAX_EXP__ 6145
+#define __FLT32X_HAS_QUIET_NAN__ 1
+#define __ATOMIC_CONSUME 1
+#define __GNUC_MINOR__ 2
+#define __INT_FAST16_WIDTH__ 64
+#define __UINTMAX_MAX__ 0xffffffffffffffffUL
+#define __PIE__ 2
+#define __FLT32X_DENORM_MIN__ 4.94065645841246544176568792868221372e-324F32x
+#define __DBL_MAX_10_EXP__ 308
+#define __LDBL_DENORM_MIN__ 3.64519953188247460252840593361941982e-4951L
+#define __INT16_C(c) c
+#define __STDC__ 1
+#define __FLT32X_DIG__ 15
+#define __PTRDIFF_TYPE__ long int
+#define __ATOMIC_SEQ_CST 5
+#define __FLT32X_MIN_10_EXP__ (-307)
+#define __UINTPTR_TYPE__ long unsigned int
+#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
+#define __DEC128_MANT_DIG__ 34
+#define __LDBL_MIN_10_EXP__ (-4931)
+#define __SSE_MATH__ 1
+#define __SIZEOF_LONG_LONG__ 8
+#define __cpp_user_defined_literals 200809L
+#define __FLT128_DECIMAL_DIG__ 36
+#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
+#define __FLT32_HAS_QUIET_NAN__ 1
+#define __FLT_DECIMAL_DIG__ 9
+#define __UINT_FAST16_MAX__ 0xffffffffffffffffUL
+#define __LDBL_NORM_MAX__ 1.18973149535723176502126385303097021e+4932L
+#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
+#define __UINT_FAST8_TYPE__ unsigned char
+#define _GNU_SOURCE 1
+#define __ATOMIC_ACQ_REL 4
+#define __ATOMIC_RELEASE 3
diff --git a/labb4/moc_qgameoverwindow.cpp b/labb4/moc_qgameoverwindow.cpp
new file mode 100644
index 0000000..7d7e091
--- /dev/null
+++ b/labb4/moc_qgameoverwindow.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+** Meta object code from reading C++ file 'qgameoverwindow.h'
+**
+** Created by: The Qt Meta Object Compiler version 67 (Qt 5.15.1)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#include <memory>
+#include "qgameoverwindow.h"
+#include <QtCore/qbytearray.h>
+#include <QtCore/qmetatype.h>
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'qgameoverwindow.h' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 67
+#error "This file was generated using the moc from 5.15.1. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+QT_BEGIN_MOC_NAMESPACE
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+struct qt_meta_stringdata_QGameOverWindow_t {
+ QByteArrayData data[1];
+ char stringdata0[16];
+};
+#define QT_MOC_LITERAL(idx, ofs, len) \
+ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
+ qptrdiff(offsetof(qt_meta_stringdata_QGameOverWindow_t, stringdata0) + ofs \
+ - idx * sizeof(QByteArrayData)) \
+ )
+static const qt_meta_stringdata_QGameOverWindow_t qt_meta_stringdata_QGameOverWindow = {
+ {
+QT_MOC_LITERAL(0, 0, 15) // "QGameOverWindow"
+
+ },
+ "QGameOverWindow"
+};
+#undef QT_MOC_LITERAL
+
+static const uint qt_meta_data_QGameOverWindow[] = {
+
+ // content:
+ 8, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 0, 0, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+ 0, // flags
+ 0, // signalCount
+
+ 0 // eod
+};
+
+void QGameOverWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
+{
+ Q_UNUSED(_o);
+ Q_UNUSED(_id);
+ Q_UNUSED(_c);
+ Q_UNUSED(_a);
+}
+
+QT_INIT_METAOBJECT const QMetaObject QGameOverWindow::staticMetaObject = { {
+ QMetaObject::SuperData::link<QWidget::staticMetaObject>(),
+ qt_meta_stringdata_QGameOverWindow.data,
+ qt_meta_data_QGameOverWindow,
+ qt_static_metacall,
+ nullptr,
+ nullptr
+} };
+
+
+const QMetaObject *QGameOverWindow::metaObject() const
+{
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
+}
+
+void *QGameOverWindow::qt_metacast(const char *_clname)
+{
+ if (!_clname) return nullptr;
+ if (!strcmp(_clname, qt_meta_stringdata_QGameOverWindow.stringdata0))
+ return static_cast<void*>(this);
+ return QWidget::qt_metacast(_clname);
+}
+
+int QGameOverWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QWidget::qt_metacall(_c, _id, _a);
+ return _id;
+}
+QT_WARNING_POP
+QT_END_MOC_NAMESPACE
diff --git a/labb4/moc_qresetbutton.cpp b/labb4/moc_qresetbutton.cpp
new file mode 100644
index 0000000..37ce99b
--- /dev/null
+++ b/labb4/moc_qresetbutton.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+** Meta object code from reading C++ file 'qresetbutton.h'
+**
+** Created by: The Qt Meta Object Compiler version 67 (Qt 5.15.1)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#include <memory>
+#include "qresetbutton.h"
+#include <QtCore/qbytearray.h>
+#include <QtCore/qmetatype.h>
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'qresetbutton.h' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 67
+#error "This file was generated using the moc from 5.15.1. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+QT_BEGIN_MOC_NAMESPACE
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+struct qt_meta_stringdata_QResetButton_t {
+ QByteArrayData data[3];
+ char stringdata0[22];
+};
+#define QT_MOC_LITERAL(idx, ofs, len) \
+ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
+ qptrdiff(offsetof(qt_meta_stringdata_QResetButton_t, stringdata0) + ofs \
+ - idx * sizeof(QByteArrayData)) \
+ )
+static const qt_meta_stringdata_QResetButton_t qt_meta_stringdata_QResetButton = {
+ {
+QT_MOC_LITERAL(0, 0, 12), // "QResetButton"
+QT_MOC_LITERAL(1, 13, 7), // "clicked"
+QT_MOC_LITERAL(2, 21, 0) // ""
+
+ },
+ "QResetButton\0clicked\0"
+};
+#undef QT_MOC_LITERAL
+
+static const uint qt_meta_data_QResetButton[] = {
+
+ // content:
+ 8, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 1, 14, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+ 0, // flags
+ 1, // signalCount
+
+ // signals: name, argc, parameters, tag, flags
+ 1, 0, 19, 2, 0x06 /* Public */,
+
+ // signals: parameters
+ QMetaType::Void,
+
+ 0 // eod
+};
+
+void QResetButton::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
+{
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ auto *_t = static_cast<QResetButton *>(_o);
+ Q_UNUSED(_t)
+ switch (_id) {
+ case 0: _t->clicked(); break;
+ default: ;
+ }
+ } else if (_c == QMetaObject::IndexOfMethod) {
+ int *result = reinterpret_cast<int *>(_a[0]);
+ {
+ using _t = void (QResetButton::*)();
+ if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&QResetButton::clicked)) {
+ *result = 0;
+ return;
+ }
+ }
+ }
+ Q_UNUSED(_a);
+}
+
+QT_INIT_METAOBJECT const QMetaObject QResetButton::staticMetaObject = { {
+ QMetaObject::SuperData::link<QLabel::staticMetaObject>(),
+ qt_meta_stringdata_QResetButton.data,
+ qt_meta_data_QResetButton,
+ qt_static_metacall,
+ nullptr,
+ nullptr
+} };
+
+
+const QMetaObject *QResetButton::metaObject() const
+{
+ return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
+}
+
+void *QResetButton::qt_metacast(const char *_clname)
+{
+ if (!_clname) return nullptr;
+ if (!strcmp(_clname, qt_meta_stringdata_QResetButton.stringdata0))
+ return static_cast<void*>(this);
+ return QLabel::qt_metacast(_clname);
+}
+
+int QResetButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QLabel::qt_metacall(_c, _id, _a);
+ if (_id < 0)
+ return _id;
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ if (_id < 1)
+ qt_static_metacall(this, _c, _id, _a);
+ _id -= 1;
+ } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
+ if (_id < 1)
+ *reinterpret_cast<int*>(_a[0]) = -1;
+ _id -= 1;
+ }
+ return _id;
+}
+
+// SIGNAL 0
+void QResetButton::clicked()
+{
+ QMetaObject::activate(this, &staticMetaObject, 0, nullptr);
+}
+QT_WARNING_POP
+QT_END_MOC_NAMESPACE
diff --git a/labb4/qgameoverwindow.cpp b/labb4/qgameoverwindow.cpp
new file mode 100644
index 0000000..5a3b359
--- /dev/null
+++ b/labb4/qgameoverwindow.cpp
@@ -0,0 +1,42 @@
+/**
+ * TDDD86 Robots
+ * This file contains the implementation of the QGameOverWindow class.
+ */
+
+#include "qgameoverwindow.h"
+#include "qresetbutton.h"
+
+#include <QVBoxLayout>
+#include <QLabel>
+
+QGameOverWindow::QGameOverWindow(QWidget *parent) :
+ QWidget(parent) {
+ setStyleSheet("QGameOverWindow { background: rgb(237,224,200); }");
+ setFixedSize(425, 205);
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ // game over label
+ QLabel* gameover = new QLabel("Game Over!", this);
+ gameover->setStyleSheet("QLabel { color: rgb(119,110,101); font: 40pt; font: bold;} ");
+
+ // reset button
+ reset = new QResetButton(this);
+ reset->setFixedHeight(50);
+ reset->setFixedWidth(100);
+
+ // add game over label to window
+ layout->insertWidget(0, gameover, 0, Qt::AlignCenter);
+
+ // add reset button to window
+ layout->insertWidget(1, reset, 0, Qt::AlignCenter);
+}
+
+QGameOverWindow::~QGameOverWindow() {
+ delete reset;
+ delete gameover;
+ delete layout;
+}
+
+QResetButton* QGameOverWindow::getResetBtn() const {
+ return reset;
+}
diff --git a/labb4/qgameoverwindow.h b/labb4/qgameoverwindow.h
new file mode 100644
index 0000000..2185d34
--- /dev/null
+++ b/labb4/qgameoverwindow.h
@@ -0,0 +1,35 @@
+/**
+ * TDDD86 Robots
+ * This file contains the declaration of the QGameOverWindow class.
+ * See qgameoverwindow.cpp for implementation of each member.
+ */
+
+#ifndef QGAMEOVERWINDOW_H
+#define QGAMEOVERWINDOW_H
+
+#include <QWidget>
+#include <QVBoxLayout>
+#include <QLabel>
+#include "qresetbutton.h"
+
+class QGameOverWindow : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit QGameOverWindow(QWidget *parent = 0);
+ ~QGameOverWindow();
+
+ QResetButton* getResetBtn() const;
+
+signals:
+
+public slots:
+
+private:
+
+ QVBoxLayout *layout = nullptr;
+ QLabel* gameover = nullptr;
+ QResetButton* reset = nullptr;
+};
+
+#endif // QGAMEOVERWINDOW_H
diff --git a/labb4/qresetbutton.cpp b/labb4/qresetbutton.cpp
new file mode 100644
index 0000000..8eef506
--- /dev/null
+++ b/labb4/qresetbutton.cpp
@@ -0,0 +1,18 @@
+/**
+ * TDDD86 Robots
+ * This file contains the implementation of the QResetButton class.
+ */
+
+#include "qresetbutton.h"
+
+QResetButton::QResetButton( QWidget* parent) : QLabel(parent) {
+ setText("Try again!");
+ setAlignment(Qt::AlignCenter);
+ setStyleSheet("QResetButton { background-color: rgb(143,122,102); border-radius: 10px; font: bold; color: white; }");
+}
+
+void QResetButton::mousePressEvent(QMouseEvent* event) {
+ if (event) {
+ emit clicked();
+ }
+}
diff --git a/labb4/qresetbutton.h b/labb4/qresetbutton.h
new file mode 100644
index 0000000..4b15e6f
--- /dev/null
+++ b/labb4/qresetbutton.h
@@ -0,0 +1,28 @@
+/**
+ * TDDD86 Robots
+ * This file contains the declaration of the QResetButton class.
+ * See qresetbutton.cpp for implementation of each member.
+ */
+
+#ifndef QRESETBUTTON_H
+#define QRESETBUTTON_H
+
+#include <QLabel>
+
+class QResetButton : public QLabel
+{
+ Q_OBJECT
+public:
+ QResetButton( QWidget* parent = 0);
+
+signals:
+ void clicked();
+
+public slots:
+
+protected:
+ void mousePressEvent(QMouseEvent* event);
+
+};
+
+#endif // QRESETBUTTON_H
diff --git a/labb4/robotsmain.cpp b/labb4/robotsmain.cpp
new file mode 100644
index 0000000..64eb176
--- /dev/null
+++ b/labb4/robotsmain.cpp
@@ -0,0 +1,21 @@
+/**
+ * TDDD86 Robots
+ * This client program contains the 'main' function to set up the overall
+ * program's graphical user interface.
+ * Your code should work properly with an unmodified version of this file.
+ */
+
+#include <QApplication>
+#include "mainwindow.h"
+#include "utilities.h"
+
+int main(int argc, char *argv[]) {
+ QApplication a(argc, argv);
+
+ rand_seed(); // seed random number generator
+
+ MainWindow view; // create main window
+ view.show(); // display main window
+
+ return a.exec(); // start Qt event loop
+}
diff --git a/labb4/utilities.cpp b/labb4/utilities.cpp
new file mode 100644
index 0000000..a894a3c
--- /dev/null
+++ b/labb4/utilities.cpp
@@ -0,0 +1,18 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#include "utilities.h"
+#include "constants.h"
+#include <cstdlib>
+#include <ctime>
+
+void rand_seed() {
+ int seed = static_cast<int>(time(0));
+ srand(seed);
+}
+
+int rand_int(int a, int b) {
+ return a + rand() % (b - a + 1);
+}
diff --git a/labb4/utilities.h b/labb4/utilities.h
new file mode 100644
index 0000000..c180129
--- /dev/null
+++ b/labb4/utilities.h
@@ -0,0 +1,27 @@
+/**
+ * Copyright (C) David Wolfe, 1999. All rights reserved.
+ * Ported to Qt and adapted for TDDD86, 2015.
+ */
+
+#ifndef UTILITIES_H
+#define UTILITIES_H
+
+struct Point {
+ int x;
+ int y;
+};
+
+/**
+ * Sets the seed of the random number generator.
+ */
+void rand_seed();
+
+/**
+ * Returns a random integer in a range.
+ * @param a the bottom of the range
+ * @param b the top of the range
+ * &return a random number x having a <= x and x <= b
+ */
+int rand_int(int a, int b);
+
+#endif // UTILITIES_H