New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement terrain and resource system (#9, #10) #26
Changes from 38 commits
2275787
cfd4fec
e989565
78b8a38
0b08a46
bc1b452
085051b
148ae2e
28cebb1
b7cd17e
84126a3
0799b90
61db194
38f6969
54dff26
8d19eeb
9177dc4
b7fd8fe
cf8d5b6
b977583
a04e6d5
4a1afbd
3ae0ca8
30465b4
f20d97b
cc84e5f
92de099
fb32c0f
760571e
cc467e9
d687827
1f130c7
f5be924
c4ac029
3dd8428
7cd2c92
26911e6
e1ac189
80350b6
00450b9
bfa54ac
85706b6
a3a6367
9733763
f48c709
afd6eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,9 +1,33 @@ | ||||||
#ifndef CIVILIZATIONPP_HEX_TILE_H | ||||||
#define CIVILIZATIONPP_HEX_TILE_H | ||||||
|
||||||
#include <Terrain.h> | ||||||
|
||||||
namespace Civilizationpp | ||||||
{ | ||||||
class HexTile {}; | ||||||
} | ||||||
class HexTile | ||||||
{ | ||||||
private: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public이 위에, private가 밑에 오도록 순서를 바꿔주세요. |
||||||
Terrain* m_Terrain; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
public: | ||||||
HexTile() | ||||||
{ | ||||||
m_Terrain = new Terrain(); | ||||||
} | ||||||
Terrain* GetTerrain() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return m_Terrain; | ||||||
} | ||||||
void ChangeTerrain(Terrain* terrain) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이름을 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Terrain이 설정되는 것은 초반뿐이라 Set으로 바꿔도 좋을 것 같습니다, 수정하겠습니다. |
||||||
{ | ||||||
m_Terrain = terrain; | ||||||
} | ||||||
void ChangeResource(Resource* resource) | ||||||
{ | ||||||
m_Terrain->ChangeResource(resource); | ||||||
} | ||||||
}; | ||||||
} // namespace Civilizationpp | ||||||
|
||||||
#endif // CIVILIZATIONPP_HEX_TILE_H |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||
#ifndef CIVILIZATIONPP_RESOURCE | ||||||
#define CIVILIZATIONPP_RESOURCE | ||||||
|
||||||
namespace Civilizationpp { | ||||||
struct Resource { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
private: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 |
||||||
int m_Food; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
int m_Production; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
int m_Gold; | ||||||
|
||||||
public: | ||||||
Resource(); | ||||||
int GetFood() const; | ||||||
int GetProduction() const; | ||||||
int GetGold() const; | ||||||
}; | ||||||
} // namespace Civilizationpp | ||||||
#endif // Resource |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||||
#ifndef CIVILAZATIONPP_TERRAIN | ||||||
#define CIVILAZATIONPP_TERRAIN | ||||||
|
||||||
#include <Resource.h> | ||||||
|
||||||
namespace Civilizationpp | ||||||
{ | ||||||
enum class BaseTerrain | ||||||
{ | ||||||
Open, | ||||||
Rough, | ||||||
Lake, | ||||||
Coast, | ||||||
Ocean, | ||||||
Fresh_Water | ||||||
}; | ||||||
enum class TerrainName | ||||||
{ | ||||||
Coast, | ||||||
Desert, | ||||||
GrassLand, | ||||||
Hill, | ||||||
Mountain, | ||||||
Ocean, | ||||||
Plains, | ||||||
Snow, | ||||||
Tundra, | ||||||
Forest, | ||||||
Jungle, | ||||||
Marsh, | ||||||
Atoll, | ||||||
FloodPlains, | ||||||
Ice, | ||||||
LAkes, | ||||||
Oasis | ||||||
}; | ||||||
struct Terrain | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
private: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 |
||||||
BaseTerrain m_Category; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
TerrainName m_Name; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
int m_Movement; | ||||||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
int m_Combat; // percent | ||||||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Resource* m_Resource; | ||||||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
public: | ||||||
Terrain(); | ||||||
BaseTerrain GetCategory() const; | ||||||
TerrainName GetName() const; | ||||||
int GetMovement() const; | ||||||
int GetCombat() const; | ||||||
Resource* GetResource() const; | ||||||
void ChangeResource(Resource* resource); | ||||||
}; | ||||||
} // namespace Civilizationpp | ||||||
|
||||||
#endif // CIVILAZATIONPP_TERRAIN |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <Resource.h> | ||
Civilizationpp::Resource::Resource() | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
m_Food = 0; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
m_Gold = 0; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
m_Production = 0; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
int Civilizationpp::Resource::GetFood() const { return m_Food; } | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int Civilizationpp::Resource::GetProduction() const { return m_Production; } | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int Civilizationpp::Resource::GetGold() const { return m_Gold; } | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <Terrain.h> | ||
|
||
int Civilizationpp::Terrain::GetCombat() const | ||
{ | ||
return m_Combat; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
Civilizationpp::Terrain::Terrain() | ||
: m_Category(BaseTerrain::Open), | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
m_Name(TerrainName::Plains) | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
m_Movement = 0; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
m_Combat = 0; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
int Civilizationpp::Terrain::GetMovement() const | ||
{ | ||
return m_Movement; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
Civilizationpp::Resource* Civilizationpp::Terrain::GetResource() const | ||
{ | ||
return m_Resource; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
void Civilizationpp::Terrain::ChangeResource(Resource* resource) | ||
{ | ||
m_Resource = resource; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
Civilizationpp::BaseTerrain Civilizationpp::Terrain::GetCategory() const | ||
{ | ||
return m_Category; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
Civilizationpp::TerrainName Civilizationpp::Terrain::GetName() const | ||
{ | ||
return m_Name; | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
#include <Worker.h> | ||
|
||
using namespace Civilizationpp; | ||
void Worker::Build(Obtainable* tile) { | ||
tile->ChangeFood([]() -> int { return 1; }); | ||
|
||
Worker::Worker(int x, int y) : BaseUnit(x, y) {} | ||
MagicalLas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void Worker::Build(Resource* resource) { | ||
auto position = GetPosition(); | ||
HexMap::GetInstance()->GetTile(position.first, position.second)->ChangeResource(resource); | ||
} | ||
|
||
void Worker::Build(HexTile* tile, Resource* resource) | ||
{ | ||
tile->ChangeResource(resource); | ||
} | ||
void Worker::Build(Obtainable* tile, eventFunction f) { tile->ChangeFood(f); } | ||
Worker::Worker(int x, int y) : BaseUnit(x, y) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
#include <Resource.h> | ||
#include <Worker.h> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace Civilizationpp; | ||
|
||
class WorkerTest : public ::testing::Test { | ||
class WorkerTest : public ::testing::Test | ||
{ | ||
protected: | ||
Worker worker{0, 0}; | ||
}; | ||
class ObtainableTileTest : public Obtainable { | ||
public: | ||
int GetFood() { return Food(); } | ||
int GetProduction() { return Production(); } | ||
int GetGold() { return Gold(); } | ||
void SetUp() override | ||
{ | ||
HexMap::GetInstance()->Generate(GameSettings(30, 30)); | ||
} | ||
Worker worker{ 0, 0 }; | ||
}; | ||
|
||
TEST_F(WorkerTest, WorkerCanMoveAnywhere) { | ||
auto position = worker.Move(1, 2); | ||
TEST_F(WorkerTest, WorkerCanMoveAnywhere) | ||
{ | ||
worker.Move(1, 2); | ||
auto position = worker.GetPosition(); | ||
ASSERT_EQ(position.first == 1, position.second == 2); | ||
} | ||
TEST_F(WorkerTest, WorkerCanChangeTile) { | ||
ObtainableTileTest tile; | ||
worker.Build(&tile); | ||
ASSERT_EQ(tile.GetFood(), 1); | ||
int t = 10; | ||
worker.Build(&tile, [t]() -> int { return t + 10; }); | ||
ASSERT_EQ(tile.GetFood(), 20); | ||
TEST_F(WorkerTest, WorkerCanChangeTile) | ||
{ | ||
Resource res; | ||
worker.Build(&res); | ||
auto position = worker.GetPosition(); | ||
ASSERT_EQ(HexMap::GetInstance()->GetTile(position.first, position.second)->GetTerrain()->GetResource(), | ||
&res); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 submodule은 삭제해주세요