【通用 】--一些游戏中常用的宏、函数和枚举

 #ifndef _MARCO_H_
#define _MARCO_H_ //------------------------常用系统库---------------------------------
#include <stdlib.h>
#include<windows.h>
#include<string.h>
#include<conio.h>
#include<iostream>
#include<time.h>
using namespace std; extern double uintSpeed ;//1秒1格 //------------------------自定义宏--------------------------------- //纯虚函数(实现空函数)
#define CC_PROPERTY_VIRTUAL(varType,varName,FunName)\
public: virtual varType Get##FunName() = ; \
public: virtual void Set##FunName(varType var) = ; //一般属性
#define CC_PROPERTY(varType, varName, FunName) \
private: varType varName; \
public: virtual varType Get##FunName(){ return varName; }\
public: virtual void Set##FunName(varType var){ varName = var; } //一般属性(私有、非负数)
#define PROPERTY_UNSIGNED(varType, varName, FunName) \
private: varType varName; \
public: virtual varType Get##FunName(){ return varName; }\
public: virtual void Set##FunName(varType var){ varName = (var>) ? var : ; } //只读属性
#define CC_PROPERTY_READ_ONLY(varType, varName, FunName)\
private:varType varName; \
public: virtual varType Get##FunName(){ return varName; } //二维数组属性
#define CC_PROPERTY_ARR(varType,uintType, varName, FunName)\
protected: varType varName; \
public: virtual varType Get##FunName(){ return varName; }\
public: virtual void Set##FunName(varType var){ varName = var; }\
public: virtual void SetUnit##FunName(int i, int j, uintType var){ varName[i][j] = var; }\
public: virtual uintType GetUnit##FunName(int i, int j){ return varName[i][j]; } //-------------------------枚举------------------------------------
enum ShapeType //外观形状
{
//============ 组合图案 ===============
// ---- 消耗品 -----
ST_Bandage , //绷带
ST_Injector, //注射剂
ST_Bullet = '_', //子弹
ST_Clip, //弹夹
ST_MedKit, //医疗箱
ST_Grenade = '+', //手榴弹
ST_Bomb, //炸弹
ST_AP, //穿甲弹 //----- 武器类 ---
ST_Dagger, //匕首
ST_Pistol, //手枪
ST_Pillbox, //机关枪
ST_SniperRifle, //狙击枪 //----- 道具类 ---
ST_Armor, //防弹衣
ST_NightVision, //夜视仪
ST_FlashLight, //手电筒
ST_Radar, //雷达
ST_Cord = 't', //绳索
ST_Backpack, //背包
ST_Bugle, //军号
ST_Armory, //军械库
ST_GoldCoin, //金币
ST_Civilian, //平民
ST_Milltia, //民兵
ST_Lighten, //照明灯 //============ 单一图案 ================ SPACE = '', //空格
bBOSS = '', //"魔"
sBOOS = '', //"妖"
MONSTER = '+', //"¤"
Gate = 'c', //"∩"
iGate = 'y', //"∪"
NPC = 't', //"♂"
HERO = 'r', //"♀"
LADDER = 'u', //"⊥"
lLadder = 'l', //"〓"
ROPE = 'k', //"↓"
WALL = 'q', //"■"
WATER = 's', //"≈"
TREE = 'w', //"※"
rArrow = 'g', //"→"
lArrow = 'h', //"←"
uArrow = 'j', //"↑"
Rain = 'n', //"〃"
FOG = '', //"∷" }; enum BodyType //物品类型
{
// ---- 消耗品 --------
ET_Bandage, //绷带
ET_Injector, //注射剂
ET_Bullet = '_',//手枪子弹
ET_PillBt = 'C',//机关枪子弹
ET_SniperBt = 'D',//狙击枪子弹
ET_Clip, //弹夹
ET_MedKit, //医疗箱
ET_Grenade = '+',//手榴弹
ET_Bomb, //炸弹
ET_AP, //穿甲弹 //----- 道具类 --------
ET_Armor, //防弹衣
ET_Caliga, //战靴
ET_NightVision, //夜视仪
ET_FlashLight, //手电筒
ET_Radar, //雷达
ET_Cord = 't', //绳索
ET_Backpack, //背包
ET_Bugle, //军号
ET_Armory, //军械库
ET_GoldCoin, //金币
ET_Civilian, //平民
ET_Milltia, //民兵
ET_Lighten, //照亮
ET_NUM , //血字
//----- 武器类 --------
ET_Dagger, //匕首
ET_Pistol, //手枪
ET_Pillbox, //机关枪
ET_SniperRifle, //狙击枪 //----- 任务物品 --------
ET_TASKITEM, }; enum ColorType //颜色
{
CT_Black, //黑
CT_TBlue, //深蓝色
CT_Green, //绿色
CT_BlueGreen, //蓝绿色
CT_Brown, //咖啡色
CT_Violet, //紫色
CT_Khaki, //卡其色
CT_OffWhite, //灰白色
CT_Grey, //灰色
CT_Blue, //蓝色
CT_LGreen, //亮绿色
CT_SkyBlue, //天蓝色
CT_Red, //红色
CT_Pink, //梅红色
CT_Yellow, //黄色
CT_White, //白色 }; //物理属性
struct PhysicalProps
{
ShapeType ST; //形状
ColorType CT; //颜色
}; enum ArmType //兵种
{
AT_Dog, //猎犬:撕咬(会自爆)
AT_Spearman, //枪兵:手枪
AT_Cavalry, //装甲车(防高、血厚)
AT_Artillery, //炮兵:攻击高 防低
AT_Boss, //boss
AT_Hero, //将军
}; enum RaceType //国籍类型
{
RT_CHINA, //中国
RT_USA, //美国
RT_RUSSIA, //俄罗斯
RT_JAPAN, //日本
RT_IS, //伊斯兰国
}; //------------------------全局函数---------------------------------
//光标移动
void GotoXY(int, int); //颜色函数
void Color(int, int); //光标打印
void Print(char, int, int); //光标打印物体
void PrintBody(PhysicalProps, int, int); //时间函数 //物品图标图形库
void GetGraphicLib(char** Graphic, BodyType); //---------开辟内存,释放内存---------
//开辟内存
char **GetCharMemory(int row, int colu);
int** GetIntMemory(int row, int colu);
bool **GetBoolMemory(int row, int colu); //释放内存
void DeleteCharMemory(char** pArr, int row);
void DeleteIntMemory(int** pArr, int row);
void DeleteBoolMemory(bool** pArr, int row); #endif // _MARCO_H_

Marco.h

 #include "Marco.h"

 //光标移动
void GotoXY(int x, int y)
{
COORD pos = { * y, x };
HANDLE phand = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(phand, pos);
} //颜色函数
void Color(int back, int before)
{
HANDLE hand = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hand, before + back * 0x10);
} //打印函数
void Print(char type, int X, int Y)
{
Color(CT_White, CT_Black);
GotoXY(X, Y);
switch (type)
{
case '': cout << " "; break;
case 'z': cout << "…"; break;
case '': cout << "★"; break;
case '': cout << "☆"; break;
case '': cout << "○"; break;
case '': cout << "∷"; break;
case 'c': cout << "∩"; break;
case 'e': cout << "⊙"; break;
case 't': cout << "♂"; break;
case 'r': cout << "♀"; break;
case 'v': cout << "∧"; break;
case 'b': cout << "∨"; break;
case 'y': cout << "∪"; break;
case 'u': cout << "⊥"; break;
case 'i': cout << "⌒"; break;
case 'a': cout << "≡"; break;
case 's': cout << "≈"; break;
case 'd': cout << "∽"; break;
case 'f': cout << "卍"; break;
case 'm': cout << "▓"; break;
case 'n': cout << "〃"; break;
case '': cout << "●"; break;
case '': cout << "◎"; break;
case '': cout << "◇"; break;
case '': cout << "◆"; break;
case '': cout << "□"; break;
case 'q': cout << "■"; break;
case 'o': cout << "△"; break;
case 'p': cout << "▲"; break;
case 'w': cout << "※"; break;
case 'g': cout << "→"; break;
case 'h': cout << "←"; break;
case 'j': cout << "↑"; break;
case 'k': cout << "↓"; break;
case 'l': cout << "〓"; break;
case 'x': cout << "×"; break; //子弹、手雷
case 'C': cout << "·"; break;
case 'D': cout << "━"; break;
case '_': cout << "о"; break;
case '+': cout << "¤"; break; //制表符
case '!': cout << "┏"; break;
case '&': cout << "┳"; break;
case '@': cout << "┓"; break;
case '=': cout << "┫"; break;
case '$': cout << "┛"; break;
case ')': cout << "┻"; break;
case '#': cout << "┗"; break;
case '-': cout << "┣"; break;
case '(': cout << "╋"; break;
case '*': cout << "┃"; break;
case '%': cout << "━"; break;
//额外
case 'A': cout << "╱"; break;
case 'B': cout << "╲"; break;
}
} //光标打印物体
void PrintBody(PhysicalProps pProps, int X, int Y)
{
Color(, pProps.CT);
Print(pProps.ST, X, Y);
} //---------地图数据开辟内存,释放内存---------
//开辟内存new
char** GetCharMemory(int row, int colu)
{
char **pArr = new char*[row];
if (pArr == nullptr)
return nullptr; for (int i = ; i < row; i++)
{
pArr[i] = new char[colu];
if (pArr[i] == nullptr)
return nullptr;
}
//开辟成功并制空
for (int i = ; i < row; i++)
for (int j = ; j < colu; j++)
pArr[i][j] = ''; return pArr;
} int** GetIntMemory(int row, int colu)
{
int **pArr = new int*[row];
if (pArr == nullptr)
return nullptr; for (int i = ; i < row; i++)
{
pArr[i] = new int[colu];
if (pArr[i] == nullptr)
return nullptr;
}
return pArr;
} bool** GetBoolMemory(int row, int colu)
{
bool **pArr = new bool*[row];
if (pArr == nullptr)
return nullptr; for (int i = ; i < row; i++)
{
pArr[i] = new bool[colu];
if (pArr[i] == nullptr)
return nullptr;
} //开辟成功并制空
for (int i = ; i < row; i++)
for (int j = ; j < colu; j++)
pArr[i][j] = true; return pArr;
} //释放内存
void DeleteCharMemory(char** pArr, int row)
{
for (int i = ; i < row; i++)
{
if (pArr[i] != nullptr)
{
delete[] pArr[i];
pArr[i] = nullptr;
}
} if (pArr != nullptr)
{
delete[] pArr;
pArr = nullptr;
}
} void DeleteIntMemory(int** pArr, int row)
{
for (int i = ; i < row; i++)
{
if (pArr[i] != nullptr)
{
delete[] pArr[i];
pArr[i] = nullptr;
}
} if (pArr != nullptr)
{
delete[] pArr;
pArr = nullptr;
}
} void DeleteBoolMemory(bool** pArr, int row)
{
for (int i = ; i < row; i++)
{
if (pArr[i] != nullptr)
{
delete[] pArr[i];
pArr[i] = nullptr;
}
} if (pArr != nullptr)
{
delete[] pArr;
pArr = nullptr;
}
} //物品图形库
void GetGraphicLib(char** Graphic, BodyType bodyType)
{
switch (bodyType)
{
case ET_Bandage: strcpy(Graphic[], "∽∽"); strcpy(Graphic[], "绷带"); break;
case ET_Injector: strcpy(Graphic[], "♂注"); strcpy(Graphic[], "射器"); break;
case ET_Bullet: strcpy(Graphic[], "ⅲⅲ"); strcpy(Graphic[], "子弹"); break;
case ET_Clip: strcpy(Graphic[], "ㄖㄖ"); strcpy(Graphic[], "弹夹"); break;
case ET_MedKit: strcpy(Graphic[], "╋医"); strcpy(Graphic[], "疗箱"); break;
case ET_Grenade: strcpy(Graphic[], "ΦΦ"); strcpy(Graphic[], "手雷"); break;
case ET_Bomb: strcpy(Graphic[], "BB"); strcpy(Graphic[], "炸弹"); break;
case ET_AP: strcpy(Graphic[], "医疗"); strcpy(Graphic[], "绷带"); break;
case ET_Armor: strcpy(Graphic[], "¥防"); strcpy(Graphic[], "弹衣"); break;
case ET_Caliga: strcpy(Graphic[], "足足"); strcpy(Graphic[], "战靴"); break;
case ET_NightVision:strcpy(Graphic[], "⊙夜"); strcpy(Graphic[], "视仪"); break;
case ET_FlashLight: strcpy(Graphic[], "⊕手"); strcpy(Graphic[], "电筒"); break;
case ET_Radar: strcpy(Graphic[], "¤¤"); strcpy(Graphic[], "雷达"); break;
case ET_Cord: strcpy(Graphic[], "§§"); strcpy(Graphic[], "绳索"); break;
case ET_Backpack: strcpy(Graphic[], "囧囧"); strcpy(Graphic[], "背包"); break;
case ET_Bugle: strcpy(Graphic[], "≤≤"); strcpy(Graphic[], "号角"); break;
case ET_Armory: strcpy(Graphic[], "医疗"); strcpy(Graphic[], "绷带"); break;
case ET_GoldCoin: strcpy(Graphic[], "医疗"); strcpy(Graphic[], "绷带"); break; case ET_Civilian: strcpy(Graphic[], "医疗"); strcpy(Graphic[], "绷带"); break;
case ET_Milltia: strcpy(Graphic[], "医疗"); strcpy(Graphic[], "绷带"); break;
case ET_Lighten: strcpy(Graphic[], "医疗"); strcpy(Graphic[], "绷带"); break;
case ET_Dagger: strcpy(Graphic[], "丿丿"); strcpy(Graphic[], "匕首"); break;
case ET_Pistol: strcpy(Graphic[], "┍┍"); strcpy(Graphic[], "手枪"); break;
case ET_Pillbox: strcpy(Graphic[], "╤机"); strcpy(Graphic[], "关枪"); break;
case ET_SniperRifle:strcpy(Graphic[], "┮狙"); strcpy(Graphic[], "击枪"); break;
case ET_TASKITEM: strcpy(Graphic[], "一封"); strcpy(Graphic[], "密信"); break;
}
}

Marco.cpp

【主函数】--游戏运行入口

