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


C++ Card::getDirection方法代码示例

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


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

示例1: knockOffPiece

	void GameBoard::knockOffPiece(Player& p, const Card& c, const BoardPosition& bp){
		Card temp=c;
		temp.distance--;
		if(!isValidMove(p,temp,bp))
			throw myException("illegalKnockOff");
		else{
				int x=bp.x;
				int y=bp.y;
 				if(c.getDirection()==NORTH)
				{x-=c.getDistance();}
				else if(c.getDirection()==SOUTH)
				{x+=c.getDistance();}
				else if(c.getDirection()==WEST)
				{y-=c.getDistance();}
				else if(c.getDirection()==EAST)
				{y+=c.getDistance();}
				if((((Piece*)(myItem[x][y]))->getName()==p.getInitial('x'))){
					throw myException("illegalKnockOff");}
				if((((Tower*)(myItem[x][y]))->getBlocks()>=0)){
					throw myException("illegalKnockOff");}
				myItem[bp.x][bp.y]=new Tower(0);
				myItem[x][y]=new Piece(p.getInitial('x'));
				p.increasePoints(1);
		}
	};
开发者ID:piyushv94,项目名称:jpcap-scanner,代码行数:25,代码来源:GameBoard.cpp

示例2: demolishTower

	void GameBoard::demolishTower(Player& p, const Card& c, const Card& pay, const BoardPosition& bp,int phase){
		/*If a player moves a piece to the location of a current tower, 
		the tower is demolished by playing a card according to the height of the tower. 
		The player receives points corresponding to the number of blocks of the tower and the player receives the blocks of the tower. 
		However, if a player has currently seven or more blocks the player has to build a tower first before removing another tower. 
		A player can also not demolish a tower if the player does not have the required card to pay for it.*/
		/*pays with the action card pay for a tower to be demolished when moving a piece to the board position bp. 
		It will throw an exception illegalDemolish if the tower cannot be demolished (invalid). 
		It must update a Player because of the demolishing of the tower.*/
		Card temp=c;
		temp.distance--;
		if(!isValidMove(p,temp,bp))
			throw myException("illegalDemolish");
		if(p.increaseBlocks(0)>=7)
			throw myException("illegalDemolish");
		else if(pay.getDistance()!=phase)
			throw myException("illegalDemolish");
		else{
				int x=bp.x;
				int y=bp.y;
				if(c.getDirection()==NORTH)
				{x-=c.getDistance();}
				else if(c.getDirection()==SOUTH)
				{x+=c.getDistance();}
				else if(c.getDirection()==WEST)
				{y-=c.getDistance();}
				else if(c.getDirection()==EAST)
				{y+=c.getDistance();}
				if((((Tower*)(myItem[x][y]))->getBlocks()==phase)){
				p.increasePoints(phase);
				p.increaseBlocks(phase);
				Hand<Card> tempC=p.getHand();
				delete(myItem[bp.x][bp.y]);
				if(x!=bp.x&&y!=bp.y)
				delete(myItem[x][y]);
				myItem[x][y]=new Piece(p.removePiece());
				myItem[bp.x][bp.y]=new Tower(0);
				p.addPiece();
				//p.addPiece();
				}
				else
					throw myException("illegalDemolish");
		}
	};
开发者ID:piyushv94,项目名称:jpcap-scanner,代码行数:44,代码来源:GameBoard.cpp

示例3: move

	void GameBoard::move(Player& p, const Card& c, const BoardPosition& bp){
		if(isValidMove(p,c,bp))
		{
			int x=bp.x;
			int y=bp.y;
			if(c.getDirection()==NORTH)
			{x-=c.getDistance();}
			else if(c.getDirection()==SOUTH)
			{x+=c.getDistance();}
			else if(c.getDirection()==WEST)
			{y-=c.getDistance();}
			else if(c.getDirection()==EAST)
			{y+=c.getDistance();}
			if((((Tower*)(myItem[x][y]))->getBlocks()!=0)&&(x!=bp.x&&y!=bp.y))
						throw myException("illegalMove");
			if(bp.x!=x||bp.y!=y){
			myItem[x][y]=myItem[bp.x][bp.y];
			myItem[bp.x][bp.y]=new Tower(0);}
		}
		else
			throw myException("illegalMove");
	};
开发者ID:piyushv94,项目名称:jpcap-scanner,代码行数:22,代码来源:GameBoard.cpp

示例4: isValidMove

	bool GameBoard::isValidMove(const Player& p, const Card& c, const BoardPosition& bp) const{
		bool res=true;
		int x=bp.x;
		int y=bp.y;
		/*A player can move one of the player's pieces on the board through 
		playing the corresponding card. Pieces can never move through towers or opponent's pieces.*/
		Direction d=c.getDirection();
		int dis=c.getDistance();
		switch(d){
			case WEST:
				for(int i=1;i<=dis;i++)
				{
					if(y-i<=0){
						res=false;
						break;
					}
					if((((Tower*)(myItem[x][y-i]))->getBlocks()!=0)){
						if((((Piece*)(myItem[x][y-i]))->getName()!=p.getInitial(' '))){
							res=false;
							break;
						}
					}
				}
				break;
			case EAST:
				for(int i=1;i<=dis;i++)
				{
					if(bp.y+i>8){
						res=false;
						break;
					}
					if((((Tower*)(myItem[x][y+i]))->getBlocks()!=0)){
						if((((Piece*)(myItem[x][y+i]))->getName()!=p.getInitial(' '))){
						res=false;
						break;
					}
					}
					
				}
				break;
				case NORTH:
				for(int i=1;i<=dis;i++)
				{
					if(x-i<=0){
						res=false;
						break;
					}
					if((((Tower*)(myItem[x-i][y]))->getBlocks()!=0)){
						if((((Piece*)(myItem[x-i][y]))->getName()!=p.getInitial(' '))){
						res=false;
						break;
					}
					}
					
				}
				break;
				case SOUTH:
				for(int i=1;i<=dis;i++)
				{
					if(x+i>8){
						res=false;
						break;
					}
					if((((Tower*)(myItem[x+i][y]))->getBlocks()!=0)){
						if((((Piece*)(myItem[x+i][y]))->getName()!=p.getInitial(' '))){
						res=false;
						break;
					}
					}
					
				}
				break;
		}
		return res;
	};
开发者ID:piyushv94,项目名称:jpcap-scanner,代码行数:75,代码来源:GameBoard.cpp


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