Ver Fonte

added primal GameManager, added empty Cells print()

noath há 6 anos atrás
pai
commit
18b201c1b8
5 ficheiros alterados com 72 adições e 14 exclusões
  1. 1 1
      client.pro
  2. 1 0
      include/Cell.h
  3. 31 5
      include/hotseatgame/GameManager.h
  4. 5 0
      source/Cell.cpp
  5. 34 8
      source/hotseatgame/GameManager.cpp

+ 1 - 1
client.pro

@@ -45,7 +45,7 @@ SOURCES += \
     source/playermanager.cpp \
     source/gui/prebattlescene.cpp \
     source/Cell.cpp \
-    source/UnitsQueue.h \
+    source/UnitsQueue.cpp \
     source/hotseatgame/GameManager.cpp
 
 HEADERS += \

+ 1 - 0
include/Cell.h

@@ -145,4 +145,5 @@ public:
 	 * Gi1dor знает, что это такое
 	 */
 	Cell* getRealShootTarget(Cell*);
+    void print();
 };

+ 31 - 5
include/hotseatgame/GameManager.h

@@ -1,13 +1,39 @@
 #include <vector>
+#include <UnitsQueue.h>
+#include <playermanager.h>
+
 
 class Cell;
 
-class GameManager{
+class GameManager : public QObject
+{
 private:
     std::vector< std::vector< Cell* > > game_table_;
     int col_table_size_, row_table_size_;
-    void generate_table_();
-    void print_all();
+    void generateTable();
+    void printAll();
+
+    /******************************/
+    UnitsQueue turn_queue_;
+    PlayerManager* player_manager_;
+    int cur_player_id_;
+
 public:
-    GameManager(int, int);
-};
+    void buildGameTable(int, int);
+    static GameManager& getInstance() {
+        static GameManager instance;
+        return instance;
+    }
+    UnitsQueue* getTurnQueue();
+
+    void AddToUnitQueue(Unit* unit);
+
+    void RmFromUnitQueue(Unit* unit);
+
+    Player* getCurrentPlayer();
+
+    int getCurPlayerId();
+
+private:
+     explicit GameManager(QObject *parent = nullptr);
+};

+ 5 - 0
source/Cell.cpp

@@ -327,3 +327,8 @@ Cell* Cell::getRealShootTarget(Cell* next){
 		return getright();
 	}
 }
+
+void Cell::print(){
+    return;
+    //do nothing, need content
+}

+ 34 - 8
source/hotseatgame/GameManager.cpp

@@ -1,16 +1,22 @@
 /*
- * Someone tells, that Qt can to build this
- */
-#include "Cell.h"
+* Someone tells, that Qt can to build this
+*/
 #include "include/hotseatgame/GameManager.h"
-
+#include "Cell.h"
 #include <iostream>
 
-GameManager::GameManager(int colSize, int rowSize):col_table_size_(colSize), row_table_size_(rowSize) {
-    generate_table_();
+GameManager::GameManager(QObject *parent) : QObject(parent)
+{
+
 }
 
-void GameManager::generate_table_() {
+void GameManager::buildGameTable(int colSize, int rowSize){
+    col_table_size_ = colSize;
+    row_table_size_ = rowSize;
+    generateTable();
+}
+
+void GameManager::generateTable() {
     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) {
@@ -44,7 +50,7 @@ void GameManager::generate_table_() {
     }
 }
 
-void GameManager::print_all() {
+void GameManager::printAll() {
     game_table_[0][0]->RecalculateTableWithCenterThisPoint();
     for (int col = 0; col < col_table_size_; ++col) {
         for (int row = 0; row < row_table_size_; ++row) {
@@ -53,3 +59,23 @@ void GameManager::print_all() {
         std::cout << std::endl;
     }
 }
+
+UnitsQueue* GameManager::getTurnQueue(){
+    return &turn_queue_;
+}
+
+void GameManager::AddToUnitQueue(Unit* unit){
+    turn_queue_.add(unit);
+}
+
+void GameManager::RmFromUnitQueue(Unit* unit){
+    turn_queue_.remove(unit);
+}
+
+int GameManager::getCurPlayerId(){
+    return cur_player_id_;
+};
+
+Player* GameManager::getCurrentPlayer(){
+    return player_manager_->getPlayer(cur_player_id_);
+}