 #include "Marco.h"
#include "GameMgr//GameScene.h"
#include "Body//Props.h"
#include "Body//Equip.h"
#include "Role//Dog.h"
#include "Role//SpearMan.h"
#include "Role//Hero.h"
#include "Backpack//Backpack.h"
#include "Body//Pistol.h"
#include "Body//Bandage.h"
#include "Body//Dagger.h"
#include "Body//Armor.h"
#include "GameMgr//GameOI.h"
#include "Map//Map.h"
#include "Map//GateWay.h"
#include "Map//Map_1.h"
#include "Map//Map_11.h"
#include "Map//Map_111.h"
#include "Map//Map_12.h"
#include "Map//Map_121.h"
#include "Body//NightVision.h"
#include "Body//Grenade.h"
#include "Body//PillBox.h"
#include "Body//SniperRifle.h"
#include "Body//Cord.h"
#include "GameUI//LandSurface.h" #pragma comment(lib,"WINMM.LIB")
//全局变量
int GameTime = ; void main()
{
WCHAR mciCmd[] = TEXT("open .//music//background//HeisAPirate.mp3 alias background"); //.mp3格式的
mciSendString(mciCmd, NULL, , NULL);
mciSendString(TEXT("play background repeat"), NULL, , NULL); // 音乐 mp3
//WCHAR mciCmd[] = TEXT("open .//music//background//gamestartup.mp3 alias background"); //.mp3格式的
//mciSendString(mciCmd, NULL, 0, NULL);
//mciSendString(TEXT("play background repeat"), NULL, 0, NULL); srand((unsigned)time(nullptr));
//初始化登陆系统
MainMenu* pMainMenu = LandSurface::InitLandSurface(); pMainMenu->OutputFrame(); pMainMenu->OutputButton(); pMainMenu->ChooseButton(); }

Main.cpp

【背包类】-----整个游戏中很单一的类,没有继承体系

