当前位置: 首页>>代码示例>>C++>>正文


C++ Cell::GetCol方法代码示例

本文整理汇总了C++中Cell::GetCol方法的典型用法代码示例。如果您正苦于以下问题:C++ Cell::GetCol方法的具体用法?C++ Cell::GetCol怎么用?C++ Cell::GetCol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cell的用法示例。


在下文中一共展示了Cell::GetCol方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: StartToFall

void SolveWizard::StartToFall(const DIRECTION dir)
{
    unsigned int fallingTime = this->gameManager->map->GetTimer();
    for (int col = 0; col < this->gameManager->map->GetWidth(); col++)
    {
        int offset = 0; // offset == (newPos - pos) * height
        Cell *pos = this->gameManager->map->cells[0][col];
        Cell *newPos = pos;

        // find the lowest vacant cell
        while (pos != NULL && pos->GetColor() != GemColor::Vacant)
        {
            pos = this->gameManager->map->Neighbor(*pos, dir);
        }
        // now, pos->GetColor() == GemColor::Vacant

        newPos = pos;
        while (newPos != NULL)
        {
            // find the next non-vacant cell newPos
            if (newPos->GetColor() != GemColor::Vacant)
            {
                // 1. move cell pos to the cell newPos' position
                pos->setPosition(this->gameManager->map->GetCellOriginalPos(*newPos));
                // 2. set cell pos' color to the cell newPos', newPos's to vacant
                // change both color and type
                pos->SetColorGemTypeDir(newPos->GetColor(), newPos->GetGemType(), newPos->GetDirection());
                newPos->SetColorGemTypeDir(GemColor::Vacant, GemType::Normal, DIRECTION::DIR1);
                // 3. set pos as falling
                pos->falling = true; 
                pos->fallingTime = fallingTime;
                this->fallingCount++;
                // move pos and newPos to next cell
                pos = this->gameManager->map->Neighbor(*pos, dir);
                newPos = this->gameManager->map->Neighbor(*newPos, dir);
            }
            else
            {
                offset++; // pos + offset = newPos
                newPos = this->gameManager->map->Neighbor(*newPos, dir);
            }
        }
        // if all upper cells above pos are vacant
        while (pos != NULL)
        {
            // 1. move pos according to offset
            pos->setPosition(Map::CalcCellPositionByIndex(pos->GetRow() + offset, pos->GetCol()));
            // 2. assgin random color to pos
            pos->SetColorGemTypeDir(Cell::RandomColor(), GemType::Normal, DIRECTION::DIR1);
            // 3. set pos as falling
            pos->falling = true;
            pos->fallingTime = fallingTime;
            this->fallingCount++;
            // move pos to next
            pos = this->gameManager->map->Neighbor(*pos, dir);
        }
    }
}
开发者ID:subject119,项目名称:subject201,代码行数:58,代码来源:SolveWizard_.cpp

示例2: aStar

stack<Cell*> aStar(Board& board,Cell* start,Cell* end)
{
	stack<Cell*> path;

	Cell *current;
	Cell *child;

	// Define the open and the close list
	list<Cell*> openList, closeList;
	list<Cell*>::iterator i;

	unsigned int n = 0, size = board.GetRowsCount() * board.GetColsCount();

    // Add the start point to the openList
	openList.push_back(start);
	start->SetOpened(true);

	while (n==0 || ( current!=end && n<size) )
	{
		// Look for the smallest F value in the openList and make it the current point
		for (i = openList.begin(); i != openList.end(); i++)
		{
			if (i==openList.begin() || (*i)->GetFar() <= current->GetFar())
			{
				current = (*i);
			}
		}
		// Stop if we reached the end
		if(current==end)
			break;

		// Remove the current point from the openList
		openList.remove(current);
		current->SetOpened(false);

		// Add the current point to the closedList
		closeList.push_back(current);
		current->SetClosed(true);

		// Get all current's adjacent walkable points
		for (int r = -1; r < 2; r++)
		{
			for (int c = -1; c < 2; c++)
			{
				if( (r==0 && c==0) || (r==-1 && c==-1) || (r==-1 && c==1) || (r==1 && c==-1) || (r==1 && c==1) )
					continue;

				child = board.GetCell(current->GetRow() + r, current->GetCol() + c);
				
				// If it's closed or not walkable or if we are at a corner then pass
				if( child == nullptr || child->IsClosed() || child->IsWall() )
					continue;

				if( !child->IsOpened())
				{
					// Add it to the openList with current point as parent
					openList.push_back(child);
					child->SetOpened(true);
					// Compute it's far score
					child->SetParent(current);
					child->ComputeScores(end);
				}
			}
		}
		n++;
	}
	
	// Reset all the cells
	for (i = openList.begin(); i != openList.end(); ++ i)
    {
		(*i)->SetOpened(false);
    }
    for (i = closeList.begin(); i != closeList.end(); ++ i)
    {
		(*i)->SetClosed(false);
    }
	if (current != end)
	{
		return path;
	}
	// Resolve the path starting from the end point
	while (current->HasParent() && current != start)
    {
        path.push(current);
		//current->SetSymbol('+');
        current = current->GetParent();
        n ++;
    }
	path.push(start);
    return path;
}
开发者ID:vpachedzhi,项目名称:PathInMaze,代码行数:91,代码来源:aStar.cpp


注:本文中的Cell::GetCol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。