Przeglądaj źródła

Deleted Debug Constants. Dont see last commit

GeorgeKolog 6 lat temu
rodzic
commit
4c2a957b5d
2 zmienionych plików z 102 dodań i 150 usunięć
  1. 69 114
      Cell.cpp
  2. 33 36
      Cell.h

+ 69 - 114
Cell.cpp

@@ -1,67 +1,56 @@
 #include "Cell.h"
-//#include "unit.h"
+#include "unit.h"
 #include <queue>
 #include <vector>
 
-/*
- * Добавьте в Unit эту функцию
- */
-class Unit {
-public:
-	bool canAttackForDistance(int) { return true; }
-	bool canAttackUnit(Unit*) { return true; }
-};
-
 Cell::Cell(Unit * character) {
-	left_up_ = left_ = left_down_ = nullptr;
-	right_up_ = right_ = right_down_ = nullptr;
-	character_ = character;
+	leftUp_ = left_ = leftDown_ = nullptr;
+	rightUp_ = right_ = rightDown_ = nullptr;
+	character_ = &character;
 	clearCell_();
 	AddedToQuery_ = true;
 }
 
-Cell::Cell(int i, int j) :i(i), j(j), AddedToQuery_(true) {}
-
-Cell * Cell::getLeftUp() {
-	return left_up_;
+Cell * Cell::getleftUp() {
+	return leftUp_;
 }
-void Cell::setLeftUp(Cell * t) {
-	left_up_ = t;
+void Cell::setleftUp(Cell * t) {
+	leftUp_ = t;
 }
 
-Cell * Cell::getLeft() {
+Cell * Cell::getleft() {
 	return left_;
 }
-void Cell::setLeft(Cell * t) {
+void Cell::setleft(Cell * t) {
 	left_ = t;
 }
 
-Cell * Cell::getLeftDown() {
-	return left_down_;
+Cell * Cell::getleftDown() {
+	return leftDown_;
 }
-void Cell::setLeftDown(Cell * t) {
-	left_down_ = t;
+void Cell::setleftDown(Cell * t) {
+	leftDown_ = t;
 }
 
-Cell * Cell::getRightUp() {
-	return right_up_;
+Cell * Cell::getrightUp() {
+	return rightUp_;
 }
-void Cell::setRightUp(Cell * t) {
-	right_up_ = t;
+void Cell::setrightUp(Cell * t) {
+	rightUp_ = t;
 }
 
-Cell * Cell::getRight() {
+Cell * Cell::getright() {
 	return right_;
 }
-void Cell::setRight(Cell * t) {
+void Cell::setright(Cell * t) {
 	right_ = t;
 }
 
-Cell * Cell::getRightDown() {
-	return right_down_;
+Cell * Cell::getrightDown() {
+	return rightDown_;
 }
-void Cell::setRightDown(Cell * t) {
-	right_down_ = t;
+void Cell::setrightDown(Cell * t) {
+	rightDown_ = t;
 }
 
 Unit * Cell::getCharacter() {
@@ -71,17 +60,17 @@ void Cell::setCharacter(Unit * t) {
 	character_ = t;
 }
 
-bool Cell::getIsMoveable() {
+bool Cell::getisMoveable() {
 	return isMoveable_;
 }
-void Cell::setIsMoveable(bool t) {
+void Cell::setisMoveable(bool t) {
 	isMoveable_ = t;
 }
 
-bool Cell::getIsAttackable() {
+bool Cell::getisAttackable() {
 	return isAttackable_;
 }
-void Cell::setIsAttackable(bool t) {
+void Cell::setisAttackable(bool t) {
 	isAttackable_ = t;
 }
 
@@ -97,17 +86,15 @@ bool Cell::isEmpty() {
 }
 
 void Cell::clearCell_() {
-	setIsMoveable(false);
+	setisMoveable(false);
+	setisAttackable(false);
 	setDistance(-1);
 }
 
-void Cell::clearTable_(bool NeedClearCell = true) {
+void Cell::clearTable_() {
 	std::queue<Cell*> q;
 	q.push(this);
-	setIsAttackable(false);
-	if (NeedClearCell) {
-		clearCell_();
-	}
+	clearCell_();
 	this->AddedToQuery_ = false;
 	auto f = [&q](Cell * t) {
 		if (t && t->AddedToQuery_ == true) {
@@ -118,16 +105,13 @@ void Cell::clearTable_(bool NeedClearCell = true) {
 	while (!q.empty()) {
 		Cell * Now = q.front();
 		q.pop();
-		Now->setIsAttackable(false);
-		if (NeedClearCell) {
-			Now->clearCell_();
-		}
-		f(Now->getLeftUp());
-		f(Now->getLeft());
-		f(Now->getLeftDown());
-		f(Now->getRightUp());
-		f(Now->getRight());
-		f(Now->getRightDown());
+		Now->clearCell_();
+		f(Now->getleftUp());
+		f(Now->getleft());
+		f(Now->getleftDown());
+		f(Now->getrightUp());
+		f(Now->getright());
+		f(Now->getrightDown());
 	}
 }
 
@@ -135,38 +119,34 @@ void Cell::handleAllMoveableCellsAndUnmoveableCells_(std::queue<Cell*> & Q) {
 	std::queue<Cell*> q;
 	q.push(this);
 	setDistance(0);
-	AddedToQuery_ = true;
-	setIsMoveable(true);
-	setIsAttackable(true);
 	auto f = [&q, &Q](Cell * t, Cell * parent) {
 		if (t && !t->AddedToQuery_) {
 			t->AddedToQuery_ = true;
-			t->setDistance(parent->getDistance() + 1);
 			if (t->getCharacter() != NULL) {
-				t->setIsMoveable(false);
+				t->setisMoveable(false);
 				Q.push(t);
 				return;
 			}
 			q.push(t);
+			t->setDistance(parent->getDistance() + 1);
 		}
 	};
 	while (!q.empty()) {
 		Cell * Now = q.front();
-		Now->setIsMoveable(true);
-		if (getCharacter() != NULL && getCharacter()->canAttackForDistance(Now->getDistance()) &&
-			(Now->getCharacter() == NULL || getCharacter()->canAttackUnit(Now->getCharacter()))) {
-			Now->setIsAttackable(true);
+		Now->setisMoveable(true);
+		if (getCharacter() != NULL && getCharacter()->СanAttack(Now->getDistance())) {
+			Now->setisAttackable(true);
 		}
 		else {
-			Now->setIsAttackable(false);
+			Now->setisAttackable(false);
 		}
 		q.pop();
-		f(Now->getLeftUp(), Now);
-		f(Now->getLeft(), Now);
-		f(Now->getLeftDown(), Now);
-		f(Now->getRightUp(), Now);
-		f(Now->getRight(), Now);
-		f(Now->getRightDown(), Now);
+		f(Now->getleftUp(), Now);
+		f(Now->getleft(), Now);
+		f(Now->getleftDown(), Now);
+		f(Now->getrightUp(), Now);
+		f(Now->getright(), Now);
+		f(Now->getrightDown(), Now);
 	}
 }
 
@@ -174,71 +154,46 @@ void Cell::handleAllUnmoveableCells_(std::queue<Cell*> & Q) {
 	auto f = [&Q](Cell * t, Cell * parent) {
 		if (t && !t->AddedToQuery_) {
 			t->AddedToQuery_ = true;
-			t->setDistance(parent->getDistance() + 1);
 			Q.push(t);
 		}
 	};
 	while (!Q.empty()) {
 		Cell * Now = Q.front();
-		Now->setIsMoveable(false);
-		Now->setIsAttackable(false);
+		Now->setisMoveable(false);
+		Now->setisAttackable(false);
 		Q.pop();
-		f(Now->getLeftUp(), Now);
-		f(Now->getLeft(), Now);
-		f(Now->getLeftDown(), Now);
-		f(Now->getRightUp(), Now);
-		f(Now->getRight(), Now);
-		f(Now->getRightDown(), Now);
+		f(Now->getleftUp(), Now);
+		f(Now->getleft(), Now);
+		f(Now->getleftDown(), Now);
+		f(Now->getrightUp(), Now);
+		f(Now->getright(), Now);
+		f(Now->getrightDown(), Now);
 	}
 }
 
-void Cell::recalculateTableWithCenterThisPoint() {
+void Cell::RecalculateTableWithCenterThisPoint() {
 	clearTable_();
 	std::queue<Cell*> qWithoutMoveable;
 	handleAllMoveableCellsAndUnmoveableCells_(qWithoutMoveable);
 	handleAllUnmoveableCells_(qWithoutMoveable);
 }
 
-void Cell::buffTableinDistance(int distance) {
-	clearTable_(false);
-	std::queue<Cell*> q;
-	q.push(this);
-	setIsAttackable(true);
-	auto f = [&q, &distance](Cell * Now) {
-		if (Now != NULL && Now->getDistance() <= distance && !Now->AddedToQuery_) {
-			q.push(Now);
-			Now->AddedToQuery_ = true;
-			Now->setIsAttackable(true);
-		}
-	};
-	while (!q.empty()) {
-		Cell * Now = q.front();
-		q.pop();
-		f(Now->getLeftUp());
-		f(Now->getLeft());
-		f(Now->getLeftDown());
-		f(Now->getRightUp());
-		f(Now->getRight());
-		f(Now->getRightDown());
-	}
-}
-
-std::vector <Cell*> Cell::actualPath(Cell* to) {
-	if (!to || !to->getIsMoveable())return std::vector<Cell*>();
+std::vector <Cell*> Cell::actualPath(Cell* to) {//std::vector<Cell*> âêëþ÷àåòñÿ â ñåáÿ è this, è end
+	if (!to || !to->getisMoveable())return std::vector<Cell*>();
 	auto ret = std::vector<Cell*>(1, to);
 	while (to != this) {
 		Cell * parent = NULL;
 		auto f = [&parent](Cell * TestParent, Cell * Now) {
-			if (TestParent && TestParent->getDistance() + 1 == Now->getDistance() && TestParent->getIsMoveable()) {
+			if (TestParent && TestParent->getDistance() + 1 == Now->getDistance() && TestParent->getisMoveable()) {
 				parent = TestParent;
 			}
 		};
-		f(to->getLeftUp(), to);
-		f(to->getLeft(), to);
-		f(to->getLeftDown(), to);
-		f(to->getRightUp(), to);
-		f(to->getRight(), to);
-		f(to->getRightDown(), to);
+		f(to->getleftUp(), to);
+		f(to->getleft(), to);
+		f(to->getleftDown(), to);
+		f(to->getrightUp(), to);
+		f(to->getright(), to);
+		f(to->getrightDown(), to);
 		to = parent;
 		ret.push_back(to);
 	}

+ 33 - 36
Cell.h

@@ -5,15 +5,15 @@
 class Unit;
 
 class Cell {
-	int i, j;
+
 private:
-	Cell * left_up_;
+	Cell * leftUp_;
 	Cell *left_;
-	Cell * left_down_;
+	Cell * leftDown_;
 
-	Cell *right_up_;
+	Cell *rightUp_;
 	Cell *right_;
-	Cell *right_down_;
+	Cell *rightDown_;
 
 	Unit *character_;
 
@@ -23,7 +23,7 @@ private:
 	int distance_;
 	bool AddedToQuery_;
 
-	void clearTable_(bool);
+	void clearTable_();
 	void clearCell_();
 
 	void handleAllMoveableCellsAndUnmoveableCells_(std::queue<Cell*> & Q);
@@ -33,41 +33,38 @@ public:
 
 	explicit Cell(Unit * character);
 
-	explicit Cell(int, int);
-
-	Cell * getLeftUp();
-	void setLeftUp(Cell *);
-
-	Cell * getLeft();
-	void setLeft(Cell *);
-
-	Cell * getLeftDown();
-	void setLeftDown(Cell *);
-
-	Cell * getRightUp();
-	void setRightUp(Cell *);
-
-	Cell * getRight();
-	void setRight(Cell *);
-
-	Cell * getRightDown();
-	void setRightDown(Cell *);
-
+	Cell * getleftUp();
+	void setleftUp(Cell *);
+
+	Cell * getleft();
+	void setleft(Cell *);
+	
+	Cell * getleftDown();
+	void setleftDown(Cell *);
+	
+	Cell * getrightUp();
+	void setrightUp(Cell *);
+	
+	Cell * getright();
+	void setright(Cell *);
+	
+	Cell * getrightDown();
+	void setrightDown(Cell *);
+	
 	Unit * getCharacter();
 	void setCharacter(Unit *);
-
-	bool getIsMoveable();
-	void setIsMoveable(bool);
-
-	bool getIsAttackable();
-	void setIsAttackable(bool);
-
+	
+	bool getisMoveable();
+	void setisMoveable(bool);
+	
+	bool getisAttackable();
+	void setisAttackable(bool);
+	
 	int getDistance();
 	void setDistance(int);
-
+	
 	bool isEmpty();
 
-	void recalculateTableWithCenterThisPoint();
-	void buffTableinDistance(int);
+	void RecalculateTableWithCenterThisPoint();
 	std::vector <Cell*> actualPath(Cell*);
 };