فهرست منبع

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

Ivan Arkhipov 6 سال پیش
والد
کامیت
8b1b179ad1
5فایلهای تغییر یافته به همراه77 افزوده شده و 15 حذف شده
  1. 6 2
      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

+ 6 - 2
client.pro

@@ -44,7 +44,9 @@ SOURCES += \
     source/gui/raceicon.cpp \
     source/playermanager.cpp \
     source/gui/prebattlescene.cpp \
-    source/Cell.cpp
+    source/Cell.cpp \
+    source/UnitsQueue.cpp \
+    source/hotseatgame/GameManager.cpp
 
 HEADERS += \
     include/gui/uniticon.h \
@@ -65,7 +67,9 @@ HEADERS += \
     include/gui/raceicon.h \
     include/playermanager.h \
     include/gui/prebattlescene.h \
-    include/Cell.h
+    include/Cell.h \
+    include/UnitsQueue.h \
+    include/hotseatgame/GameManager.h
 
 FORMS += \
     include/gui/gui.ui \

+ 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
- */
+* Someone tells, that Qt can to build this
+*/
+#include "include/hotseatgame/GameManager.h"
 #include "Cell.h"
-#include "GameManager.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::buildGameTable(int colSize, int rowSize){
+    col_table_size_ = colSize;
+    row_table_size_ = rowSize;
+    generateTable();
 }
 
-void GameManager::generate_table_() {
+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_);
+}