public ITerritory Move(ITerritory source, ICreature.direction direction) { var tileSource = source as ITile; var target = (ITile)Activator.CreateInstance(source.GetType()); target.currentLevel = source.currentLevel; string movementDirection = ""; switch (direction) { case ICreature.direction.N: { target.SetX(tileSource.X, 0); target.SetY(tileSource.Y, 1); movementDirection = "northwards"; break; } case ICreature.direction.NE: { target.SetY(tileSource.Y, 1); target.SetX(tileSource.X, 1); movementDirection = "northeastwards"; break; } case ICreature.direction.E: { target.SetX(tileSource.X, 1); target.SetY(tileSource.Y, 0); movementDirection = "eastwards"; break; } case ICreature.direction.SE: { target.SetY(tileSource.Y, -1); target.SetX(tileSource.X, 1); movementDirection = "southeastwards"; break; } case ICreature.direction.S: { target.SetX(tileSource.X, 0); target.SetY(tileSource.Y, -1); movementDirection = "southwards"; break; } case ICreature.direction.SW: { target.SetY(tileSource.Y, -1); target.SetX(tileSource.X, -1); movementDirection = "southwestwards"; break; } case ICreature.direction.W: { target.SetX(tileSource.X, -1); target.SetY(tileSource.Y, 0); movementDirection = "westwards"; break; } case ICreature.direction.NW: { target.SetY(tileSource.Y, 1); target.SetX(tileSource.X, -1); movementDirection = "northwestwards"; break; } default: { break; } } if (target.isAccessible) { // Generate with ITileFactory source.creatures.Remove(this); target.creatures.Add(this); if (pack != null) { foreach (var creature in pack) { creature.Move(source, target, true); } } Console.WriteLine($"{name} is moving {movementDirection}."); return(target); } else { Console.WriteLine("You are going too far away from your territory!"); return(source); } }
// fix output type public ITerritory OnMovement(Character character, ITerritory department, ITerritory destination, ICreature.direction direction) { CoolDownSet(); var midway = character.Move(department, direction); if (midway != department) { var finalDestination = character.Move(midway, direction); if (finalDestination != midway) { Console.WriteLine("Longer feathers made your flight longer."); return(finalDestination); } return(midway); } return(department); }