 #ifndef _BACKPACK_H_
#define _BACKPACK_H_ #include "..//Marco.h"
class Role;
class Body; class Backpack
{
public:
Backpack(Role* pHero);
~Backpack(); public://外部接口函数
void OutputSurface(); //打印外观
void CloseSurface(); //关闭外观
void PushBackBody(Body* pBody); //添加物品
void ChooseBody(); //选择物品
void GetCapacity(); //背包扩容
Body** GetBodyArr(); //获取物品容器
int Size(){ return m_capacity; } private://内部操作函数
void InitFrame(); //导入背包框架
void OutputAllBody(); //打印所有物体
void OutputCurBody(); //醒目打印当前指向物体
void CleanCurBody(); //清除当前指向物体底色
void OutputBodyInfo(Body* pBody); //打印物品信息
void EraseBodyInfo(); //清除物品信息
void UseBody(); //使用物品 private://背包存储物品数据成员
Role* m_role; //背包归属
Body** m_bodyArr; //物品容器
int m_capacity; //目前容量(基础容量16)
int m_index; //目前指向器的物品(当前所显示物品)
int m_pos[][]; //每个物品坐标(最大容量64) private://用于打印显示的属性
char** m_surface; //背包外观
int m_row; //背包高度
int m_colu; //背包宽度
int m_x; //背包打开位置x
int m_y; //背包打开位置y }; #endif //! _BACKPACK_H_

Backpack.h

