summaryrefslogtreecommitdiffstats
path: root/labb4/Unit.h
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/Unit.h
parent209bc7540a97bb238e70b9f9e248a0a0c756a4c0 (diff)
downloadtddd86-6a72f2f15c9f39b2a851b955b9b87abede8d0257.tar.gz
initial work
Diffstat (limited to 'labb4/Unit.h')
-rw-r--r--labb4/Unit.h60
1 files changed, 60 insertions, 0 deletions
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