bool CGameLogic::IsLink(int anMap[MAX_ROW][MAX_COL],Vertex v1, Vertex v2) { PushVertex(v1); //Link is a straight line of horizontal if(v1.row == v2.row) { if(LinkInRow(anMap,v1,v2)) return true; if(TwoCornerLink(anMap,v1,v2)) return true; } //link in a straight line of vertical else if(v1.col == v2.col) { if(LinkInCol(anMap,v1,v2)) return true; if(TwoCornerLink(anMap,v1,v2)) return true; } else if(OneCornerLink(anMap,v1,v2)) { PushVertex(v2); return true; } else if(TwoCornerLink(anMap,v1,v2)) { return true; } PopVertex(); return false; }
/* ================== Push 4 vertices into the buffer creating a quad ================== */ void IND_SurfaceManager::Push4Vertices (CUSTOMVERTEX2D *pVertices, int pPosVert, int pPosX, int pPosY, int pPosZ, int pWidthBlock, int pHeightBlock, float pU, float pV) { // Push the 4 vertex of the quad // The pushing order is important // Upper-right PushVertex (pVertices, pPosVert, pPosX + pWidthBlock, pPosY - pHeightBlock, pPosZ, pU, pV); // Lower-right PushVertex (pVertices, pPosVert+1, pPosX + pWidthBlock, pPosY, pPosZ, pU, 0.0f); // Upper-left PushVertex (pVertices, pPosVert+2, pPosX, pPosY - pHeightBlock, pPosZ, 0.0f, pV); // Lower-left PushVertex (pVertices, pPosVert+3, pPosX, pPosY, pPosZ, 0.0f, 0.0f); }
/* ================== Push 4 vertices into the buffer creating a quad ================== */ void IND_Surface::Push4Vertices (CUSTOMVERTEX2D *pVertices, int pPosVert, int pX, int pY, int pZ, int pWidthBlock, int pHeightBlock, int pWidth, int pHeight) { // Push the 4 vertex of the quad // The pushing order is important // Upper-right PushVertex (pVertices, pPosVert, pX + pWidthBlock, pY - pHeightBlock, pZ, (float) (pX + pWidthBlock) / pWidth, 1.0f - ( (float) (pY - pHeightBlock) / pHeight) ); // Lower-right PushVertex (pVertices, pPosVert+1, pX + pWidthBlock, pY, pZ, (float) (pX + pWidthBlock) / pWidth, 1.0f - ( (float) pY / pHeight) ); // Upper-left PushVertex (pVertices, pPosVert+2, pX, pY - pHeightBlock, pZ, (float) pX / pWidth, 1.0f - ( (float) (pY - pHeightBlock) / pHeight) ); // Lower-left PushVertex (pVertices, pPosVert+3, pX, pY, pZ, (float) pX / pWidth, 1.0f - ( (float) pY / pHeight) ); }
bool GameLogic::SearchPath2(CGraph &graph, int nV0, int nV1) { //得到顶点数 int nVexnum = graph.GetVexnum(); //遍历图中nV0行,从0列到nVexnum列,值为true的点 for (int nVi = 0; nVi < nVexnum; nVi++) { if (graph.GetArc(nV0, nVi) && !IsExist(nVi)) { //压入当前顶点。假设为路径的一个有效顶点 PushVertex(nVi); if (m_nCorner > 2) { PopVertex(); continue; } if (nVi != nV1) { //当中间顶点为空时,表示该条路径不通 if (graph.GetVertex(nVi) != BLANK) { PopVertex(); continue; } //如果nVi是一个已消除的点,则判断(nVi,nV1)是否连通 if (SearchPath2(graph, nVi, nV1)) { return true; } } else { return true; } PopVertex(); } } return false; }
bool GameLogic::SearchValidPath(CGraph& graph) { //得到顶点数 int nVexnum = graph.GetVexnum(); for (int i = 0; i < nVexnum; i++) { //得到第一个非空顶点 //遍历得到第二个同色顶点 for (int j = 0; j < nVexnum; j++) { if (i != j) { //如果i和j同色 int nInfo1 = graph.GetVertex(i); int nInfo2 = graph.GetVertex(j); if (nInfo1 == nInfo2 && nInfo1 != BLANK && nInfo2 != BLANK) { //压入第一个顶点 PushVertex(i); //搜寻两个点之间的连通路径 if (SearchPath2(graph, i, j)) { return true; } PopVertex(); } } } } return false; }
bool CGameLogic::LinkInCol(int anMap[MAX_ROW][MAX_COL] ,Vertex v1, Vertex v2) { int nRow1 = v1.row; int nRow2 = v2.row; int nCol = v1.col; if(nRow1 > nRow2) { for(int i = nRow2 +1 ; i <nRow1; i++) { if(anMap[i][nCol]!=-1) return false; } } //Link in a straight line else { for(int i = nRow1 + 1 ; i < nRow2; i++) { if(anMap[i][nCol]!=-1) return false; } } PushVertex(v2); return true; }
bool GameLogic::IsLink(CGraph &graph, Vertex v1, Vertex v2) { int nV1Index = v1.row * MAX_PIC_NUM + v1.col; int nV2Index = v2.row * MAX_PIC_NUM + v2.col; PushVertex(nV1Index); if (SearchPath2(graph, nV1Index, nV2Index)) { return true; } PopVertex(); //采用线性结构判断方法来对非线性结构判断 return false; }
bool CGameLogic::LinkInRow(int anMap[MAX_ROW][MAX_COL],Vertex v1, Vertex v2) { int nCol1 = v1.col; int nCol2 = v2.col; int nRow = v1.row; //Link is a straight line if(nCol1<nCol2) for(int i = nCol1 +1 ; i < nCol2; i++) { if(anMap[nRow][i]!=-1) return false; } else for(int i = nCol2 +1 ; i < nCol1; i++) { if(anMap[nRow][i]!=-1) return false; } PushVertex(v2); return true; }
bool CGameLogic::TwoCornerLink(int anMap[MAX_ROW][MAX_COL],Vertex v1, Vertex v2) { Vertex left,right,temp; left.col=v1.col; right.col=v2.col; for(int i = 0; i< MAX_ROW; i++) { if(LineX(anMap,i,v1.col,v2.col)){ if(LineY(anMap,i,(v1.row > i) ? v1.row-1 : v1.row+1 , v1.col) && LineY(anMap,i,(v2.row > i) ? v2.row-1 : v2.row+1, v2.col)){ temp.col=v1.col; temp.row=i; PushVertex(temp); temp.col=v2.col; temp.row=i; PushVertex(temp); PushVertex(v2); return true; } } } left.row=v1.row; right.row=v2.row; for(int i = 0; i< MAX_COL; i++) { if(LineY(anMap,v1.row,v2.row,i)){ if(LineX(anMap,v1.row,i,(v1.col >i) ? v1.col-1 :v1.col+1) && LineX(anMap,v2.row,i,(v2.col>i) ? v2.col-1 : v2.col+1)){ temp.col=i; temp.row=v1.row; PushVertex(temp); temp.col=i; temp.row=v2.row; PushVertex(temp); PushVertex(v2); return true; } } } return false; }
bool CGameLogic::OneCornerLink(int anMap[MAX_ROW][MAX_COL],Vertex v1,Vertex v2) { int nRow1 = v1.row; int nRow2 = v2.row; int nCol1 = v1.col; int nCol2 = v2.col; Vertex temp; if(nRow1 > nRow2) { if(nCol1<nCol2) { if(LineY(anMap,nRow2,nRow1-1,nCol1)&&LineX(anMap,nRow2,nCol1,nCol2-1)){ temp.row = nRow2; temp.col = nCol1; PushVertex(temp); return true;} if(LineY(anMap,nRow2+1,nRow1,nCol2)&&LineX(anMap,nRow1,nCol1+1,nCol2)){ temp.row = nRow1; temp.col = nCol2; PushVertex(temp); return true;} } else { if(LineY(anMap,nRow2+1,nRow1,nCol2)&&LineX(anMap,nRow1,nCol2,nCol1-1)){ temp.row = nRow1; temp.col = nCol2; PushVertex(temp); return true;} if(LineY(anMap,nRow2,nRow1-1,nCol1)&&LineX(anMap,nRow2,nCol2+1,nCol1)){ temp.row = nRow2; temp.col = nCol1; PushVertex(temp); return true;} } } else { if(nCol1 < nCol2) { if(LineY(anMap,nRow1,nRow2-1,nCol2)&&LineX(anMap,nRow1,nCol1+1,nCol2)){ temp.row = nRow1; temp.col = nCol2; PushVertex(temp); return true;} if(LineY(anMap,nRow1+1,nRow2,nCol1)&&LineX(anMap,nRow2,nCol1,nCol2-1)){ temp.row = nRow2; temp.col = nCol1; PushVertex(temp); return true;} } else { if(LineY(anMap,nRow1+1,nRow2,nCol1)&&LineX(anMap,nRow2,nCol2+1,nCol1)){ temp.row = nRow2; temp.col = nCol1; PushVertex(temp); return true;} if(LineY(anMap,nRow1,nRow2-1,nCol2)&&LineX(anMap,nRow1,nCol2,nCol1-1)){ temp.row = nRow1; temp.col = nCol2; PushVertex(temp); return true;} } } return false; }
void rImmediateBuffer::PushVertex(const rVector3& position, const rVector2& texCoord){ PushVertex(position); PushVertex(texCoord); }