-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
666 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#pragma once | ||
#include <string> | ||
#include "Enums.h" | ||
#include "Structs.h" | ||
|
||
class CellClass { | ||
|
||
private: | ||
|
||
CellType type_; | ||
double passability_; | ||
std::string belonging_; | ||
double influence_; | ||
Tower tower_; | ||
Resource resource_; | ||
|
||
|
||
public: | ||
CellClass() : type_(Field), passability_(1.0), belonging_("-"), influence_(0.0), tower_(), resource_() {}; // default constructor | ||
|
||
CellClass(CellClass&& moveField) noexcept { | ||
|
||
this->type_ = moveField.type_; | ||
this->passability_ = moveField.passability_; | ||
this->belonging_ = moveField.belonging_; | ||
this->influence_ = moveField.influence_; | ||
this->tower_ = moveField.tower_; | ||
this->resource_ = moveField.resource_; | ||
|
||
moveField.type_ = Empty; | ||
moveField.passability_ = 0; | ||
moveField.belonging_ = "-"; | ||
moveField.influence_ = 0; | ||
moveField.tower_.towerExistence = NotExists; | ||
moveField.tower_.towerLevel = Zero; | ||
moveField.resource_.resourceExistence = NotExists; | ||
moveField.resource_.resourceProductionRate = None; | ||
moveField.resource_.resourceType = NoResource; | ||
}; // move constructor | ||
|
||
CellClass(const CellClass& copyFiled) { | ||
|
||
type_ = copyFiled.type_; | ||
passability_ = copyFiled.passability_; | ||
influence_ = copyFiled.influence_; | ||
tower_ = copyFiled.tower_; | ||
resource_ = copyFiled.resource_; | ||
}; // copy constructor | ||
|
||
CellType getCellType() { | ||
return this->type_; | ||
} | ||
|
||
double getPassability() { | ||
return this->passability_; | ||
} | ||
|
||
void setBelonging(std::string belonging) { | ||
this->belonging_ = belonging; | ||
} | ||
|
||
std::string getBelonging() const { | ||
return this->belonging_; | ||
} | ||
|
||
void setInfluence(double influence) { | ||
this->influence_ = influence; | ||
} | ||
|
||
double getInfluence() { | ||
return this->influence_; | ||
} | ||
|
||
void setTower(Tower tower) { | ||
this->tower_.towerExistence = tower.towerExistence; | ||
this->tower_.towerLevel = tower.towerLevel; | ||
} | ||
|
||
Tower getTower() { | ||
return this->tower_; | ||
} | ||
|
||
void setResource(Resource resource) { | ||
this->resource_.resourceExistence = resource.resourceExistence; | ||
this->resource_.resourceProductionRate = resource.resourceProductionRate; | ||
this->resource_.resourceType = resource.resourceType; | ||
} | ||
|
||
Resource getResource() { | ||
return this->resource_; | ||
} | ||
|
||
void generateRandomCellType() { | ||
int randomNumber = rand() % 4 + 1; | ||
switch (randomNumber) | ||
{ | ||
case 1: | ||
this->type_ = Field; | ||
break; | ||
case 2: | ||
this->type_ = Swamp; | ||
break; | ||
case 3: | ||
this->type_ = Elevation; | ||
break; | ||
case 4: | ||
this->type_ = Mountain; | ||
break; | ||
default: | ||
this->type_ = Field; | ||
break; | ||
} | ||
} | ||
|
||
double generateRandomPassability() { | ||
int randomNumber = rand() % 1000; | ||
this->passability_ = static_cast<double>(randomNumber) / 100; | ||
return this->passability_; | ||
} | ||
|
||
void generateTower() { | ||
this->tower_.towerExistence = NotExists; | ||
this->tower_.towerLevel = Zero; | ||
} | ||
|
||
void generateRandomResource() { | ||
int randomNumberExist = rand() % 2; | ||
switch (randomNumberExist) | ||
{ | ||
case 0: | ||
this->resource_.resourceExistence = NotExists; | ||
break; | ||
case 1: | ||
this->resource_.resourceExistence = Exists; | ||
break; | ||
default: | ||
this->resource_.resourceExistence = NotExists; | ||
break; | ||
} | ||
|
||
int randomNumberResType = rand() % 4; | ||
switch (randomNumberResType) | ||
{ | ||
case 0: | ||
this->resource_.resourceType = NoResource; | ||
break; | ||
case 1: | ||
this->resource_.resourceType = Wood; | ||
break; | ||
case 2: | ||
this->resource_.resourceType = Gold; | ||
break; | ||
case 3: | ||
this->resource_.resourceType = Stone; | ||
break; | ||
default: | ||
this->resource_.resourceType = NoResource; | ||
break; | ||
} | ||
|
||
this->resource_.resourceProductionRate = None; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
enum CellType { | ||
|
||
Empty, | ||
Field, | ||
Swamp, | ||
Elevation, | ||
Mountain | ||
}; | ||
|
||
enum Existence { | ||
|
||
NotExists, | ||
Exists | ||
}; | ||
|
||
enum TowerLevel { | ||
|
||
Zero, | ||
First, | ||
Second, | ||
Third | ||
}; | ||
|
||
enum ResourceType { | ||
|
||
NoResource, | ||
Wood, | ||
Gold, | ||
Stone | ||
}; | ||
|
||
enum ResourceProductionRate { | ||
|
||
None, | ||
Low, | ||
Midium, | ||
High | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
void main() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
#include "Cell.h" | ||
#include "Player.h" | ||
#include "Fraction.h" | ||
#include <iostream> | ||
|
||
class FieldClass { | ||
|
||
private: | ||
int rows_, cols_; | ||
|
||
std::vector<std::vector<CellClass>> cells_; | ||
std::vector<PlayerClass> players_; | ||
std::vector<FractionClass> fractions_; | ||
|
||
static FieldClass* fieldClassInstance; | ||
|
||
FieldClass(int rows, int cols) : rows_(rows), cols_(cols) { | ||
cells_.resize(rows_); | ||
for (int i = 0; i < rows_; i++) { | ||
cells_[i].resize(cols_); | ||
for (int j = 0; j < cols_; j++) { | ||
cells_[i][j].generateRandomCellType(); | ||
cells_[i][j].generateRandomPassability(); | ||
cells_[i][j].setBelonging("-"); | ||
cells_[i][j].setInfluence(0); | ||
cells_[i][j].generateTower(); | ||
cells_[i][j].generateRandomResource(); | ||
} | ||
} | ||
}; | ||
|
||
FieldClass(const FieldClass& obj) = delete; | ||
|
||
public: | ||
FieldClass& operator = (const FieldClass& obj) = delete; | ||
|
||
static FieldClass* getInstance(int rows, int cols) { | ||
|
||
if (fieldClassInstance == nullptr) { | ||
fieldClassInstance = new FieldClass(rows, cols); | ||
return fieldClassInstance; | ||
} | ||
else { | ||
return fieldClassInstance; | ||
} | ||
} | ||
|
||
//void generatePlayers() { | ||
|
||
// int rowsNumber = cells_.size(); | ||
// int colsNumber = cells_[0].size(); | ||
// int cellsNumber = rowsNumber * colsNumber; | ||
|
||
// if (cellsNumber <= 10) { | ||
// players_.resize(2); | ||
// } | ||
// else if (cellsNumber > 10 && cellsNumber <= 20) { | ||
// players_.resize(4); | ||
// } | ||
// else if (cellsNumber > 20 && cellsNumber <= 30) { | ||
// players_.resize(6); | ||
// } | ||
//} | ||
|
||
//void generateFractions() { | ||
// int playersNumber = players_.size(); | ||
// if (playersNumber <= 2) { | ||
// fractions_.resize(2); | ||
// } | ||
// else if (playersNumber > 2 && playersNumber <= 8) { | ||
// fractions_.resize(4); | ||
// } | ||
// else if (playersNumber > 8) { | ||
// fractions_.resize(7); | ||
// } | ||
//} | ||
|
||
void createPlayers(int number) { | ||
players_.resize(number); | ||
} | ||
|
||
void createFructions(int number) { | ||
fractions_.resize(number); | ||
} | ||
|
||
FieldClass& generateField(int cellsNumber, int playersNumber, int fractionsNumber, int rows, int cols) { | ||
FieldClass& newField = *FieldClass::getInstance(rows, cols); | ||
newField.cells_.resize(rows); | ||
for (int i = 0; i < rows; i++) { | ||
newField.cells_[i].resize(cols); | ||
for (int j = 0; j < cols; j++) { | ||
newField.cells_[i][j].generateRandomCellType(); | ||
newField.cells_[i][j].generateRandomPassability(); | ||
newField.cells_[i][j].setBelonging("-"); | ||
newField.cells_[i][j].setInfluence(0); | ||
newField.cells_[i][j].generateTower(); | ||
newField.cells_[i][j].generateRandomResource(); | ||
} | ||
} | ||
newField.createPlayers(playersNumber); | ||
newField.createFructions(fractionsNumber); | ||
return newField; | ||
} | ||
|
||
auto findPlayersCell(std::string nick) { | ||
std::vector<std::pair<int, int>>result; | ||
for (int i = 0; i < cells_.size(); i++) { | ||
for (int j = 0; j < cells_[i].size(); j++) { | ||
if (cells_[i][j].getBelonging() == nick) { | ||
result.push_back(std::make_pair(i, j)); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
~FieldClass() {} | ||
}; | ||
|
||
FieldClass* FieldClass::fieldClassInstance = nullptr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
class FractionClass { | ||
|
||
private: | ||
std::string name_; | ||
int fractionId_; | ||
|
||
public: | ||
|
||
FractionClass() : name_("-"), fractionId_(0) {}; // default constructor | ||
|
||
FractionClass(FractionClass&& fraction) noexcept { | ||
|
||
this->name_ = fraction.name_; | ||
this->fractionId_ = fraction.fractionId_; | ||
|
||
fraction.name_ = "-"; | ||
fraction.fractionId_ = 0; | ||
}; // move constructor | ||
|
||
FractionClass(const FractionClass& copyFraction) { | ||
|
||
this->name_ = copyFraction.name_; | ||
this->fractionId_ = copyFraction.fractionId_; | ||
}; // copy constructor | ||
|
||
void setFractionName(std::string name) { | ||
this->name_ = name; | ||
} | ||
|
||
std::string getFractionName() { | ||
return this->name_; | ||
} | ||
|
||
void setFractionId(int id) { | ||
this->fractionId_ = id; | ||
} | ||
|
||
int getFractionId() { | ||
return this->fractionId_; | ||
} | ||
}; |
Oops, something went wrong.