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


C++ Stone类代码示例

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


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

示例1: checkNeighbourLiberty

void StoneHandler::checkNeighbourLiberty(int x, int y, Q3ValueList<int> &libCounted, int &liberties, Matrix *m)    //SL added eb 8
{
	if (!x || !y)
		return;
	
	Stone *s;
//  CHECK_PTR(m); // SL added eb 8

  if (m==NULL) //added eb 8 -> we don't have a matrix passed here, so we check on the board
  {
	  if (x <= boardHandler->board->getBoardSize() && y <= boardHandler->board->getBoardSize() && x >= 0 && y >= 0 &&
		  !libCounted.contains(100*x + y) &&
  		((s = stones->find(Matrix::coordsToKey(x, y))) == NULL ||
	  	!s->isVisible()))
	  {
		  libCounted.append(100*x + y);
		  liberties ++;
	  }
  }  
  else                                      
  {
    if (x <= boardHandler->board->getBoardSize() && y <= boardHandler->board->getBoardSize() && x >= 0 && y >= 0 &&
	    !libCounted.contains(100*x + y) &&
	    (m->at(x - 1, y - 1) == stoneNone ))         // ?? check stoneErase ?
	  {
		  libCounted.append(100*x + y);
		  liberties ++;
	  }            // end add eb 8
  }
}
开发者ID:alserkli,项目名称:q4Go,代码行数:30,代码来源:stonehandler.cpp

示例2: CHECK_PTR

int StoneHandler::countLibertiesOnMatrix(Group *group, Matrix *m)    
{
	CHECK_PTR(group);
	CHECK_PTR(m);
	
	int liberties = 0;
	Q3ValueList<int> libCounted;
	
	// Walk through the horizontal and vertial directions, counting the
	// liberties of this group.
	for (unsigned int i=0; i<group->count(); i++)
	{
		Stone *tmp = group->at(i);
		CHECK_PTR(tmp);
		
		int x = tmp->posX(),
			y = tmp->posY();
		
		// North
		checkNeighbourLibertyOnMatrix(x, y-1, libCounted, liberties, m);
		
		// West
		checkNeighbourLibertyOnMatrix(x-1, y, libCounted, liberties, m);
		
		// South
		checkNeighbourLibertyOnMatrix(x, y+1, libCounted, liberties, m);
		
		// East
		checkNeighbourLibertyOnMatrix(x+1, y, libCounted, liberties, m);
	}
	return liberties;
}
开发者ID:alserkli,项目名称:q4Go,代码行数:32,代码来源:stonehandler.cpp

示例3: doRegret

void SceneGame::doRegret()
{
	// 游戏还没有开始不能悔棋
	if (_steps.size() == 0)
		return;

	// 恢复最后一步
	Step* step = *_steps.rbegin();
	_steps.pop_back();

	// 具体恢复工作
	Stone* s = _s[step->moveid];
	s->_row = step->rowFrom;
	s->_col = step->colFrom;
	s->setPosition(s->fromPlate());

	Stone* kill;
	if (step->killid != -1)
	{
		kill = _s[step->killid];
		kill->_dead = false;
		kill->setVisible(true);
	}

	_bRedTurn = !_bRedTurn;
	delete step;

	// 避免在选中棋子的情况下,悔棋
	_selectid = -1;
	_selectSprite->setVisible(false);
}
开发者ID:dalechngame,项目名称:mygame,代码行数:31,代码来源:SceneGame.cpp

示例4: checkNeighbour

Group* StoneHandler::checkNeighbour(int x, int y, StoneColor color, Group *group, Matrix *m) //SL added eb 8
{
//	CHECK_PTR(group);
//	CHECK_PTR(m); //added eb 8
  bool visible = false ;
  int size = boardHandler->board->getBoardSize();     //end add eb 8

  Stone *tmp = stones->find(Matrix::coordsToKey(x, y));
  
  // Okay, this is dirty and synthetic :
  // Because we use this function where the matrix can be NULL, we need to check this
  // Furthermore, since this has been added after the first code, we keep the 'stone->visible' test where one should only use the 'matrix' code
  if (m != NULL && x-1 >= 0 && x-1 < size && y-1 >= 0 && y-1 < size) //SL added eb 8
   visible = (m->at(x - 1, y - 1) != stoneNone); //SL added eb 9 We do this in order not to pass a null matrix to the matrix->at function (seen in handicap games)

  // again we priviledge matrix over stone visibility (we might be browsing a game)
	if (tmp != NULL && tmp->getColor() == color && (tmp->isVisible()|| visible)) //SL added eb 8
	{
		if (!group->contains(tmp))
		{
			group->append(tmp);
			tmp->checked = true;
		}
	}
	return group;
}
开发者ID:alserkli,项目名称:q4Go,代码行数:26,代码来源:stonehandler.cpp

示例5: if

