From 3686258d2fa6fdffebb57f7d530952fd4dabf366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 21 Sep 2020 16:13:25 +0200 Subject: Given files L4 --- labb4/Unit.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 labb4/Unit.h (limited to 'labb4/Unit.h') 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 -- cgit v1.2.1