/// <summary> /// Compares the position of IRoadTile to know if they are stick to each other /// </summary> /// <param name="a">IRoadTile</param> /// <param name="b">IRoadTile</param> /// <returns>true is IRoadTiles are stick to each other, else false</returns> public static bool IsPositionCompatible(IRoadTile a, IRoadTile b) { int diffX = Math.Abs(a.Position.X - b.Position.X); int diffY = Math.Abs(a.Position.Y - b.Position.Y); if (diffX < -1 || diffX > 1 || diffY < -1 || diffY > 1) { return(false); } // L : J'ai changé les tests qui m'avaient l'air bizares. if (diffX == 0) { if (diffY == -1 || diffY == 1) { return(true); } } else if (diffY == 0) { if (diffX == -1 || diffX == 1) { return(true); } } return(false); }
public static bool HasExtremity(IRoadTile a, Extremity x) { switch (x) { case Extremity.Top: return (a.Type == RoadTile.RoadType.Vertical || a.Type == RoadTile.RoadType.TopLeft || a.Type == RoadTile.RoadType.TopRight || a.Type == RoadTile.RoadType.TopBottomLeft || a.Type == RoadTile.RoadType.TopBottomRight || a.Type == RoadTile.RoadType.TopLeftRight || a.Type == RoadTile.RoadType.TopBottomLeftRight); case Extremity.Bottom: return (a.Type == RoadTile.RoadType.Vertical || a.Type == RoadTile.RoadType.BottomLeft || a.Type == RoadTile.RoadType.BottomRight || a.Type == RoadTile.RoadType.TopBottomLeft || a.Type == RoadTile.RoadType.TopBottomRight || a.Type == RoadTile.RoadType.BottomLeftRight || a.Type == RoadTile.RoadType.TopBottomLeftRight); case Extremity.Left: return (a.Type == RoadTile.RoadType.Horizontal || a.Type == RoadTile.RoadType.TopLeft || a.Type == RoadTile.RoadType.BottomLeft || a.Type == RoadTile.RoadType.TopBottomLeft || a.Type == RoadTile.RoadType.TopLeftRight || a.Type == RoadTile.RoadType.BottomLeftRight || a.Type == RoadTile.RoadType.TopBottomLeftRight); case Extremity.Right: return (a.Type == RoadTile.RoadType.Horizontal || a.Type == RoadTile.RoadType.TopRight || a.Type == RoadTile.RoadType.BottomRight || a.Type == RoadTile.RoadType.TopBottomRight || a.Type == RoadTile.RoadType.TopLeftRight || a.Type == RoadTile.RoadType.BottomLeftRight || a.Type == RoadTile.RoadType.TopBottomLeftRight); } return(false); }
public bool Remove(IMapTile tile) { if (tile is IRoadTile) { IRoadTile road = ((IRoadTile)tile); int i = this.ContainsAndIndex(road); if (i == 0) { tiles.RemoveAt(0); return(true); } if (i == tiles.Count - 1) { tiles.RemoveAt(tiles.Count - 1); return(true); } } return(false); }
public static TruckAnimation FindNextTo( IMapTile ModelTile, Travel.Extremity to) { if (ModelTile is IRoadTile) { IRoadTile Road = (IRoadTile)ModelTile; switch (Road.Type) { case RoadTile.RoadType.BottomLeft: if (to == Travel.Extremity.Left) { return(TruckAnimation.Bottom2Left); } else { return(TruckAnimation.Left2Bottom); } case RoadTile.RoadType.BottomRight: if (to == Travel.Extremity.Right) { return(TruckAnimation.Bottom2Right); } else { return(TruckAnimation.Right2Bottom); } case RoadTile.RoadType.Horizontal: if (to == Travel.Extremity.Right) { return(TruckAnimation.Left2Right); } else { return(TruckAnimation.Right2Left); } case RoadTile.RoadType.TopLeft: if (to == Travel.Extremity.Top) { return(TruckAnimation.Left2Top); } else { return(TruckAnimation.Top2Left); } case RoadTile.RoadType.TopRight: if (to == Travel.Extremity.Top) { return(TruckAnimation.Right2Top); } else { return(TruckAnimation.Top2Right); } case RoadTile.RoadType.Vertical: if (to == Travel.Extremity.Top) { return(TruckAnimation.Bottom2Top); } else { return(TruckAnimation.Top2Bottom); } default: throw new ArgumentException("Can't match tile and direction"); } } else { throw new ArgumentException("Can't animate the truck somewhere else than on a road"); } }
/// <summary> /// Compares two IRoadTile to know if they are bound to each other /// </summary> /// <param name="a">IRoadTile</param> /// <param name="b">IRoadTile</param> /// <returns>true is IRoadTiles are bound to each other, else false</returns> public static bool IsTypeCompatible(IRoadTile a, IRoadTile b) { Extremity a_commun_border_with_b; int diffX = a.Position.X - b.Position.X; int diffY = a.Position.Y - b.Position.Y; if (diffX == 0) { if (diffY == 1) { a_commun_border_with_b = Extremity.Top; } else { a_commun_border_with_b = Extremity.Bottom; } } else { if (diffX == 1) { a_commun_border_with_b = Extremity.Left; } else { a_commun_border_with_b = Extremity.Right; } } switch (a_commun_border_with_b) { case Extremity.Top: if (HasExtremity(a, Extremity.Top) && HasExtremity(b, Extremity.Bottom)) { return(true); } break; case Extremity.Bottom: if (HasExtremity(a, Extremity.Bottom) && HasExtremity(b, Extremity.Top)) { return(true); } break; case Extremity.Left: //LEFT if (HasExtremity(a, Extremity.Left) && HasExtremity(b, Extremity.Right)) { return(true); } break; case Extremity.Right: //RIGHT if (HasExtremity(a, Extremity.Right) && HasExtremity(b, Extremity.Left)) { return(true); } break; } return(false); }