Browse Source

Merge branch 'dev' into gui

Ivan Arkhipov 6 years ago
parent
commit
68b7bc3ef4
4 changed files with 44 additions and 26 deletions
  1. 4 5
      include/cell.h
  2. 4 6
      include/hotseatgame/gamemanager.h
  3. 19 10
      source/cell.cpp
  4. 17 5
      source/hotseatgame/gamemanager.cpp

+ 4 - 5
include/cell.h

@@ -3,7 +3,7 @@
 #include <vector>
 #include <memory>
 #include <iostream>
-
+#include <list>
 /*
  * Решили, что метод canAttackForDistance(int) имеет шаблон, который обозначает тип атаки
  * Melee - без учёта препятствий
@@ -85,8 +85,7 @@ private:
 	void updateUnMovealeCells_(std::queue<Cell *> &Q);
 
 public:
-    explicit Cell(double coor_x, double coor_y);
-    explicit Cell(std::shared_ptr<Unit> character, double coor_x, double coor_y);
+    explicit Cell();
 	/*
 	 * Геттеры и сеттеры соседних клеток и персонажа
 	 */
@@ -156,6 +155,6 @@ public:
 	 * Выполнится только с лучае, если эта следующая клетка существует
 	 * Gi1dor знает, что это такое
 	 */
-	Cell* getRealShootTarget(Cell*);
-    void print();
+    std::vector<std::pair<double, double> > getPoints(double, double);
+    Cell* getRealShootTarget(Cell*);
 };

+ 4 - 6
include/hotseatgame/gamemanager.h

@@ -1,13 +1,15 @@
+#pragma once
 #include <vector>
 #include <hotseatgame/unitsqueue.h>
 #include <playermanager.h>
 
-
 class Cell;
 
 class GameManager : public QObject
 {
-public:    
+public:
+    void buildGameTable(int, int);
+
     static GameManager& getInstance() {
         static GameManager instance;
         return instance;
@@ -26,8 +28,6 @@ public:
 
     int getCurPlayerId();
 
-private:
-
 private:
     explicit GameManager(QObject *parent = nullptr);
 
@@ -37,8 +37,6 @@ private:
 
     void generateTable();
 
-    void printAll();
-
     /******************************/
     UnitsQueue turn_queue_;
     PlayerManager* player_manager_;

+ 19 - 10
source/cell.cpp

@@ -8,6 +8,7 @@
 #include <vector>
 #include <map>
 #include <iostream>
+#include <cmath>
 
 class EffectsForCell{
 public:
@@ -22,7 +23,7 @@ Cell::Cell()
     clearCell_();
     AddedToQuery_ = true;
     col_ = row_ = 0;
-    coor_x_ = coor_y_ = 0;
+    coor_x_ = coor_y_ = -1;
 }
 
 Cell * Cell::getleftUp() {
@@ -61,10 +62,10 @@ Cell * Cell::getrightDown() {
 void Cell::setrightDown(Cell * t) {
 	rightDown_ = t;
 }
-Unit * Cell::getCharacter() {
+std::shared_ptr<Unit> Cell::getCharacter() {
 	return character_;
 }
-void Cell::setCharacter(Unit * t) {
+void Cell::setCharacter(std::shared_ptr<Unit> t) {
     character_ = t;
 }
 
@@ -82,8 +83,7 @@ double Cell::getYCoordinate() {
     return coor_y_;
 }
 
-void Cell::setXCoordinate(double coordinate)
-{
+void Cell::setYCoordinate(double coordinate) {
     coor_y_ = coordinate;
 }
 
@@ -224,7 +224,7 @@ void Cell::clearTable_() {
 }
 
 void Cell::recalcAttackable_(Cell * Now,bool isReached){
-   /* if(Now == nullptr)return;
+    if(Now == nullptr)return;
     if (!isEmpty() && !Now->isEmpty() &&
         getCharacter()->canAttackForDistance("Melee", Now->getdistance_barrier())
             ) {
@@ -234,7 +234,7 @@ void Cell::recalcAttackable_(Cell * Now,bool isReached){
         getCharacter()->canAttackForDistance("Range", Now->getdistance_barrier())
             ) {
         Now->setisRangeAttackAble(true);
-    }*/
+    }
     return;
 }
 
@@ -281,6 +281,7 @@ void Cell::updateMoveableCells_(std::queue<Cell*> & Q) {
 void Cell::updateUnMovealeCells_(std::queue<Cell*> & Q) {
 	auto f = [&Q](Cell * t, Cell * parent) {
 		if (t && !t->AddedToQuery_) {
+            parent->getCharacter();
 			t->AddedToQuery_ = true;
 			Q.push(t);
 		}
@@ -350,7 +351,15 @@ Cell* Cell::getRealShootTarget(Cell* next){
 	}
 }
 
-void Cell::print(){
-    return;
-    //do nothing, need content
+std::vector<std::pair<double, double> > Cell::getPoints(double radius, double start_angle) {
+    const double delta_radians = acos(-1) / 180.0;
+    std::vector<std::pair<double, double> > res;
+    std::vector<double> angles = {0, 60, 120, 180, 240, 300};
+    for(size_t i = 0;i < angles.size();++i){
+        angles[i] += start_angle;
+        res.push_back({coor_x_ + radius * std::cos(angles[i] * delta_radians),
+                       coor_y_ + radius * std::sin(angles[i] * delta_radians)});
+    }
+    return res;
 }
+

+ 17 - 5
source/hotseatgame/gamemanager.cpp

@@ -51,15 +51,27 @@ void GameManager::generateTable() {
             }
         }
     }
-}
 
-void GameManager::printAll() {
-    game_table_[0][0]->RecalculateTableWithCenterThisPoint();
+    game_table_[0][0]->setXCoordinate(start_x_coordinate_);
+    game_table_[0][0]->setYCoordinate(start_y_coordinate_);
+
     for (int col = 0; col < col_table_size_; ++col) {
         for (int row = 0; row < row_table_size_; ++row) {
-            game_table_[col][row]->print();
+            auto cell = game_table_[col][row];
+
+            double center_x = cell->getXCoordinate();
+            double center_y = cell->getYCoordinate();
+
+            if (center_x == -1 && center_y == -1)
+                continue;
+
+            auto verticles = cell->getPoints(cell_radius_, 0.0);
+
+            if (cell->getleft() && cell->getleft()->getXCoordinate() == -1 && cell->getleft()->getYCoordinate() == -1) {
+                cell->getleft()->setXCoordinate(center_x + 2 * (verticles[0].first - center_x));
+                cell->getleft()->setYCoordinate(center_y + 2 * (verticles[0].second - center_y));
+            }
         }
-        std::cout << std::endl;
     }
 }