 #include <string.h>
#include <conio.h>
#include "..//Marco.h"
#include "..//Body//Body.h"
#include "..//Role//Hero.h"
#include "..//GameMgr///GameOI.h"
#include "Backpack.h"
#include "..//Map/Map.h" //======= 构造函数 ===============
Backpack::Backpack(Role* pRole)
{
//初始化
m_role = pRole; m_bodyArr = new Body*[]; //初始背包
if (m_bodyArr == nullptr) return;
for (int i = ; i < ; i++)
m_bodyArr[i] = nullptr; m_capacity = ; //背包容量
m_row = m_capacity/ + ; //背包高度
m_colu = ; //背包宽度 m_index = ; //默认指向第一个
m_surface = nullptr; //默认框架数据nullptr m_x = ;
m_y = ; //初始化背包框架数据
this->InitFrame();
} Backpack::~Backpack()
{
if (m_bodyArr != nullptr)
{
delete[] m_bodyArr;
m_bodyArr = nullptr;
}
} //==================================== 外部接口函数 ===================================
//======= 打印外观 ===============
void Backpack::OutputSurface()
{
//设置打印颜色
Color(ColorType::CT_White, ColorType::CT_Violet);
//打印框架
for (int i = ; i < m_row; i++)
for (int j = ; j < m_colu - ; j++)
Print(m_surface[i][j], i + m_x, j + m_y); //打印文字-上部分
GotoXY(m_x, m_y + );
cout << "【" << m_role->GetName() << "】的背包";
Color(ColorType::CT_White, ColorType::CT_TBlue);
GotoXY(m_x, m_y + );
cout<<"〔容量"<<m_capacity<<"格〕";
GotoXY(m_x + , m_y + );
cout << "【物品名称】 【数量】";
GotoXY(m_x + , m_y + );
cout << "【物品名称】 【数量】"; //打印文字-下部分
GotoXY(m_x + + m_capacity / + , m_y + );
cout << "【金币】: " << m_role->GetMoney();
GotoXY(m_x + + m_capacity / + , m_y + );
cout << "【Y使用物品/ B退出】"; //打印显示所有的物品
this->OutputAllBody(); //每次初始打印背包外观,醒目显示当前指向物体
this->OutputCurBody(); //背包操作函数
this->ChooseBody();
} //======= 关闭外观 ===============
void Backpack::CloseSurface()
{
Map* map = m_role->GetGameOI()->GetMap(); for (int i = ; i < m_row; i++)
for (int j = ; j < m_colu - ; j++)
map->OutputMap(i+m_x, j + m_y);
} //======= 添加物品 ===============
void Backpack::PushBackBody(Body* pBody)
{
if (pBody == nullptr)//传进无效数据
return; pBody->SetOwner(m_role); int indexNull = ;//标记第1个空格子 for (int i = ; i < m_capacity;i++) //遍历每一个物品
{
//标记找到的第一个空格子
if (!indexNull && m_bodyArr[i] == nullptr)
indexNull = i + ; //如果物品相同(名字判断)
if (m_bodyArr[i]!= nullptr && strcmp(m_bodyArr[i]->GetName(), pBody->GetName()) == )
{
int countMax = m_bodyArr[i]->GetCountMax(); //物体最大叠加数
int pTempCount = m_bodyArr[i]->GetCountCur(); //目标物体当前数
int pCount = pBody->GetCountCur(); //添加物体当前数 //当数量不超过最大堆叠数时,直接添加进去
if (pTempCount + pCount <= countMax)
{
m_bodyArr[i]->SetCountCur(pTempCount + pCount);
//释放该物品
delete pBody;
pBody = nullptr;
}
else //否则 pTempCount + pCount > countMax
{
pBody->SetCountCur(pTempCount + pCount - countMax);
m_bodyArr[i]->SetCountCur(countMax);
}
}
} //还有剩余没装完,且存在空格子时
if ( indexNull && pBody != nullptr)
m_bodyArr[indexNull - ] = pBody;
} //======= 扩容函数 ===============
void Backpack::GetCapacity()
{
if (m_capacity == ) //已经达到最大容量
return; Body** bodyArrTemp = new Body*[m_capacity + ]; //初始背包
if (bodyArrTemp == nullptr) return; for (int i = ; i < m_capacity + ; i++)
bodyArrTemp[i] = i< m_capacity ? m_bodyArr[i]:nullptr; m_capacity = m_capacity + ; //容量加num
m_row = m_row + ; //背包高度 delete[] m_bodyArr;
m_bodyArr = bodyArrTemp; this->InitFrame(); //录入新的框架数据
} //======= 选择物品 ===============
void Backpack::ChooseBody()
{
while (true)
{
char choose = getch(); //选择按键
if (choose == -) choose = getch(); //屏蔽-32 //当按了方向键,移动刷子
if (choose == || choose == || choose == || choose == )
{
int dPos = ;
switch (choose)
{
case : if (m_index > ) dPos = -; break;
case : if (m_index < m_capacity - ) dPos = +; break;
case : if (m_index > ) dPos = -; break;
case : if (m_index < m_capacity) dPos = +; break;
}
if (dPos != ) //发生了变动
{
this->CleanCurBody(); //清除原位置
this->EraseBodyInfo(); //清除原物品信息 m_index += dPos;
this->OutputCurBody(); //打印新位置
}
} //按Y 使用物品
if (choose == 'y' || choose == 'Y')
this->UseBody(); //按B 退出背包
if (choose == 'B' || choose == 'b')
{
this->CloseSurface();
return;
}
}
} //获取物品容器
Body** Backpack::GetBodyArr()
{
return m_bodyArr;
} //====================================== private 内部操作函数 =====================================================
//=======导入背包框架===============
void Backpack::InitFrame()
{
const int colu = ;
char PackHead[][colu] = //头部
{ "",
"mmmmmmmmmmmmmmmmmmmmmmmmm",
"m00000000000*00000000000m" }; char PackMid[colu] = //背包部分
{ "m00000000000*00000000000m" }; char PackBack[][colu] = //底部
{ "m%%%%%%%%%%%)%%%%%%%%%%%m",
"m00000000000000000000000m",
"m00000000000000000000000m",
"m00000000000000000000000m",
"m%%%%%%%%%%%&%%%%%%%%%%%m",
"m00000000000*00000000000m",
"mmmmmmmmmmmmmmmmmmmmmmmmm" }; //将新数据存到背包
if (m_surface != nullptr)
DeleteCharMemory(m_surface, m_row - );
m_surface = GetCharMemory(m_row, m_colu);
if (m_surface == nullptr) return; //记录每个元素的坐标
for (int i = ; i < m_capacity; i += )
{
m_pos[i][] = + i / ; m_pos[i][] = ;
m_pos[i + ][] = + i / ; m_pos[i + ][] = ;
} //框架数据赋值(i是框架surface的行,h是Head的行,b是Back的行)
for (int i = , h = , b = ; i < m_row; i++)
{
if (i >= && i < ) //头部赋值
strcpy(m_surface[i], PackHead[h++]);
else if (i >= + m_capacity / ) //尾部赋值
strcpy(m_surface[i], PackBack[b++]);
else//( i>= 3 + m_capacity / 2 ) //中部赋值
strcpy(m_surface[i], PackMid);
}
} //打印显示所有的物品
void Backpack::OutputAllBody()
{
for (int i = ; i < m_capacity; i++)
{
if (m_bodyArr[i] == nullptr)
continue; //打印物品名字
GotoXY(m_pos[i][] + m_x, m_pos[i][] + m_y);
cout << m_bodyArr[i]->GetName();
//打印物品数量
GotoXY(m_pos[i][] + m_x, m_pos[i][] + + m_y);
printf("%02d/%02d", m_bodyArr[i]->GetCountCur(), m_bodyArr[i]->GetCountMax());
}
} //打印当前指向元素(改变醒目颜色)
void Backpack::OutputCurBody()
{
//改醒目颜色
Color(ColorType::CT_LGreen, ColorType::CT_Red); if (m_bodyArr[m_index - ] != nullptr)
{
//打印物品名字
GotoXY(m_pos[m_index - ][] + m_x, m_pos[m_index - ][] + m_y);
cout << m_bodyArr[m_index - ]->GetName();
//打印物品数量
GotoXY(m_pos[m_index - ][] + m_x, m_pos[m_index - ][] + + m_y);
printf("%02d/%02d", m_bodyArr[m_index - ]->GetCountCur(), m_bodyArr[m_index - ]->GetCountMax());
//打印物品信息
this->OutputBodyInfo(m_bodyArr[m_index - ]);
}
else
{
GotoXY(m_pos[m_index - ][] + m_x, m_pos[m_index - ][] + m_y);
cout << " ";
}
//恢复系统色
Color(ColorType::CT_White, ColorType::CT_TBlue);
} //恢复当前指向元素醒目颜色
void Backpack::CleanCurBody()
{
if (m_bodyArr[m_index - ] != nullptr)
{
//打印物品名字
GotoXY(m_pos[m_index - ][] + m_x, m_pos[m_index - ][] + m_y);
cout << m_bodyArr[m_index - ]->GetName();
//打印物品数量
GotoXY(m_pos[m_index - ][] + m_x, m_pos[m_index - ][] + + m_y);
printf("%02d/%02d", m_bodyArr[m_index - ]->GetCountCur(), m_bodyArr[m_index - ]->GetCountMax());
//打印物品信息
this->EraseBodyInfo();
}
else
{
GotoXY(m_pos[m_index - ][] + m_x, m_pos[m_index - ][] + m_y);
cout << " ";
}
} //打印物品信息
void Backpack::OutputBodyInfo(Body* pBody)
{
pBody->BodyInfo(m_x + + m_capacity / , m_y + );
pBody->OutputTip(m_x + + m_capacity / , m_y + );
} //清除物品信息
void Backpack::EraseBodyInfo()
{
for (int i = ; i < ; i++)
{
GotoXY(m_x + + m_capacity / + i, m_y + );
for (int j = ; j <= m_colu - ; j++)
cout << " ";
}
} //使用物品
void Backpack::UseBody()
{
m_role->GetGameOI()->AppendBody(m_bodyArr[m_index - ], m_index); this->OutputCurBody();
m_role->EquipSurface();
}

Backpack.cpp

【C++第一个Demo】---控制台RPG游戏2【通用宏、背包类】的更多相关文章

