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); } }
internal virtual void Link(DominoTileEntity linkedTile, DominoTileEntity unlinkedTile) { throw new IllegalStateActionException(GetType()); }
private bool AreLinkedValuesAligned(DominoTileEntity tile, DominoTileEntity otherTile) => otherTile.state is EngineState ? otherTile.SecondValue == tile.FirstValue : tile.SecondValue == otherTile.FirstValue || otherTile.SecondValue == tile.FirstValue;
public bool IsMatch(DominoTileEntity otherTile) => GetValues() .Any(v => otherTile .GetValues() .Any(ov => v == ov));
internal virtual void Link(DominoTileEntity tile) => state.Link(this, tile);
internal bool MatchesUnlinkedValue(DominoTileEntity tile) => GetUnlinkedValues() .Any(x => tile.GetUnlinkedValues() .Any(y => x == y));
internal bool IsLinked(DominoTileEntity tile) => linkedTiles.Contains(tile);
internal bool HasMatchingUnlinkedValue(DominoTileEntity otherTile) => GetUnlinkedValues() .Any(v => otherTile .GetUnlinkedValues() .Any(ov => v == ov));
internal override void Link(DominoTileEntity linkedTile, DominoTileEntity unlinkedTile) { }