示例#1
0
 internal override void Link(DominoTileEntity tile, DominoTileEntity otherTile)
 {
     if (tile == null)
     {
         throw new ArgumentNullException(nameof(tile));
     }
     if (otherTile == null)
     {
         throw new ArgumentNullException(nameof(otherTile));
     }
     if (tile.IsLinked(otherTile))
     {
         throw new ApplicationException($"Can't link: '{tile}' with '{otherTile}' because tiles are already linked");
     }
     if (!tile.IsMatch(otherTile))
     {
         throw new ApplicationException($"Illegal move, no matching values. Can't link: tile: '{tile}' with tile: '{otherTile}'");
     }
     if (!tile.HasMatchingUnlinkedValue(otherTile) && !otherTile.IsLinked(tile))
     {
         throw new ApplicationException($"Illegal move, no matching unlinked values. Can't link: '{tile}' with '{otherTile}'");
     }
     tile.linkedTiles.Add(otherTile);
     tile.state = new HalfLinkedState();
     if (!AreLinkedValuesAligned(tile, otherTile))
     {
         tile.Flip();
     }
     if (!otherTile.IsLinked(tile))
     {
         otherTile.Link(tile);
     }
 }
示例#2
0
 internal virtual void Link(DominoTileEntity linkedTile, DominoTileEntity unlinkedTile)
 {
     throw new IllegalStateActionException(GetType());
 }
示例#3
0
 private bool AreLinkedValuesAligned(DominoTileEntity tile, DominoTileEntity otherTile) =>
 otherTile.state is EngineState
         ? otherTile.SecondValue == tile.FirstValue
         : tile.SecondValue == otherTile.FirstValue ||
 otherTile.SecondValue == tile.FirstValue;
示例#4
0
 public bool IsMatch(DominoTileEntity otherTile) =>
 GetValues()
 .Any(v =>
      otherTile
      .GetValues()
      .Any(ov => v == ov));
示例#5
0
 internal virtual void Link(DominoTileEntity tile) =>
 state.Link(this, tile);
示例#6
0
 internal bool MatchesUnlinkedValue(DominoTileEntity tile) =>
 GetUnlinkedValues()
 .Any(x =>
      tile.GetUnlinkedValues()
      .Any(y => x == y));
示例#7
0
 internal bool IsLinked(DominoTileEntity tile) =>
 linkedTiles.Contains(tile);
示例#8
0
 internal bool HasMatchingUnlinkedValue(DominoTileEntity otherTile) =>
 GetUnlinkedValues()
 .Any(v =>
      otherTile
      .GetUnlinkedValues()
      .Any(ov => v == ov));
示例#9
0
 internal override void Link(DominoTileEntity linkedTile, DominoTileEntity unlinkedTile)
 {
 }