//判断在走的X,Y轴上,moveID和killID之间有多少个棋子
int GameScene::getStoneCountInSingleXY(int moveID, int killID, int tox, int toy){
	int count = 0;
	Stone* moveStone = sts[moveID];
	if (moveStone->getX() != tox && moveStone->getY() != toy){
		return -1;
	}
	int m_x = moveStone->getX();
	int m_y = moveStone->getY();
	if (m_x == tox){
		int y_min = m_y < toy ? m_y : toy;
		int y_max = m_y > toy ? m_y : toy;
		for (int i = y_min + 1; i < y_max; i++){
			if (getStoneIDByXY(m_x, i) != -1){
				count++;
			}
		}
	}
	else if (m_y == toy){
		int x_min = m_x < tox ? m_x : tox;
		int x_max = m_x > tox ? m_x : tox;
		for (int i = x_min + 1; i < x_max; i++){
			if (getStoneIDByXY(i, m_y) != -1){
				count++;
			}
		}
	}
	else{
		return -1;
	}
	return count;
}
开发者ID:rereadyou,项目名称:cocos2dx,代码行数:32,代码来源:GameScene.cpp

示例6: Stone

void GameClass::Stones_Init()
{
	for (int i = 0; i < MAX_STONE_NUM; ++i)
	{
		Stone* stone = new Stone();
		stone->width = 64;
		stone->height = 64;
		stone->foot = 32;
		stone->Set_img(L"GameMedia\\stone.png");
		stone->out_of_map = false;
		stones[i] = stone;
	}


	map<int, Sprite*>::iterator iter;
	iter = stones.begin();
	for (int i = 0; i < GAMEPANEL_HEIGHT; i++)
	{
		for (int j = 0; j < GAMEPANEL_WIDTH; j++)
		{
			if (WALL[i][j] == 2)
			{
				iter->second->world_Y = i;
				iter->second->world_X = j;

				if (iter == stones.end())
					return;

				++iter;
			}

		}
	}

}
开发者ID:xfningxia,项目名称:HouNou,代码行数:35,代码来源:GameClass.cpp

示例7: Stone

Stone* Stone::create(int id)
{
    Stone* s = new Stone();
    s->init(id);
    s->autorelease();
    return s;
};
开发者ID:laizhihuan,项目名称:cocos2dx-api-demo,代码行数:7,代码来源:Stone.cpp

示例8: CHECK_PTR

bool Group::isAttachedTo(Stone *s)
{
	CHECK_PTR(s);

	int stoneX = s->posX();
	int stoneY = s->posY();
	int x, y;
	StoneColor col = s->getColor(), c;
	Stone *tmp;

	if (isEmpty())
		return false;

	for (unsigned int i=0; i<size(); i++)
	{
		tmp = at(i);
		x = tmp->posX();
		y = tmp->posY();
		c = tmp->getColor();
		if (((stoneX == x && (stoneY == y-1 || stoneY == y+1)) ||
		     (stoneY == y && (stoneX == x-1 || stoneX == x+1))) &&
		    c == col)
			return true;
	}    

	return false;
}
开发者ID:alserkli,项目名称:q4Go,代码行数:27,代码来源:group.cpp

示例9: abs

bool GameScene::canMoveBING(int moveID, int killID, int tox, int toy){
	Stone* moveStone = sts[moveID];
	int m_x = moveStone->getX();
	int m_y = moveStone->getY();
	int xoff = abs(m_x - tox);
	int yoff = abs(m_y - toy);
	int checkXY = xoff * 10 + yoff;
	if (checkXY != 1 && checkXY != 10){
		return false;
	}
	if (clickRed == moveStone->getisRed()){//棋盘的下半部分
		if (toy < m_y){
			return false;
		}
		if (m_y <= 4 && m_x != tox){//过河了
			return false;
		}
	}
	else{//棋盘的上半部分
		if (toy > m_y){
			return false;
		}
		if (m_y >= 5 && m_x != tox){//过河了
			return false;
		}
	}
	return true;
}
开发者ID:rereadyou,项目名称:cocos2dx,代码行数:28,代码来源:GameScene.cpp

示例10: canMoveSHI

bool GameScene::canMoveSHI(int moveID, int tox, int toy){
	Stone* moveStone = sts[moveID];
	int m_x = moveStone->getX();
	int m_y = moveStone->getY();
	int xoff = abs(m_x - tox);
	int yoff = abs(m_y - toy);
	if (xoff != 1 || yoff != 1){
		return false;
	}

	/*判断将或帅是否走出9宫格*/
	if (tox > 5 || tox < 3){
		return false;
	}
	if (clickRed == sts[moveID]->getisRed()){
		if (toy > 2 || toy < 0){
			return false;
		}
	}
	else{
		if (toy > 9 || toy < 7){
			return false;
		}
	}
	return true;
}
开发者ID:rereadyou,项目名称:cocos2dx,代码行数:26,代码来源:GameScene.cpp

示例11: canMoveJU

