?? matrix.cpp
字號:
// Matrix.cpp: implementation of the CMatrix class.
#include "Matrix.h"
#include "Object.h"
#include "Item.h"
#include "Human.h"
CMatrix::CMatrix()
{
// 初始ID = 1
m_seq = 1;
}
CMatrix::~CMatrix()
{
}
// 創(chuàng)建一個新物體
CObject *CMatrix::CreateObject(long type)
{
CObject *ob = NULL;
// 根據(jù)物體類型創(chuàng)建實例
switch(type)
{
case OTYPE_ITEM:
ob = new CItem;
break;
case OTYPE_HUMAN:
ob = new CHuman;
break;
}
if(ob)
{
// 設置ID
ob->SetUniqueId(m_seq++);
// 添加到物體列表中
m_obList.push_back(ob);
}
return ob;
}
// 銷毀一個物體
void CMatrix::DestroyObject(CObject *ob)
{
// 從物體列表中清除
m_obList.remove(ob);
// 釋放內(nèi)存
delete ob;
}
// 根據(jù)ID查找物體
CObject * CMatrix::FindObject(long uid)
{
CObject *ob = NULL;
list<CObject*>::iterator it;
for(it = m_obList.begin(); it != m_obList.end();it++)
{
if((*it)->GetUniqueId() == uid)
{
ob = (*it);
break;
}
}
return ob;
}
// 取得物體的總數(shù)量
int CMatrix::GetObjectCount()
{
return m_obList.size();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -