Skip to content
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

Merged
merged 46 commits into from Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2275787
#9 Add Terrain headerfile
MagicalLas Sep 28, 2018
cfd4fec
#9 Basic header setting
MagicalLas Sep 28, 2018
e989565
#9 Enumclass Implement
MagicalLas Sep 28, 2018
78b8a38
#9 Include Terrain to Tile
MagicalLas Sep 28, 2018
0b08a46
#9 Apply Terrain to Tile
MagicalLas Sep 28, 2018
bc1b452
Add Resource and Deprecate Obtainable interface
MagicalLas Oct 8, 2018
085051b
Add TerrainName
MagicalLas Oct 8, 2018
148ae2e
Define Terrain structure
MagicalLas Oct 8, 2018
28cebb1
Replace TerrainCetegory to Terrain
MagicalLas Oct 8, 2018
b7cd17e
Chage Terrain
MagicalLas Oct 8, 2018
84126a3
Update Includes/Resource.h
MagicalLas Oct 8, 2018
0799b90
Add Resource.cpp
MagicalLas Oct 8, 2018
61db194
Add Getter to const for Resource
MagicalLas Oct 8, 2018
38f6969
Add Terrain Getter
MagicalLas Oct 8, 2018
54dff26
Add Resource change method
MagicalLas Oct 9, 2018
8d19eeb
Change HexTile
MagicalLas Oct 9, 2018
9177dc4
Change Worker signature
MagicalLas Oct 9, 2018
b7fd8fe
All Unit have HexMap pointer
MagicalLas Oct 10, 2018
cf8d5b6
Fixed Worker Implementation
MagicalLas Oct 10, 2018
b977583
Ghange map singleton
MagicalLas Oct 12, 2018
a04e6d5
Change Unit struct
MagicalLas Oct 12, 2018
4a1afbd
Delete interface
MagicalLas Oct 29, 2018
3ae0ca8
Change Constructor
MagicalLas Oct 29, 2018
30465b4
Change UnitTest
MagicalLas Oct 29, 2018
f20d97b
Add Resource Constructor
MagicalLas Oct 29, 2018
cc84e5f
Change Terrain method const
MagicalLas Oct 29, 2018
92de099
FIx testcase
MagicalLas Oct 29, 2018
fb32c0f
Change implementaion of Worker::Build
MagicalLas Oct 29, 2018
760571e
Implement HexTile to Resource
MagicalLas Oct 29, 2018
cc467e9
Add testcase
MagicalLas Oct 29, 2018
d687827
Fix HexTile Constructor
MagicalLas Oct 29, 2018
1f130c7
Fix Resource
MagicalLas Oct 29, 2018
f5be924
FIx Error in Terrain::consructor
MagicalLas Oct 29, 2018
c4ac029
Delete unused field
MagicalLas Oct 29, 2018
3dd8428
Update .gitmodules
MagicalLas Oct 29, 2018
7cd2c92
Fix Modules Error
MagicalLas Oct 29, 2018
26911e6
Fix Error
MagicalLas Oct 29, 2018
e1ac189
Fix Error Worker::Build
MagicalLas Oct 29, 2018
80350b6
Change Variable Name
MagicalLas Nov 2, 2018
00450b9
delete temp gitmodule
MagicalLas Nov 2, 2018
bfa54ac
Update Libraries/googletest
MagicalLas Nov 2, 2018
85706b6
Change Resource coding style
MagicalLas Nov 2, 2018
a3a6367
Seperate Tile Implementation
MagicalLas Nov 2, 2018
9733763
Sorting Lines
MagicalLas Nov 2, 2018
f48c709
Seperate UnitFactory Implementaion
MagicalLas Nov 2, 2018
afd6eb7
Change struct to class
MagicalLas Nov 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitmodules
Expand Up @@ -4,3 +4,5 @@
[submodule "Libraries/googlebenchmark"]
path = Libraries/googlebenchmark
url = https://github.com/google/benchmark.git
[submodule "bar1"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 submodule은 삭제해주세요

branch = master
3 changes: 2 additions & 1 deletion Includes/BaseUnit.h
Expand Up @@ -13,8 +13,9 @@ class BaseUnit {
public:
BaseUnit(int x, int y);
virtual ~BaseUnit() = default;

virtual std::pair<int, int> Move(int x, int y) noexcept;
std::pair<int, int> GetPosition();
};
} // namespace Civilizationpp

