summaryrefslogtreecommitdiffstats
path: root/labb3/tiles/Tile.cpp
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2020-08-17 14:57:07 +0200
committerGustav Sörnäs <gusso230@student.liu.se>2020-08-17 14:57:07 +0200
commitd894e06c6e6a335ea672ca2aaf30066b0a9d077a (patch)
tree8fbea33bf6a8622e435aeedbc7c2a8b5b82204d9 /labb3/tiles/Tile.cpp
parentb1bf345edb518800d0cfeae97eceacf51985e7e7 (diff)
downloadtddd86-d894e06c6e6a335ea672ca2aaf30066b0a9d077a.tar.gz
add given files
Diffstat (limited to 'labb3/tiles/Tile.cpp')
-rw-r--r--labb3/tiles/Tile.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/labb3/tiles/Tile.cpp b/labb3/tiles/Tile.cpp
new file mode 100644
index 0000000..dc16cf6
--- /dev/null
+++ b/labb3/tiles/Tile.cpp
@@ -0,0 +1,31 @@
+/*
+ * TDDD86 Tiles
+ * This file contains the implementation of the Tile structure.
+ * See Tile.h for comments about each member.
+ * Your code should work properly with an unmodified version of this file.
+ */
+
+#include <QGraphicsRectItem>
+#include "Tile.h"
+
+bool Tile::contains(int x, int y) const {
+ return this->x <= x && x < this->x + this->width &&
+ this->y <= y && y < this->y + this->height;
+}
+
+void Tile::draw(QGraphicsScene *scene) const {
+ QGraphicsRectItem *item = new QGraphicsRectItem(x, y, width, height);
+ item->setBrush(QBrush(QColor(r, g, b)));
+ scene->addItem(item);
+}
+
+string Tile::toString() const {
+ return "Tile{x=" + to_string(x) + ",y=" + to_string(y)
+ + ",width=" + to_string(width) + ",height=" + to_string(height)
+ + ",r=" + to_string(r) + ",g=" +to_string (g) + ",b=" + to_string(b) + "}";
+}
+
+ostream& operator<<(ostream& out, const Tile& tile) {
+ out << tile.toString();
+ return out;
+}