bool GameScene::canMoveJIANG(int moveID, int killID, int tox, int toy){
	/*如果要杀的对面的将或帅,则直接按车的走法*/
	if (killID != -1 && sts[killID]->getType() == Stone::JIANG){
		return canMoveJU(moveID, killID, tox, toy);
	}
	/*判断是否走的一格*/
	Stone* moveStone = sts[moveID];
	int m_x = moveStone->getX();
	int m_y = moveStone->getY();
	int xoff = abs(m_x - tox);
	int yoff = abs(m_y - toy);
	int checkXY = xoff * 10 + yoff;
	if (checkXY != 1 && checkXY != 10){
		return false;
	}

	/*判断将或帅是否走出9宫格*/
	if (tox > 5 || tox < 3){
		return false;
	}
	if (clickRed == sts[moveID]->getisRed()){
		if (toy > 2 || toy < 0){
			return false;
		}
	}
	else{
		if (toy > 9 || toy < 7){
			return false;
		}
	}
	return true;
}
开发者ID:rereadyou,项目名称:cocos2dx,代码行数:32,代码来源:GameScene.cpp

示例12: startClient

void SceneGame::startClient(CCObject*obj)
{
	if (Net::Connect("127.0.0.1"))
	{
		// 把棋子倒过来
		for (int i = 0; i < 32; i++)
		{
			Stone* s = _s[i];
			s->_row = 9 - s->_row;
			s->_col = 8 - s->_col;
			s->setPosition(s->fromPlate());
		}

		// 开始接收
		Net::RecvStart();
		schedule(schedule_selector(SceneGame::CheckRecv));

		Net::_isConnected = true;
		_bRedSide = false;
		CCMenuItemFont *font = (CCMenuItemFont *)obj;
		CCMenuItemFont *server = (CCMenuItemFont *)font->getUserObject();
		server->setEnabled(false);
		font->setEnabled(false);
	}
	else
	{
		CCLog("Connect failure....");
	}
}
开发者ID:dalechngame,项目名称:mygame,代码行数:29,代码来源:SceneGame.cpp

示例13: qWarning

bool StoneHandler::removeStone(int x, int y, bool hide)
{
	if (!hasStone(x, y))
		return false;
	
	if (!hide)
	{
    // We delete the killed stones only if we want to update the board (i.e. : not if we are browsing the game)
    if (boardHandler->getDisplay_incoming_move())             //SL added eb 9
      if (!stones->remove(Matrix::coordsToKey(x, y)))
	    {
			   qWarning("   ***   Key for stone %d, %d not found!   ***", x, y);
			   return false;
		   }
	}
	else
	{
		Stone *s;
		if ((s = stones->find(Matrix::coordsToKey(x, y))) == NULL)
		{
			qWarning("   ***   Key for stone %d, %d not found!   ***", x, y);
			return false;
		}
		s->hide();
	}
	
	return true;
}
开发者ID:alserkli,项目名称:q4Go,代码行数:28,代码来源:stonehandler.cpp

示例14: unschedule

void SceneGame::CheckRecv(float)
{
	if (Net::isRecvComplete())
	{
		int len;
		char* data = Net::RecvData(len);
		unschedule(schedule_selector(SceneGame::CheckRecv));
		
		// 悔棋
		if (data[0] == 3)
		{
			doRegret2();
			// 继续接收
			Net::RecvStart();
			schedule(schedule_selector(SceneGame::CheckRecv));
		}
		// 选棋
		else if (data[0] == 1)
		{
			_selectid = data[1];
			_selectSprite->setPosition(_s[_selectid]->fromPlate());
			_selectSprite->setVisible(true);

			// 继续接收
			Net::RecvStart();
			schedule(schedule_selector(SceneGame::CheckRecv));
		}
		else if (data[0] == 2)
		{
			// 接受移动信息
			Stone* s = _s[data[1]];
			int row = 9 - data[2];
			int col = 8 - data[3];
			int killid = Common::getStoneFromRowCol(row, col, _s);

			// 记录走棋信息
			recordStep(_selectid, killid, _s[_selectid]->_row, _s[_selectid]->_col, row, col);

			// 移动棋子
			s->_row = row;
			s->_col = col;
			s->setPosition(s->fromPlate());

			// 杀死棋子
			if (killid != -1)
			{
				Stone* ks = _s[killid];
				ks->_dead = true;
				ks->setVisible(false);
			}

			// 更新数据
			_selectid = -1;
			_selectSprite->setVisible(false);
			_bRedTurn = !_bRedTurn;
		}
	}
}
开发者ID:dalechngame,项目名称:mygame,代码行数:58,代码来源:SceneGame.cpp

示例15: show

void Emerald::show()
{
	Stone *p = head;
	while (p)
	{
		p->print();
		p = p->next;
	}
}
开发者ID:samantond,项目名称:OOP,代码行数:9,代码来源:Emerald.cpp


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