init
This commit is contained in:
65
src/Unit.h
Executable file
65
src/Unit.h
Executable file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (C) David Wolfe, 1999. All rights reserved.
|
||||
* Ported to Qt and adapted for TDDD86, 2015.
|
||||
* Updated for TDDD86, 2021.
|
||||
*/
|
||||
|
||||
#ifndef UNIT_H
|
||||
#define UNIT_H
|
||||
|
||||
#include "utilities.h"
|
||||
#include <QGraphicsScene>
|
||||
|
||||
/* Root class for all pieces on the board.
|
||||
* Subclasses are Robot, Hero and Junk.
|
||||
*/
|
||||
class Unit {
|
||||
public:
|
||||
|
||||
/*
|
||||
* Create a unit at a random position
|
||||
*/
|
||||
Unit();
|
||||
|
||||
/*
|
||||
* Create unit at given point
|
||||
*/
|
||||
Unit(const Point& p);
|
||||
|
||||
virtual ~Unit(){}
|
||||
|
||||
/*
|
||||
* Return Point representation of Unit
|
||||
*/
|
||||
Point asPoint() const;
|
||||
|
||||
/*
|
||||
* Am I in the same square as u?
|
||||
*/
|
||||
bool at(const Unit& u) const;
|
||||
|
||||
|
||||
/*
|
||||
* Take one step closer to point
|
||||
*/
|
||||
void moveTowards(const Point&);
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
Reference in New Issue
Block a user