一个常常用到的管理类
来源:互联网 发布:如何在淘宝申请品牌 编辑:程序博客网 时间:2024/05/22 02:05
类似这种管理类,经常的写。烦死了,留一个在这里,以后就直接拷贝了
如果有错误,请指出,谢谢
头文件
#include <Windows.h>
#include <list>
using namespace std;
struct Player
{
DWORD PlayerID;
string strName;
int nLevel;
int nScore;
};
class CScoreManage
{
public:
CScoreManage(void);
~CScoreManage(void);
CScoreManage(int nCount);
bool InitScore(int nCount);
typedef list<Player*> ListPlayer;
ListPlayer m_ListPlayer;
bool UpdateInfo(Player& player);
void DeletePlayer();
};
extern CScoreManage ScoreManage;
///////////////////////////////////////////////////////////////////////////////////
cpp文件:
#include "ScoreMag.h"
CScoreManage::CScoreManage(void)
{
}
CScoreManage::CScoreManage( int nCount )
{
InitScore( nCount );
}
CScoreManage::~CScoreManage(void)
{
DeletePlayer();
}
bool CScoreManage::InitScore( int nCount )
{
bool bRs = false;
for (int i= 0;i < nCount; i++)
{
Player* pPlayer = new Player;
if (!pPlayer)
{
return bRs;
}
pPlayer->nLevel = 0;
pPlayer->nScore = 0;
pPlayer->PlayerID = 0;
m_ListPlayer.push_back(pPlayer);
}
bRs = true;
return bRs;
}
bool CScoreManage::UpdateInfo( Player& player )
{
bool bRs = false;
ListPlayer::iterator ite;
for (ite = m_ListPlayer.begin(); ite != m_ListPlayer.end(); ite++)
{
if ( (*ite)->PlayerID == player.PlayerID)
{
(*ite)->nScore = player.nScore;
(*ite)->nLevel = player.nLevel;
}
}
return bRs = true;
}
void CScoreManage::DeletePlayer()
{
ListPlayer::iterator ite;
for (ite = m_ListPlayer.begin(); ite != m_ListPlayer.end(); ite++)
{
if (*ite)
{
delete *ite;
*ite = 0;
}
}
m_ListPlayer.clear();
}
- 一个常常用到的管理类
- 常常用到判断电话号码的正则表达式
- java反射学习--常常用到的的方法
- 程序员常常会用到的几款文本编辑器
- 项目用到的窗口管理类
- 常常用到的跳转回上一页(哪里来的回哪里去)
- linux下基本常常用到的shell命令(部分)
- CentOS 7 环境开发PHP项目常常会用到的指令
- 一个我现在用到的Hibernate类
- 一个我现在用到的Hibernate类
- 项目用到的一个资源管理类
- 用到的一个json
- 工程设计中 uart 常常会用到啊
- 那些行业常常会用到ABBYY
- 为什么工程学里常常用到分贝
- 常常冠以一个异常美丽的词:缘分
- 一个数学中常用到的复数类的实现
- 一个用到Boost中time_duration类而产生的bug
- Android执行linux外部命令
- Polynomial use LinkList
- Android执行shell命令
- 覆盖方法遵循原则
- sizeof的使用简单分析
- 一个常常用到的管理类
- Fck编辑器快速嵌入到jsp页面中
- 】PhoneLookup.NUMBER----ContactsContract类Android 2.0 API改变
- ASIHTTPRequest官方文档
- java和c语言中数组定义初始化的区别
- Android混淆、反编译以及反破解的简单回顾
- Android 数字签名学习笔记
- struts自定义拦截器
- CCSV5.2(Code Composer Studio v5)下使用TMS320F28335