summaryrefslogtreecommitdiffstats
path: root/labb4/Unit.h
diff options
context:
space:
mode:
Diffstat (limited to 'labb4/Unit.h')
-rw-r--r--labb4/Unit.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/labb4/Unit.h b/labb4/Unit.h
new file mode 100644
index 0000000..1de5687
--- /dev/null
+++ b/labb4/Unit.h
@@ -0,0 +1,57 @@
+/**
+ * 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?
+ */
+ bool attacks(const Unit& u) const;
+
+ /*
+ * Take one step closer to u
+ */
+ void moveTowards(const Unit& u);
+
+ /*
+ * 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