Browse Source

Merge branch 'cell' of GooseHouse/game-client into dev

Ivan Arkhipov 6 năm trước cách đây
mục cha
commit
9c1f93d5bc

+ 1 - 0
include/Cell.h

@@ -1,6 +1,7 @@
 #pragma once
 #include <queue>
 #include <vector>
+#include <iostream>
 /*
  * Решили, что метод canAttackForDistance(int) имеет шаблон, который обозначает тип атаки
  * Melee - без учёта препятствий

+ 15 - 0
include/UnitsQueue.h

@@ -0,0 +1,15 @@
+#include <vector>
+
+class Unit;
+
+class UnitsQueue{
+private:
+    std::vector<Unit*> queue_;
+    typedef std::vector<Unit*>::iterator viterator;
+public:
+    void add(Unit*);
+    void remove(viterator);
+    void remove(Unit*);
+    viterator beginIterator();
+    viterator endIterator();
+};

+ 13 - 0
include/hotseatgame/GameManager.h

@@ -0,0 +1,13 @@
+#include <vector>
+
+class Cell;
+
+class GameManager{
+private:
+    std::vector< std::vector< Cell* > > game_table_;
+    int col_table_size_, row_table_size_;
+    void generate_table_();
+    void print_all();
+public:
+    GameManager(int, int);
+};

+ 3 - 0
source/Cell.cpp

@@ -1,3 +1,6 @@
+/*
+ * I love Qt
+ */
 #include "Cell.h"
 #include "unit.h"
 #include <string>

+ 33 - 0
source/UnitsQueue.cpp

@@ -0,0 +1,33 @@
+#include "UnitsQueue.h"
+#include <vector>
+#include <string>
+
+void UnitsQueue::add(Unit* unit){
+    queue_.push_back(unit);
+}
+
+void UnitsQueue::remove(viterator iter){
+    if (beginIterator() <= iter && iter < endIterator()){
+        queue_.erase(iter);
+        return;
+    }
+    throw std::string("Iterator is not in UnitsQueue");
+}
+
+void UnitsQueue::remove(Unit* unit){
+    for (viterator it = beginIterator(); it != endIterator();++it){
+        if( (*it) == unit){
+            remove(it);
+            return;
+        }
+    }
+    throw std::string("Unit* is not in UnitsQueue");
+}
+
+UnitsQueue::viterator UnitsQueue::beginIterator() {
+    return queue_.begin();
+}
+
+UnitsQueue::viterator UnitsQueue::endIterator(){
+    return queue_.end();
+}

+ 55 - 0
source/hotseatgame/GameManager.cpp

@@ -0,0 +1,55 @@
+/*
+ * Someone tells, that Qt can to build this
+ */
+#include "Cell.h"
+#include "GameManager.h"
+
+#include <iostream>
+
+GameManager::GameManager(int colSize, int rowSize):col_table_size_(colSize), row_table_size_(rowSize) {
+    generate_table_();
+}
+
+void GameManager::generate_table_() {
+    game_table_.assign(col_table_size_, std::vector< Cell* >(row_table_size_, nullptr));
+    for (int col = 0; col < col_table_size_; ++col) {
+        for (int row = 0; row < row_table_size_; ++row) {
+            game_table_[col][row] = new Cell(nullptr);
+        }
+    }
+    int isEven = 1;
+    for (int col = 0; col < col_table_size_; ++col) {
+        isEven ^= 1;
+        for (int row = 0; row < row_table_size_; ++row) {
+            if (col != 0 && row != 0 -isEven) {
+                game_table_[col][row]->setleftUp(game_table_[col - 1][row - 1 +isEven]);
+            }
+            if (row != 0) {
+                game_table_[col][row]->setleft(game_table_[col][row - 1]);
+            }
+            if (col != col_table_size_ - 1 && row != 0 -isEven) {
+                game_table_[col][row]->setleftDown(game_table_[col + 1][row - 1 +isEven]);
+            }
+
+            if (col != 0 && row != row_table_size_ -isEven) {
+                game_table_[col][row]->setrightUp(game_table_[col - 1][row +isEven]);
+            }
+            if (row != row_table_size_ - 1) {
+                game_table_[col][row]->setright(game_table_[col][row + 1]);
+            }
+            if (col != col_table_size_ - 1 && row != row_table_size_ -isEven) {
+                game_table_[col][row]->setrightDown(game_table_[col + 1][row +isEven]);
+            }
+        }
+    }
+}
+
+void GameManager::print_all() {
+    game_table_[0][0]->RecalculateTableWithCenterThisPoint();
+    for (int col = 0; col < col_table_size_; ++col) {
+        for (int row = 0; row < row_table_size_; ++row) {
+            game_table_[col][row]->print();
+        }
+        std::cout << std::endl;
+    }
+}