2021 - Reflection
The Code
The code below is from the HexGrid class, and it is a section of the ExecuteCommandInTile method:
Piece thePiece = tiles[tileToUse].GetPieceInTile();
items[0] = items[0][0].ToString().ToUpper() + items[0].Substring(1);
if (thePiece.HasMethod(items[0]))
{
string methodToCall = items[0];
Type t = thePiece.GetType();
System.Reflection.MethodInfo method = t.GetMethod(methodToCall);
object[] parameters = { tiles[tileToUse].GetTerrain() };
if (items[0] == "Saw")
{
lumber += Convert.ToInt32(method.Invoke(thePiece, parameters));
}
else if (items[0] == "Dig")
{
fuel += Convert.ToInt32(method.Invoke(thePiece, parameters));
if (Math.Abs(fuel) > 2)
{
tiles[tileToUse].SetTerrain(" ");
}
}
}
Explanation
If you remember the LESSPiece class, and the PBDSPiece class contain methods for 'Saw' and 'Dig'.