Beispiel #1
0
	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);
		}
	};
Beispiel #2
0
	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");
		}
	};
Beispiel #3
0
	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");
	};
Beispiel #4
0
	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;
	};