Bladeren bron

last personal traits

noath 6 jaren geleden
bovenliggende
commit
5d3d09c298
2 gewijzigde bestanden met toevoegingen van 89 en 43 verwijderingen
  1. 37 30
      unit.cpp
  2. 52 13
      unit.h

+ 37 - 30
unit.cpp

@@ -28,20 +28,6 @@ void Unit::setHealthPoints(double value) {
 	health_points_ = value;
 }
 
-double Unit::getManaPoints() {
-	return mana_points_;
-}
-void Unit::setManaPoints(double value) {
-	mana_points_ = value;
-}
-
-double Unit::getEnergyPoints() {
-	return energy_points_;
-}
-void Unit::setEnergyPoints(double value) {
-	energy_points_ = value;
-}
-
 double Unit::getAttackRange() {
 	return attack_range_;
 }
@@ -49,6 +35,13 @@ void Unit::setAttackRange(double value) {
 	attack_range_ = value;
 }
 
+int Unit::getActivityPoints(){
+	return activity_points_;
+}
+void Unit::setActivityPoints(int value){
+	activity_points_ = value;
+}
+
 Cell* Unit::getLocation() {
 	return location_;
 }
@@ -56,11 +49,18 @@ void Unit::setLocation(Cell* to) {
 	location_ = to;
 }
 
-int Unit::getMovementPoints() {
-	return movement_points_;
+int Unit::getMovementSpeed() {
+	return movement_speed_;
 }
-void Unit::setMovementPoints(int value) {
-	movement_points_ = value;
+void Unit::setMovementSpeed(int value) {
+	movement_speed_ = value;
+}
+
+int Unit::getAttackSpeed(){
+	return attack_speed_;
+}
+void Unit::setAttackSpeed(int value){
+	attack_speed_ = value;
 }
 
 double Unit::getInitiative() {
@@ -98,6 +98,13 @@ void Unit::setAgility(double value) {
 	agility_ = value;
 }
 
+int Unit::getAttackPoints(){
+	return attack_speed_;
+}
+void Unit::setAttackPoints(int value){
+	attack_speed_ = value;
+}
+
 double Unit::getMagicDefence() {
 	return magic_defence_;
 }
@@ -155,27 +162,27 @@ int Unit::lenOfActualPath(Cell* destination) {
 }
 
 bool Unit::canMoveForDistance(int distance) {
-	return (movement_points_ >= distance);
+	return (movement_speed_ >= distance);
 }
 
 bool Unit::canMoveToCell(Cell* destination) {
-	return (destination->isEmpty() && canMoveForDistance(lenOfActualPath(destination)));
-}
+	return (destination->isEmpty() && lenOfActualPath(destination) > 0 && canMoveForDistance(lenOfActualPath(destination)));
+}	
 
 void Unit::moveToCell(Cell* destination) {
-	if (!canMoveToCell)
+	if (!canMoveToCell(destination))
 		return;	//here could be a gui-message about failed move (x-mark, for example)
 	else {
-		int decreasedValue = getMovementPoints() - lenOfActualPath(destination);
-		setMovementPoints(decreasedValue);
+		int decreasedValue = getMovementSpeed() - lenOfActualPath(destination);
+		setMovementSpeed(decreasedValue);
 		setLocation(destination);
 	}
 }
 
+int main() {
+	std::cout << "Hello, world!\n";
+}
 
-
-/*bool canAttack(int distance) {
-
-}*/
-
-//TODO: real_x_, real_y_
+bool MeleeUnit::canAttackForDistance(int distance) {	
+//	if 
+}

+ 52 - 13
unit.h

@@ -30,10 +30,11 @@ private:
 
 	//actions and events
 	double initiative_;
+	int activity_points_;
 
 	//movement
 	Cell* location_;
-	double movement_points_; //how many cells can move for one activity point
+	int movement_speed_;	//how many cells can move for one activity point
 	double real_x_;
 	double real_y_;
 
@@ -41,10 +42,9 @@ private:
 	double agility_;
 	double attack_range_;
 	double damage_per_hit_;
-	double energy_points_;  //for physical attacks
 	double intelligence_;
-	double mana_points_;    //for magic attacks
 	double strength_;
+	int attack_cost_;     //how many activity points does attack cost
 
 	//durability
 	double health_points_;
@@ -64,20 +64,20 @@ public:
 	double getHealthPoints();
 	void setHealthPoints(double value);
 
-	double getManaPoints();
-	void setManaPoints(double value);
-
-	double getEnergyPoints();
-	void setEnergyPoints(double value);
-
 	double getAttackRange();
 	void setAttackRange(double value);
 
+	int getActivityPoints();
+	void setActivityPoints(int value);
+
 	Cell* getLocation();
 	void setLocation(Cell* to);
 
-	int getMovementPoints();
-	void setMovementPoints(int value);
+	int getMovementSpeed();
+	void setMovementSpeed(int value);
+
+	int getAttackCost();
+	void setAttackCost(int value);
 
 	double getInitiative();
 	void setInitiative(double value);
@@ -94,6 +94,9 @@ public:
 	double getAgility();
 	void setAgility(double value);
 
+	int getAttackPoints();
+	void setAttackPoints(int value);
+
 	double getMagicDefence();
 	void setMagicDefence(double value);
 
@@ -121,5 +124,41 @@ public:
 
 	virtual void moveToCell(Cell* destination);
 	
-//	bool canAttackForDistance(int distance);
-};
+	virtual	bool canAttackForDistance(int distance) = 0;
+
+	virtual bool canAttackToCell(Cell* destination) = 0;
+
+	virtual bool canAttackUnit(Unit* target) = 0;
+};
+
+class MeleeUnit : public Unit {
+protected:
+private:
+
+public:
+	virtual ~MeleeUnit() = delete;
+
+	virtual	bool canAttackForDistance(int distance);
+
+	virtual bool canAttackToCell(Cell* destination);
+
+	virtual bool canAttackUnit(Unit* target);
+
+};
+
+class RangeUnit : public Unit {
+protected:
+private:
+
+public:
+	virtual ~RangeUnit() = delete;
+};
+
+template <class Base>
+class AbstractUnitCreator {
+public:
+	AbstractUnitCreator() {}
+	virtual ~AbstractUnitCreator() {}
+	virtual Base* create() const = 0;
+};
+