Difference between revisions of "2021 - PBDSPiece"
(Created page with "=Actual Code= <syntaxhighlight lang=c#> class PBDSPiece : Piece { static Random rNoGen = new Random(); public PBDSPiece(bool player1) : ba...") |
(→Things to note) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 41: | Line 41: | ||
=Things to note= | =Things to note= | ||
− | Constructor runs the base constructor as well as setting peiceType & | + | Constructor runs the base constructor as well as setting peiceType, VPValue, & fuelCostOfMove. |
− | CheckMoveIsValid is overriden in this sub class. | + | CheckMoveIsValid is overriden in this sub class, because each piece has different rules for movement. |
Dig is a method to give this sub class of piece extra functionality. | Dig is a method to give this sub class of piece extra functionality. |
Latest revision as of 11:51, 3 September 2020
Actual Code
class PBDSPiece : Piece
{
static Random rNoGen = new Random();
public PBDSPiece(bool player1)
: base(player1)
{
pieceType = "P";
VPValue = 2;
fuelCostOfMove = 2;
}
public override int CheckMoveIsValid(int distanceBetweenTiles, string startTerrain, string endTerrain)
{
if (distanceBetweenTiles != 1 || startTerrain == "~")
{
return -1;
}
return fuelCostOfMove;
}
public int Dig(string terrain)
{
if (terrain != "~")
{
return 0;
}
if (rNoGen.NextDouble() < 0.9)
{
return 1;
}
else
{
return 5;
}
}
}
Things to note
Constructor runs the base constructor as well as setting peiceType, VPValue, & fuelCostOfMove.
CheckMoveIsValid is overriden in this sub class, because each piece has different rules for movement.
Dig is a method to give this sub class of piece extra functionality.