HRESULT CObjMgr::AddObject( CPrototype* pProto, const TCHAR* pObjKey ) { map<const TCHAR*,list<CObj*>>::iterator iter = m_MapObject.find(pObjKey); CObj* pProtoInst = ((CObjProto*)pProto)->GetProto(pObjKey); if (pProtoInst == NULL) { return E_FAIL; } //객체를 가져온다 CObj* pObject = pProtoInst->Clone(); //복사해서 담아온다 pObject->Initialize(); if (iter == m_MapObject.end()) {//처음에 iter가 없다 (키가없다) list<CObj*> Objlist; Objlist.push_back(pObject); //프로토타입으로 복제한 오브젝트를 넣어줌 m_MapObject.insert(make_pair(pObjKey,Objlist)); } else {//키가 있을때 iter->second.push_back(pObject); } return S_OK; }
void CGameFrameWork::CreateBlock(const Point2D& pos) { vector<Tile*> tile = dynamic_cast<CBoard*>(m_pBoard)->GetTile(); int idx = 0; for (auto p = tile.cbegin(); p != tile.cend(); ++p, ++idx) { if ((*p)->pos.x == pos.x && (*p)->pos.y == pos.y) break; } tile[idx]->option = 1; CObj* block = new CBlock(pos, 2, idx); block->Initialize(); m_vecBlock.push_back(block); }
void CGameFrameWork::CreateBlock() { srand(unsigned(time(NULL))); vector<Tile*> tile = dynamic_cast<CBoard*>(m_pBoard)->GetTile(); int idx = rand() % 16; while (tile[idx]->option != 0) idx = rand() % 16; tile[idx]->option = 1; CObj* block = new CBlock(tile[idx]->pos, 2, idx); block->Initialize(); m_vecBlock.push_back(block); ///////////////////////////////////////// m_NewBlockPos = tile[idx]->pos; ///////////////////////////////////////// }