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