  1. 【C++第一个Demo】---控制台RPG游戏4【角色系统】

    [角色基类] #ifndef _ROLE_H_ #define _ROLE_H_ #include<list> #include<vector> #include " ...

  2. 【C++第一个Demo】---控制台RPG游戏3【登陆菜单树】

    [登陆系统--树结构] 1 首先我这里设计,由一个基类MainMenu构建树结构,并实现控制台上菜单之间的切换和返回操作 #ifndef _UI_BASE_H_ #define _UI_BASE_H_ ...

  3. 【C++第一个Demo】---控制台RPG游戏1【游戏简介】

       经过1个月的制作和多次修改,终于有了基本雏形(此篇仅用于纪念历时3个多月C/C++学习所付出努力,也给和我一样苦恼于不能快速理解面向对象的同学们一点灵感) 在制作这个Demo过程中也受到了很多大 ...

  4. Cocos2dx游戏开发系列笔记13:一个横版拳击游戏Demo完结篇

    懒骨头(http://blog.csdn.net/iamlazybone QQ:124774397 ) 写下这些东西的同时 旁边放了两部电影 周星驰的<还魂夜> 甄子丹的<特殊身份& ...

  5. 【android原生态RPG游戏框架源码】

    转载请注明原创地址:http://www.cnblogs.com/zisou/p/android-RPG.html 这份源码是在今年6月份写的,当时公司有一个技术部们的学习讨论的讲座,然后我自己就写了 ...

  6. RPG游戏开发基础教程

    RPG游戏开发基础教程 第一步 下载RPG Maker 开发工具包 1.RPG Maker 是什么? RPG Maker 是由Enterbrain公司推出的RPG制作工具. 中文译名为RPG制作大师. ...

  7. 如何制作一款HTML5 RPG游戏引擎——第五篇,人物&人物特效

    上一次,我们实现了对话类,今天就来做一个游戏中必不可少的——人物类. 当然,你完全是可以自己写一个人物类,但是为了方便起见,还是决定把人物类封装到这个引擎里. 为了使这个类更有意义,我还给人物类加了几 ...

  8. 使用HTML5制作简单的RPG游戏

    很久以前就想着做一个游戏,但什么都不会又不知道从哪里开始,胡乱找来一些书籍和资料结果太深奥看不懂,无奈只能放弃.这一弃就是十多年,倥偬半生,眼看垂垂老矣,还是没能有什么成果. 近年来游戏引擎越来越多, ...

  9. Silverlight 2.5D RPG游戏技巧与特效处理:(十一)AI系统

    Silverlight 2.5D RPG游戏技巧与特效处理:(十一)AI系统 作者: 深蓝色右手  来源: 博客园  发布时间: 2011-04-19 11:18  阅读: 1282 次  推荐: 0 ...

随机推荐

  1. Protocol协议分发器

    1. 用途: 能够制定多个对象实现<Protocol>, 同一个代理方法,可以在多个对象中同时实现 2.原理: 利用消息转发机制,将方法分发到多个对象中 使用方式: self.tableV ...

  2. xcodebuild 自动化打包

    altool 文档 使用xcode自带的xcodebuild 命令通过脚本进行打包 打包->导出ipa, 两行关键的脚本代码 1.Archive xcodebuild archive -arch ...

  3. 判断是否是NaN

    if (isNaN(parseInt(x))) { alert("非数字"); } else{ alert("数字"); }

  4. dubbo远程服务调用和maven依赖的区别

    dubbo:跨系统通信.比如:两个系统,一个系统A作客户端,一个系统B作服务器, 服务器B把自己的接口定义提供给客户端A,客户端A将接口定义在spring中的bean.客户端A可直接使用这个bean, ...

  5. 爬取拉勾网python工程师的岗位信息并生成csv文件

    转载自:https://www.cnblogs.com/sui776265233/p/11146969.html 代码写得很好,但是目前只看得懂前一部分 一.爬取和分析相关依赖包 Python版本: ...

  6. shell数学运算

    shell的数学运算 branches@ubuntu:~$ var1=$[ * ] branches@ubuntu:~$ echo $var1 branches@ubuntu:~$ var2=$[$v ...

  7. kubernetes容器集群管理部署master节点组件

    集群部署获取k8s二进制包 [root@master ~]# wget https://dl.k8s.io/v1.15.0/kubernetes-server-linux-amd64.tar.gz [ ...

  8. OkHttp的使用

    Download OkHttp3 implementation 'com.squareup.okhttp3:okhttp:3.10.0' 1.1. 异步GET请求 -new OkHttpClient; ...

  9. Ansible--02 ansible playbook的应用

    目录 Ansible playbook的应用 什么是playbook playbook的组成 playbook和Ad-Hoc对比 YAML语法 安装httpd练习 rsyncd实战 实战1: 实战2: ...

  10. linux随笔-06

    用户身份与文件权限 用户身份与能力 Linux系统的管理员之所以是root,并不是因为它的名字叫root,而是因为该用户的身份号码即UID(User IDentification)的数值为0. 在Li ...