Ejemplo n.º 1
0
// 重新排列
void CLogic::Realign(BYTE  chess[CHESSCOUNT_H][CHESSCOUNT_W])
{
	CArrayTemplate<CPoint> pos;
	CArrayTemplate<BYTE> data;
	int temp,temp2;

	for(int i=0; i<CHESSCOUNT_H; i++)
	for(int j=0; j<CHESSCOUNT_W; j++)
	{
		if(chess[i][j] != ERROR_ALL)
		{
			pos.InsertAt(pos.GetCount(),CPoint(i,j));
			data.InsertAt(data.GetCount(),chess[i][j]);
		}
		chess[i][j] = ERROR_ALL;
	}
	srand((unsigned int)time(NULL));
	for(; pos.GetCount()>0;)
	{
		temp = rand()%((int)pos.GetCount());
		temp2 = rand()%((int)data.GetCount());
		chess[pos.ElementAt(temp).x][pos.ElementAt(temp).y] = data[temp2];
		pos.RemoveAt(temp);
		data.RemoveAt(temp2);
	}
}
Ejemplo n.º 2
0
//游戏开始
bool __cdecl CTableFrameSink::OnEventGameStart()
{
	m_bIsGameEnd=false;
	m_pITableFrame->SetGameStatus(GS_PLAYING);

	srand((UINT)time(NULL));
	int nRandNum=rand()%19;
	CMD_S_GameStart  start;
	//ZeroMemory(&start,sizeof(start));
	//memset(&start,ERROR_ALL,sizeof(start));

	memset(start.bChess, ERROR_ALL, sizeof(start.bChess));

	//初始化棋盘
	int tempvalue,randnum;
	CArrayTemplate<CPoint> Map;
	for(int i=0;i<CHESSCOUNT_H;i++)
	{
		for(int j=0;j<CHESSCOUNT_W;j++)
		{
			if(LLK_MAP[nRandNum][i][j])
			{
				Map.Add(CPoint(i,j));
			}
		}
	}
	if(Map.GetCount()%2 == 1)
	{
		TRACE("地图棋子为奇数");
		return false;
	}
	//随地图
	for(; Map.GetCount()!=0;)
	{
		//随机一个棋子类型
		if(rand()%10)
		{
			tempvalue = RandNumber(0,MAX_CHESS_VALUE);
		}
		else
		{
			tempvalue =RandNumber(PROP_MIN_VALUE,PROP_MIN_VALUE+PROP_MAX_CNT);
		}
		//找出第一个位置
		randnum = RandNumber(0,(int)Map.GetCount());
		start.bChess[Map.ElementAt(randnum).x][Map.ElementAt(randnum).y] = tempvalue;
		Map.RemoveAt(randnum);
		//找出第二个位置
		randnum = RandNumber(0,(int)Map.GetCount());
		start.bChess[Map.ElementAt(randnum).x][Map.ElementAt(randnum).y] = tempvalue;
		Map.RemoveAt(randnum);
	}
	IServerUserItem * pIServerUserItem;
	for (WORD i=0;i<GAME_PLAYER;i++)
	{
		pIServerUserItem=m_pITableFrame->GetServerUserItem(i);
		if (pIServerUserItem!=NULL)
		{
			m_bPlayStatus [i] = GS_PLAYING;
			memcpy(m_bChess[i],start.bChess,sizeof(m_bChess[i]));
		}
		else
			m_bPlayStatus [i] = GS_FREE;
	}
	memcpy(start.bPlayState, m_bPlayStatus, sizeof(m_bPlayStatus));
	//发送地图数据
	for(int i=0;i<GAME_PLAYER;i++)
	{
		memcpy(start.bPropCnt,m_bPropCnt[i],sizeof(m_bPropCnt[i]));
		m_pITableFrame->SendTableData(i,SUB_S_GAME_START,&start,sizeof(start));
		m_pITableFrame->SendLookonData(i,SUB_S_GAME_START,&start,sizeof(start));
	}
	return true;
}
Ejemplo n.º 3
0
// 寻找符合条件的最短路径
void CLogic::ShortPath(BYTE  chess[CHESSCOUNT_H][CHESSCOUNT_W],CArrayTemplate<CPoint> * r, CPoint one , CPoint two, CPoint* ipoint)
{
	CArrayTemplate<CPoint> t;
	CPoint hotpoint;
	bool blog = true;


	if( one.x !=two.x)
	{
		for(int i= one.x,j=one.y; i!=two.x; one.x<two.x?i++:i--)
		{
			if(i!=one.x && chess[j][i]!=ERROR_ALL)
			{
				blog = false;
				break;
			}
			else
			{
				t.InsertAt(t.GetCount(),CPoint(i,j));
			}
		}
	}
	if(one.y != two.y)
	{
		hotpoint.x = two.x;
		hotpoint.y = one.y;
		for(int i=two.x,j = one.y;j!=two.y; one.y<two.y ? j++:j--)
		{
			if(chess[j][i]!=ERROR_ALL)
			{
				blog = false;
				break;
			}
			else
				{
					t.InsertAt(t.GetCount(),CPoint(i,j));
				}
		}
	}
	if(blog)
	{
		for(int i=0; i<t.GetCount(); ++i)
		{
			r->InsertAt(r->GetCount(),CPoint(t.ElementAt(i).x,t.ElementAt(i).y));
			if(ipoint!=NULL)
			{
				ipoint->x = hotpoint.x;
				ipoint->y = hotpoint.y;
			}
		}
		return;
	}
	else
	{
		t.RemoveAll();
		hotpoint.x = ERROR_ALL;
		hotpoint.y = ERROR_ALL;
		blog = true;
	}

	if(one.y != two.y)
	{
		for(int i=one.x,j = one.y;j!= two.y; one.y<two.y ? j++:j--)
		{
			if(j!= one.y&&chess[j][i]!=ERROR_ALL)
			{
				t.RemoveAll();
				blog = false;
				break;
			}
			else
				{
					t.InsertAt(t.GetCount(),CPoint(i,j));
				}
		}
	}
	if(one.x != two.x)
	{
		hotpoint.x = one.x;
		hotpoint.y = two.y;
		for(int i= one.x,j=two.y; i!=two.x; one.x<two.x?i++:i--)
		{
			if(chess[j][i]!=ERROR_ALL)
			{
				t.RemoveAll();
				blog = false;
				break;
			}
			else
				{
					t.InsertAt(t.GetCount(),CPoint(i,j));
				}
		}
	}

	if(blog)
	{
		for(int i=0; i<t.GetCount(); ++i)
		{
			r->InsertAt(r->GetCount(),CPoint(t.ElementAt(i).x,t.ElementAt(i).y));
			if(ipoint!=NULL)
			{
				ipoint->x = hotpoint.x;
				ipoint->y = hotpoint.y;
			}
		}
		return;
	}
	return;
}