feat:ConfigManager游戏配置管理器类;Wave波次类相关定义;ConfigManager成员类定义;Map类新增一些接口
This commit is contained in:
parent
7f5129c48c
commit
13c5b15b99
@ -134,11 +134,14 @@
|
|||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="config_manager.h" />
|
||||||
|
<ClInclude Include="enemy_type.h" />
|
||||||
<ClInclude Include="game_manager.h" />
|
<ClInclude Include="game_manager.h" />
|
||||||
<ClInclude Include="manager.h" />
|
<ClInclude Include="manager.h" />
|
||||||
<ClInclude Include="map.h" />
|
<ClInclude Include="map.h" />
|
||||||
<ClInclude Include="route.h" />
|
<ClInclude Include="route.h" />
|
||||||
<ClInclude Include="tile.h" />
|
<ClInclude Include="tile.h" />
|
||||||
|
<ClInclude Include="wave.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
<Filter Include="头文件\manager">
|
<Filter Include="头文件\manager">
|
||||||
<UniqueIdentifier>{f50376ab-e971-4317-8a3c-da0f2703263e}</UniqueIdentifier>
|
<UniqueIdentifier>{f50376ab-e971-4317-8a3c-da0f2703263e}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="头文件\enemy">
|
||||||
|
<UniqueIdentifier>{d16b420a-6329-4705-af2a-57caf4eee0e9}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
@ -38,5 +41,14 @@
|
|||||||
<ClInclude Include="route.h">
|
<ClInclude Include="route.h">
|
||||||
<Filter>头文件</Filter>
|
<Filter>头文件</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="config_manager.h">
|
||||||
|
<Filter>头文件\manager</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="wave.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="enemy_type.h">
|
||||||
|
<Filter>头文件\enemy</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
107
TdGame/config_manager.h
Normal file
107
TdGame/config_manager.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef _CONFIG_MANAGER_H_
|
||||||
|
#define _CONFIG_MANAGER_H_
|
||||||
|
|
||||||
|
#include "map.h"
|
||||||
|
#include "wave.h"
|
||||||
|
#include "manager.h"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <string>
|
||||||
|
#include <cJSON.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
//作为全局数据配置中心
|
||||||
|
|
||||||
|
class ConfigManager : public Manager<ConfigManager>
|
||||||
|
{
|
||||||
|
friend class Manager<ConfigManager>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct BasicTemplate
|
||||||
|
{
|
||||||
|
std::string window_title = u8"村庄保卫战!";
|
||||||
|
int window_width = 1280;
|
||||||
|
int window_height = 720;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PlayerTemplate
|
||||||
|
{
|
||||||
|
double speed = 3;
|
||||||
|
double normal_attack_interval = 0.5;
|
||||||
|
double normal_attack_damage = 0;
|
||||||
|
double skill_interval = 10;
|
||||||
|
double skill_damage = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TowerTemplate
|
||||||
|
{
|
||||||
|
double interval[10] = { 1 };
|
||||||
|
double damage[10] = { 25 };
|
||||||
|
double view_range[10] = { 5 };
|
||||||
|
double cost[9] = { 50 };
|
||||||
|
double upgrade_cost[9] = { 75 };
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EnemyTemplate
|
||||||
|
{
|
||||||
|
double hp = 100;
|
||||||
|
double speed = 1;
|
||||||
|
double damage = 1;
|
||||||
|
double reward_ratio = 0.5;
|
||||||
|
double recover_interval = 10;
|
||||||
|
double recover_range = 0;
|
||||||
|
double recover_intensity = 25;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
Map map;
|
||||||
|
std::vector<Wave> wave_list;
|
||||||
|
|
||||||
|
int level_archer = 0;//弓箭手等级
|
||||||
|
int level_axeman = 0;//斧头兵等级
|
||||||
|
int level_gunner = 0;//枪兵等级
|
||||||
|
|
||||||
|
bool is_game_win =true;//游戏是否获胜
|
||||||
|
bool is_game_over = false;//游戏是否结束,和上面是两个不同层面的条件,需要分析
|
||||||
|
SDL_Rect rect_tile_map = { 0 };
|
||||||
|
|
||||||
|
BasicTemplate basci_template;
|
||||||
|
PlayerTemplate player_template;
|
||||||
|
|
||||||
|
TowerTemplate archer_template;
|
||||||
|
TowerTemplate axeman_template;
|
||||||
|
TowerTemplate gunner_template;
|
||||||
|
|
||||||
|
EnemyTemplate slim_template;
|
||||||
|
EnemyTemplate king_slim_template;
|
||||||
|
EnemyTemplate skeleton_template;
|
||||||
|
EnemyTemplate goblin_template;
|
||||||
|
EnemyTemplate goblin_priest_template;
|
||||||
|
|
||||||
|
const double num_initial_hp = 10;//房屋初始生命
|
||||||
|
const double num_initial_coin = 100;//初始金币
|
||||||
|
const double num_coin_per_prop = 10;//每个道具奖励金币数
|
||||||
|
|
||||||
|
public:
|
||||||
|
//加载波次配置
|
||||||
|
bool load_level_config(const std::string& path)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//加载游戏配置
|
||||||
|
bool load_game_config(const std::string& path)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ConfigManager() = default;
|
||||||
|
|
||||||
|
~ConfigManager() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // !_CONFIG_MANAGER_H_
|
||||||
|
|
14
TdGame/enemy_type.h
Normal file
14
TdGame/enemy_type.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef _ENEMY_TYPE_H_
|
||||||
|
#define _ENEMY_TYPE_H_
|
||||||
|
|
||||||
|
enum class EnemyType
|
||||||
|
{
|
||||||
|
Slim,
|
||||||
|
KingSlim,
|
||||||
|
Skeleton,
|
||||||
|
Goblin,
|
||||||
|
GoblinPriest
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -2,6 +2,8 @@
|
|||||||
#ifndef _MANAGER_H_
|
#ifndef _MANAGER_H_
|
||||||
#define _MANAGER_H_
|
#define _MANAGER_H_
|
||||||
|
|
||||||
|
//데절친겼잚
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Manager
|
class Manager
|
||||||
{
|
{
|
||||||
|
21
TdGame/map.h
21
TdGame/map.h
@ -79,6 +79,27 @@ public:
|
|||||||
return tile_map.size();//行数量(高度)
|
return tile_map.size();//行数量(高度)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TileMap& get_tile_map() const
|
||||||
|
{
|
||||||
|
return tile_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SDL_Point& get_idx_home() const
|
||||||
|
{
|
||||||
|
return idx_home;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SpawnerRoutePool& get_idx_spawner_pool() const
|
||||||
|
{
|
||||||
|
return spawner_route_pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
void place_tower(const SDL_Point& idx_tile)
|
||||||
|
{
|
||||||
|
tile_map[idx_tile.y][idx_tile.x].has_tower = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TileMap tile_map;
|
TileMap tile_map;
|
||||||
SDL_Point idx_home = { 0 };//房屋点
|
SDL_Point idx_home = { 0 };//房屋点
|
||||||
|
@ -21,7 +21,7 @@ struct Tile
|
|||||||
int terrian = 0;
|
int terrian = 0;
|
||||||
int decoration = -1;
|
int decoration = -1;
|
||||||
int special_flag = -1;
|
int special_flag = -1;
|
||||||
bool has_tower = false;
|
bool has_tower = false;//运行时数据
|
||||||
Direction direction = Direction::None;
|
Direction direction = Direction::None;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
24
TdGame/wave.h
Normal file
24
TdGame/wave.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef _WAVE_H_
|
||||||
|
#define _WAVE_H_
|
||||||
|
|
||||||
|
#include "enemy_type.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct Wave
|
||||||
|
{
|
||||||
|
//描述生成事件
|
||||||
|
struct SpawnEvent
|
||||||
|
{
|
||||||
|
double interval = 0;
|
||||||
|
int spawn_point = 1;
|
||||||
|
EnemyType enemy_type = EnemyType::Slim;//在level.json文件中见格式,波次序列配置文件
|
||||||
|
};
|
||||||
|
|
||||||
|
double rewards = 0;
|
||||||
|
double interval = 0;
|
||||||
|
std::vector<SpawnEvent> spawn_event_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !_WAVE_H_
|
Loading…
Reference in New Issue
Block a user