Expand Down
28 changes: 26 additions & 2 deletions Includes/HexTile.h
@@ -1,9 +1,33 @@
#ifndef CIVILIZATIONPP_HEX_TILE_H
#define CIVILIZATIONPP_HEX_TILE_H

#include <Terrain.h>

namespace Civilizationpp
{
class HexTile {};
}
class HexTile
{
private:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public이 위에, private가 밑에 오도록 순서를 바꿔주세요.

Terrain* m_Terrain;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_pTerrain으로 변경해주세요.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Terrain* m_Terrain;
Terrain* m_pTerrain;


public:
HexTile()
{
m_Terrain = new Terrain();
}
Terrain* GetTerrain()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const 붙여주세요

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Terrain* GetTerrain()
Terrain* GetTerrain() const

{
return m_Terrain;
}
void ChangeTerrain(Terrain* terrain)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이름을 SetTerrain으로 바꾸는 건 어떨까요?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void ChangeTerrain(Terrain* terrain)
void SetTerrain(Terrain* terrain)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
25 changes: 0 additions & 25 deletions Includes/Material.h

This file was deleted.

18 changes: 18 additions & 0 deletions Includes/Resource.h
@@ -0,0 +1,18 @@
#ifndef CIVILIZATIONPP_RESOURCE
#define CIVILIZATIONPP_RESOURCE

namespace Civilizationpp {
struct Resource {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private 변수가 있는데 struct일 필요는 없어보입니다.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct Resource {
class Resource {

private:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 privatepublic의 순서를 바꿔주세요.

int m_Food;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int m_Food;
int m_food;

int m_Production;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int m_Production;
int m_production;

int m_Gold;

public:
Resource();
int GetFood() const;
int GetProduction() const;
int GetGold() const;
};
} // namespace Civilizationpp
#endif // Resource
57 changes: 57 additions & 0 deletions Includes/Terrain.h
@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct Terrain
class Terrain

{
private:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 privatepublic의 순서를 바꿔주세요.

BaseTerrain m_Category;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BaseTerrain m_Category;
BaseTerrain m_category;

TerrainName m_Name;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TerrainName m_Name;
TerrainName m_name;

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
1 change: 0 additions & 1 deletion Includes/UnitFactory.h
Expand Up @@ -14,7 +14,6 @@ class UnitFactory {
private:
int m_x;
int m_y;

public:
UnitFactory(int x, int y);
auto CreatUnit(Unit::Codes unitCode) -> BaseUnit* {
Expand Down
5 changes: 2 additions & 3 deletions Includes/Worker.h
Expand Up @@ -2,14 +2,13 @@
#define CIVILIZATIONPP_WORKER

#include <BaseUnit.h>
#include <Material.h>

namespace Civilizationpp {
class Worker : public BaseUnit {
public:
Worker(int x, int y);
void Build(Obtainable* tile);
void Build(Obtainable* tile, eventFunction f);
void Build(Resource* tile);
void Build(HexTile* tile, Resource* resource);
};
} // namespace Civilizationpp

Expand Down
2 changes: 1 addition & 1 deletion Libraries/googlebenchmark
Submodule googlebenchmark updated 68 files
+1 −0 .gitignore
+11 −6 .travis.yml
+2 −0 AUTHORS
+16 −4 BUILD.bazel
+22 −7 CMakeLists.txt
+2 −0 CONTRIBUTORS
+96 −61 README.md
+0 −6 appveyor.yml
+3 −0 cmake/GetGitVersion.cmake
+7 −9 cmake/HandleGTest.cmake
+3 −0 cmake/split_list.cmake
+28 −71 docs/tools.md
+203 −116 include/benchmark/benchmark.h
+18 −2 src/CMakeLists.txt
+94 −231 src/benchmark.cc
+15 −0 src/benchmark_api_internal.cc
+8 −3 src/benchmark_api_internal.h
+17 −0 src/benchmark_main.cc
+26 −10 src/benchmark_register.cc
+350 −0 src/benchmark_runner.cc
+51 −0 src/benchmark_runner.h
+4 −1 src/check.h
+1 −1 src/colorprint.cc
+1 −1 src/commandlineflags.cc
+14 −6 src/complexity.cc
+2 −22 src/console_reporter.cc
+16 −9 src/counter.cc
+4 −4 src/counter.h
+19 −15 src/csv_reporter.cc
+4 −4 src/cycleclock.h
+13 −10 src/internal_macros.h
+37 −30 src/json_reporter.cc
+2 −1 src/log.h
+15 −9 src/re.h
+9 −1 src/reporter.cc
+1 −1 src/sleep.cc
+37 −25 src/statistics.cc
+89 −0 src/string_util.cc
+18 −2 src/string_util.h
+14 −8 src/sysinfo.cc
+0 −2 src/thread_manager.h
+3 −5 src/timers.cc
+1 −0 test/AssemblyTests.cmake
+9 −1 test/BUILD
+20 −0 test/CMakeLists.txt
+1 −0 test/basic_test.cc
+31 −15 test/complexity_test.cc
+43 −0 test/display_aggregates_only_test.cc
+8 −0 test/link_main_test.cc
+42 −0 test/memory_manager_test.cc
+24 −12 test/output_test.h
+89 −48 test/output_test_helper.cc
+4 −2 test/register_benchmark_test.cc
+39 −0 test/report_aggregates_only_test.cc
+287 −84 test/reporter_output_test.cc
+3 −6 test/skip_with_error_test.cc
+2 −0 test/state_assembly_test.cc
+10 −43 test/statistics_gtest.cc
+146 −0 test/string_util_gtest.cc
+3 −3 test/templated_fixture_test.cc
+101 −83 test/user_counters_tabular_test.cc
+247 −56 test/user_counters_test.cc
+161 −0 test/user_counters_thousands_test.cc
+102 −4 tools/compare.py
+0 −67 tools/compare_bench.py
+65 −0 tools/gbench/Inputs/test3_run0.json
+65 −0 tools/gbench/Inputs/test3_run1.json
+351 −36 tools/gbench/report.py
2 changes: 1 addition & 1 deletion Libraries/googletest
Submodule googletest updated 241 files
7 changes: 6 additions & 1 deletion Sources/BaseUnit.cpp
Expand Up @@ -6,8 +6,13 @@ BaseUnit::BaseUnit(int x, int y) {
m_positionX = x;
m_positionY = y;
}

std::pair<int, int> BaseUnit::Move(int x, int y) noexcept {
m_positionX = x;
m_positionY = y;
return {m_positionX, m_positionY};
}
}

std::pair<int, int> Civilizationpp::BaseUnit::GetPosition() {
return {m_positionX, m_positionY};
}
10 changes: 0 additions & 10 deletions Sources/Material.cpp

This file was deleted.

10 changes: 10 additions & 0 deletions Sources/Resource.cpp
@@ -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
34 changes: 34 additions & 0 deletions Sources/Terrain.cpp
@@ -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
}
15 changes: 11 additions & 4 deletions Sources/Worker.cpp
@@ -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) {}
36 changes: 19 additions & 17 deletions Tests/UnitTests/WorkerTests.cpp
@@ -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);
}