本文整理汇总了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);
}
};
示例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");
}
};
示例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");
};
示例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;
};