public void Dispatch(IUnit unit, ITerrain terrain) { Type unitType = unit.GetType(); Type terrainType = terrain.GetType(); // go through the list and find the action that corresponds to the // most-derived IUnit and ITerrain types that are in the ancestor // chain for unitType and terrainType. Action <IUnit, ITerrain> action = /* left as exercise for reader ;) */ action(unit, terrain); }
public static ImageSource GetTexture(ITerrain terrain) { //TODO: Fill factory Bitmap grassImage = Images.Grass; ImageSource image; if (terrain.GetType() == typeof(CDirt)) { image = Images.Dirt.ToImageSource(); return(image); } else { image = grassImage.ToImageSource(); } return(image); }