private Vector2 GetFaceDirection(TileFace tileFace) { Vector2 direction; switch (tileFace) { case TileFace.Right: direction = this.rayCastRight.transform.position - this.rayCastStart.transform.position; break; case TileFace.Left: direction = this.rayCastLeft.transform.position - this.rayCastStart.transform.position; break; case TileFace.Bottom: direction = this.rayCastBottom.transform.position - this.rayCastStart.transform.position; break; default: direction = new Vector2(); break; } direction = direction.normalized; return(direction); }
//public HitDirection ReturnDirection(GameObject other, GameObject objectHit) //{ // HitDirection hitDirection = HitDirection.None; // RaycastHit MyRayHit; // Vector3 direction = (other.transform.position - objectHit.transform.position).normalized; // Ray MyRay = new Ray(objectHit.transform.position, direction); // if (Physics.Raycast(MyRay, out MyRayHit)) // { // if (MyRayHit.collider != null) // { // Vector3 MyNormal = MyRayHit.normal; // Debug.Log("WorldNormal: " + MyNormal); // MyNormal = MyRayHit.transform.TransformDirection(MyNormal); // Debug.Log("LocalNormal: " + MyNormal); // } // } // return hitDirection; //} public TileFace ReturnDirection(GameObject other, GameObject objectHit, Color rayColor) { TileFace hitDirection = TileFace.None; //Vector2 direction = (other.transform.position - objectHit.transform.position).normalized; Vector2 direction = (other.transform.position - objectHit.transform.position).normalized; Vector2 direction2 = (objectHit.transform.localPosition - objectHit.transform.InverseTransformPoint(other.transform.position)).normalized; Debug.Log("Direction world: " + direction); Debug.Log("Direction local: " + direction2); Debug.Log("Direction local: " + objectHit.transform.InverseTransformDirection(direction)); //Ray MyRay = new Ray(objectHit.transform.position, direction); //RaycastHit2D MyRayHit = Physics2D.Raycast(objectHit.transform.TransformPoint(other.transform.position), objectHit.transform.TransformDirection(direction)); //RaycastHit2D MyRayHit = Physics2D.Raycast(objectHit.transform.position, objectHit.transform.InverseTransformDirection(direction)); RaycastHit2D MyRayHit = Physics2D.Raycast(objectHit.transform.position, direction); if (MyRayHit.collider != null) { Vector2 MyNormal = MyRayHit.normal; Debug.Log("WorldNormal: " + MyNormal); //MyNormal = objectHit.transform.InverseTransformDirection(MyNormal); //MyNormal = objectHit.transform.TransformDirection(MyNormal); //MyNormal = MyRayHit.transform.InverseTransformDirection(MyNormal); //MyNormal = MyRayHit.transform.TransformDirection(MyNormal); //Debug.DrawRay(objectHit.transform.position, direction * 100, rayColor, 100); Debug.DrawRay(objectHit.transform.position, MyNormal * 100, rayColor, 1000); MyNormal = objectHit.transform.TransformDirection(MyNormal); Debug.Log("LocalNormal: " + MyNormal); } return(hitDirection); }
private string GetValueFromTileFace(TileFace face) { string[] parts = this.gameObject.name.Split('-'); if (parts.Length != 3) { throw new ArgumentException($"Tile name ('{name}') does not contain three numbers."); } string faceValue = string.Empty; switch (face) { case TileFace.Right: faceValue = parts[0] + "-" + parts[1]; break; case TileFace.Bottom: faceValue = parts[1] + "-" + parts[2]; break; case TileFace.Left: faceValue = parts[2] + "-" + parts[0]; break; default: break; } return(faceValue); }
/// <summary> /// Determines a TriominoTile-Faces value for one tile name. /// </summary> /// <param name="name">the tiles name.</param> /// <param name="face">the face whose value is requested.</param> /// <returns>the faces value.</returns> public static string[] GetValuesForFace(this string name, TileFace face) { name.EnsureTriominoTileName(); string[] parts = name.GetTriominoTileNumbersFromName(); switch (face) { case TileFace.Right: return(new List <string>() { parts[0], parts[1] }.ToArray()); case TileFace.Bottom: return(new List <string>() { parts[1], parts[2] }.ToArray()); case TileFace.Left: return(new List <string>() { parts[2], parts[0] }.ToArray()); default: throw new ArgumentException("Face couldn't be recognized."); } }
/// <summary> /// Creates a new Instance of this class. /// </summary> /// <param name="edge">the starting tile of this hexagon.</param> /// <param name="tileFace">the face of the starting tile for the next tile.</param> public Hexagon(HyperEdge edge, TileFace tileFace, HyperEdge outgoingConnector) { if (!edge.IsThreeSidedEdge()) { throw new ArgumentException($"Edge '{edge}' has to be threesided."); } if (!outgoingConnector.IsTwoSidedEdge()) { throw new ArgumentException($"Edge '{outgoingConnector}' has to be twosided."); } if (!outgoingConnector.ContainsVertexOnValueBasis(edge.GetVertexOnSpecificSide(tileFace))) { throw new ArgumentException($"Connector '{outgoingConnector}' has no vertex with edge '{edge}' in common."); } this.Triominos = new List <HyperEdge>(6); this.Triominos.AddRange(Enumerable.Repeat(default(HyperEdge), 6)); this.outgoingConnectors = new List <HyperEdge>(6); this.outgoingConnectors.AddRange(Enumerable.Repeat(default(HyperEdge), 6)); this.TriominoOutgoingFaces = new List <TileFace>(6); this.TriominoOutgoingFaces.AddRange(Enumerable.Repeat(default(TileFace), 6)); this.Pointer = this.DetermineHexagonPosition(edge.Orientation, tileFace); this.Triominos[this.Pointer] = edge; this.TriominoOutgoingFaces[this.Pointer] = tileFace; this.outgoingConnectors[this.Pointer] = outgoingConnector; this.IsComplete = false; }
private void SetGhostFaceAtFace(WorldObject target, TileFace resultFace) { var bb = target.ObjectType.TileData.GetBoundingBox(); var range = (bb.Max - bb.Min) * 0.5f; Vector3 right; Vector3 normal; Vector3 up; normal = TileSnapInformationBuilder.getFaceNormal(resultFace); up = TileSnapInformationBuilder.getFaceUp(resultFace); right = Vector3.Cross(up, normal); range *= 2f; Vector3 dim = new Vector3(); var ghostWidth = 0.01f; dim += normal * ghostWidth; dim += up * Vector3.Dot(up, range); dim += right * Vector3.Dot(right, range); dim.X = Math.Abs(dim.X); dim.Y = Math.Abs(dim.Y); dim.Z = Math.Abs(dim.Z); ghostFace.Dimensions = dim; ghostFace.PivotPoint = Vector3.One * 0.5f; ghostFace.WorldMatrix = Matrix.CreateTranslation(normal * (Math.Abs(Vector3.Dot(normal, range * 0.5f)) + 0.01f)) * target.WorldMatrix; }
public bool CanPlaceTileOnGameBoard(Action <bool, GameObject> modifyAdjacentTile = null) { Dictionary <TileFace, GameObject> adjacentTiles = this.GetAllAdjacentTiles(); if (UnityGameManager.instance.GameManager.TurnCount > 0 && !adjacentTiles.Any()) { return(false); } foreach (KeyValuePair <TileFace, GameObject> kv in adjacentTiles) { TileFace otherFace = kv.Value.GetComponent <TileManager>().GetAdjacentFaceToOtherTile(this.gameObject); if (!UnityGameManager.instance.GameManager.GameBoard.CanPlaceTileOnGameBoard(this.gameObject.name, kv.Value.gameObject.name, kv.Key, otherFace, out TriominoTile placableTile)) { modifyAdjacentTile?.Invoke(false, kv.Value); if (modifyAdjacentTile == null) { return(false); } } else { modifyAdjacentTile?.Invoke(true, kv.Value); } } // Examine if single tile corner is adjacent to another tiles corner (Bridge) and color this other tile accordingly. if (adjacentTiles.Count == 1 && !this.CheckIfNumberOppositeOfFaceMatches(adjacentTiles.First().Key, modifyAdjacentTile)) { return(false); } return(true); }
/// <summary> /// Returns a tile from the tileGrid starting from a given face of a specific tile (and it's position on the tileGrid). /// </summary> /// <param name="tile">Tile to start from.</param> /// <returns></returns> internal TriominoTile GetAdjacentTileAtSpecificFace(TriominoTile tile, TileFace tileFace) { ArrayTileOrientation orientation = tile.Orientation.ToArrayTileOrientation(); if (orientation == ArrayTileOrientation.BottomUp && tileFace == TileFace.Bottom) { return(this.tileGrid[tile.TileGridPosition.Y + 1, tile.TileGridPosition.X]); } if (orientation == ArrayTileOrientation.TopDown && tileFace == TileFace.Bottom) { return(this.tileGrid[tile.TileGridPosition.Y - 1, tile.TileGridPosition.X]); } if (orientation == ArrayTileOrientation.BottomUp && tileFace == TileFace.Right || orientation == ArrayTileOrientation.TopDown && tileFace == TileFace.Left) { return(this.tileGrid[tile.TileGridPosition.Y, tile.TileGridPosition.X + 1]); } if (orientation == ArrayTileOrientation.BottomUp && tileFace == TileFace.Left || orientation == ArrayTileOrientation.TopDown && tileFace == TileFace.Right) { return(this.tileGrid[tile.TileGridPosition.Y, tile.TileGridPosition.X - 1]); } return(null); }
private GameObject GetAdjacentTileInDirection(TileFace tileFace) { Vector2 direction = this.GetFaceDirection(tileFace); RaycastHit2D objectHit = Physics2D.Raycast(this.transform.position, direction, rayCastDistance, layerMask: raycastFilter); if (objectHit.collider != null) { Debug.Log("Side: " + tileFace + " Distance: " + objectHit.distance); return(objectHit.collider.gameObject); } // Make Raycast visible in Editor Color color = Color.black; switch (tileFace) { case TileFace.Right: color = Color.red; break; case TileFace.Left: color = Color.blue; break; case TileFace.Bottom: color = Color.green; break; } Debug.DrawRay(this.transform.position, direction * rayCastDistance, color); return(null); }
public TileFace ReturnDirection(GameObject other, Color rayColor) { TileFace hitDirection = TileFace.None; Vector2 direction = (other.transform.position - this.transform.position).normalized; direction = new Vector2(-direction.x, -direction.y); Debug.Log("Direction local: " + this.transform.InverseTransformDirection(direction)); Debug.DrawRay(this.transform.position, direction * 100, rayColor, 1000); return(hitDirection); }
public bool GetTotalWinding(TileFace face) { if (GetFaceType(face) == null) { return(false); } var ret = GetLocalWinding(face) ^ GetFaceType(face).GetTotalWinding(); return(ret); }
public TileFace GetAdjacentFaceToOtherTile(GameObject other) { Vector2 direction = this.GetDirection(other); Debug.Log("Direction (locale): " + direction); TileFace hitDirection = this.GetHitDirection(direction); Debug.Log("HitDirection: " + hitDirection); return(hitDirection); }
IEnumerator Thing(int i, int j) { while (!GameGlobals.tilesLoaded) { yield return(new WaitForSeconds(.1f)); } this.renderer.material.mainTexture = GameGlobals.TileImages[i]; tileType = (TileType)i; tileFace = (TileFace)j; }
/// <summary> /// Places a Tile on the GameBoard next to another tile, based on both tiles /// gameobjects and the faces with which they should be placed towards each other. /// </summary> /// <param name="thisTile">The GameObject of the tile to be placed.</param> /// <param name="thisFace">The face of the tile to be placed.</param> /// <param name="otherTile">The other tiles GameObject.</param> /// <param name="otherFace">The others tile face.</param> private void PlaceTileNextToOther(GameObject thisTile, TileFace thisFace, GameObject otherTile, TileFace otherFace = TileFace.None) { if (otherFace.Equals(TileFace.None)) { otherFace = otherTile.GetComponent <TileManager>().GetAdjacentFaceToOtherTile(thisTile); } Vector3 thisTilePosition = this.GetNewTilePositionFromPlacedTile(otherFace, otherTile); Quaternion thisTileRotation = this.GetNewTileOrientationByOtherFaceAndThisFace(otherTile, thisTile, otherFace, thisFace); thisTile.transform.SetPositionAndRotation(thisTilePosition, thisTileRotation); thisTile.transform.SetParent(this.PlacedTiles.transform); }
public SnapPoint GetPoint(TileData data, TileFace tileFace, TileFaceType faceType, bool winding) { var point = new SnapPoint(); point.Position = Math.Abs(Vector3.Dot((data.Dimensions * 0.5f), getFaceNormal(tileFace))) * getFaceNormal(tileFace); if (faceType != null) { point.SnapType = getSnapType(faceType); } point.Normal = getFaceNormal(tileFace); point.Up = getFaceUp(tileFace); point.ClockwiseWinding = winding; return(point); }
private bool CheckAllFacesForNewTileOnOtherTileFace(string tileName, string otherTileName, TileFace otherTileFace, out TileFace matchingFace) { TileFace[] facesToCheck = new TileFace[] { TileFace.Right, TileFace.Bottom, TileFace.Left }; matchingFace = TileFace.None; foreach (TileFace faceToCheck in facesToCheck) { if (this.GameManager.GameBoard.CanPlaceTileOnGameBoard(tileName, otherTileName, faceToCheck, otherTileFace, out TriominoTile placableTile)) { matchingFace = faceToCheck; return(true); } } return(false); }
public Vertex GetVertexOnSpecificSide(TileFace tileFace) { switch (tileFace) { case TileFace.Right: return(this.Vertices[0]); case TileFace.Bottom: return(this.Vertices[1]); case TileFace.Left: return(this.Vertices[2]); } throw new ArgumentException($"No vertex for Side '{tileFace}'."); }
/// <summary> /// Determiens the possible position of a tile within a Hexagon, based /// on its orientation and the face on which the next tile can be placed /// to get a hexagon. /// </summary> /// <param name="orientation">Orientation of the tile.</param> /// <param name="tileFace">the face of the tile, on which the next tile can be placed, to get a hexagon.</param> /// <returns>The position in a possible hexagon.</returns> private int DetermineHexagonPosition(TileOrientation orientation, TileFace tileFace) { if ((orientation == TileOrientation.Straight && tileFace == TileFace.Right) || (orientation == TileOrientation.DoubleTiltRight && tileFace == TileFace.Left) || (orientation == TileOrientation.DoubleTiltLeft && tileFace == TileFace.Bottom)) { return(0); } if ((orientation == TileOrientation.TiltLeft && tileFace == TileFace.Right) || (orientation == TileOrientation.TiltRight && tileFace == TileFace.Left) || (orientation == TileOrientation.Flipped && tileFace == TileFace.Bottom)) { return(1); } if ((orientation == TileOrientation.Straight && tileFace == TileFace.Left) || (orientation == TileOrientation.DoubleTiltRight && tileFace == TileFace.Bottom) || (orientation == TileOrientation.DoubleTiltLeft && tileFace == TileFace.Right)) { return(2); } if ((orientation == TileOrientation.TiltLeft && tileFace == TileFace.Left) || (orientation == TileOrientation.TiltRight && tileFace == TileFace.Bottom) || (orientation == TileOrientation.Flipped && tileFace == TileFace.Right)) { return(3); } if ((orientation == TileOrientation.Straight && tileFace == TileFace.Bottom) || (orientation == TileOrientation.DoubleTiltRight && tileFace == TileFace.Right) || (orientation == TileOrientation.DoubleTiltLeft && tileFace == TileFace.Left)) { return(4); } if ((orientation == TileOrientation.TiltLeft && tileFace == TileFace.Bottom) || (orientation == TileOrientation.TiltRight && tileFace == TileFace.Right) || (orientation == TileOrientation.Flipped && tileFace == TileFace.Left)) { return(5); } throw new ArgumentException($"No HexagonPosition for Edge with Orientation '{orientation}' and TileFace '{tileFace}'"); }
/// <summary> /// Determines the position for a new Tile according to another tiles positions. /// </summary> /// <param name="placedTileFace">The face (which is adjacent to the new tile) of the tile on the gameboard.</param> /// <param name="placedTile">The GameObject of the tile on the gameboard.</param> /// <returns>The new Position</returns> private Vector3 GetNewTilePositionFromPlacedTile(TileFace placedTileFace, GameObject placedTile) { int orientation = Convert.ToInt32(Math.Round(placedTile.transform.rotation.eulerAngles.z)); if (orientation > 180) { orientation -= 360; } Vector2 positionToAdd = this.NewTilePositionsByOtherOrientationAndTileFace[orientation][placedTileFace]; Vector3 newPosition = new Vector3(placedTile.transform.position.x, placedTile.transform.position.y, this.BoardPositionZ); newPosition += new Vector3(positionToAdd.x, positionToAdd.y, 0); return(newPosition); }
public Dictionary <TileFace, GameObject> GetAllAdjacentTiles() { TileFace[] facesToCheck = new TileFace[3] { TileFace.Left, TileFace.Right, TileFace.Bottom }; Dictionary <TileFace, GameObject> adjacentTiles = new Dictionary <TileFace, GameObject>(); foreach (TileFace face in facesToCheck) { GameObject adjacentTile = this.GetAdjacentTileInDirection(face); if (adjacentTile != null) { adjacentTiles.Add(face, adjacentTile); } } return(adjacentTiles); }
public bool CanPlaceNextToOtherTile(TileFace thisFace, GameObject other) { if (!this.CheckIfOtherTileOrientationMatches(other)) { return(false); } TileFace faceOther = other.GetComponent <TileManager>().GetAdjacentFaceToOtherTile(this.gameObject); string faceValueOther = other.gameObject.GetComponent <TileManager>().GetValueFromTileFace(faceOther); string faceValueThis = this.GetValueFromTileFace(thisFace); if (!UnityGameManager.instance.CheckFaceValues(faceValueOther, faceValueThis)) { return(false); } return(true); }
/// <summary> /// Places a tile on the GameBoard only if this tile can be placed. /// </summary> /// <param name="tile">The tile to be placed.</param> /// <returns>True if it was placed, false if not.</returns> public bool TryPlaceTile(GameObject tile) { this.isReady = false; // if it's the first turn, tile hast to be placed in center with orientation straight if (UnityGameManager.instance.GameManager.TurnCount == 0) { this.isReady = true; return(UnityGameManager.instance.GameManager.TryPlaceOnGameBoard(tile.gameObject.name)); } // if it's not the first turn, the tile hast to be placed adjacent to another tile, according to the others tile // orientation and the faces with which both tiles should be placed adjacent to each other. KeyValuePair <TileFace, GameObject> adjacentTile = tile.GetComponent <TileManager>().GetAllAdjacentTiles().First(); TileFace otherFace = adjacentTile.Value.GetComponent <TileManager>().GetAdjacentFaceToOtherTile(tile); this.isReady = true; return(UnityGameManager.instance.GameManager.TryPlaceOnGameBoard(tile.name, adjacentTile.Value.name, adjacentTile.Key, otherFace)); }
public bool CheckIfNumberOppositeOfFaceMatches(TileFace matchingFace, Action <bool, GameObject> modifyAdjacentTile = null) { GameObject opositeNumber = this.gameObject.transform.Find("Number3").gameObject; switch (matchingFace) { case TileFace.Left: opositeNumber = this.gameObject.transform.Find("Number2").gameObject; break; case TileFace.Bottom: opositeNumber = this.gameObject.transform.Find("Number1").gameObject; break; } Vector2 origin = new Vector2(opositeNumber.transform.position.x, opositeNumber.transform.position.y); Vector3 direction = (opositeNumber.transform.position - this.gameObject.GetComponent <TileManager>().rayCastStart.transform.position).normalized; Debug.DrawRay(new Vector3(origin.x, origin.y, 0), direction * circleCastDistance, Color.white); RaycastHit2D[] numbersInRange = Physics2D.CircleCastAll(origin, cirlceCastRadius, new Vector2(direction.x, direction.y), circleCastDistance); numbersInRange = numbersInRange.Where(n => n.collider != null && n.collider.gameObject.CompareTag(TagManager.TILENUMBER)).ToArray(); if (numbersInRange.Length > 0) { foreach (RaycastHit2D number in numbersInRange) { if (opositeNumber.gameObject.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text != number.collider.gameObject.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text) { modifyAdjacentTile?.Invoke(false, number.collider.transform.parent.gameObject); return(false); } else { modifyAdjacentTile?.Invoke(true, number.collider.transform.parent.gameObject); } } } return(true); }
private bool CheckMatchingAdjacentTiles(TriominoTile newTile) { bool newTileMatchesAdjacentTiles = true; TileFace[] facesToCheck = new TileFace[] { TileFace.Bottom, TileFace.Right, TileFace.Left }; foreach (TileFace faceToCheck in facesToCheck) { TriominoTile adjacenTileAtFace = this.GetAdjacentTileAtSpecificFace(newTile, faceToCheck); if (adjacenTileAtFace != null) { newTileMatchesAdjacentTiles = newTileMatchesAdjacentTiles && this.CheckMatchingAdjacentTileFaces(newTile, adjacenTileAtFace); } else { newTileMatchesAdjacentTiles = newTileMatchesAdjacentTiles && this.CheckBridgeEdgesAtTileFace(newTile, faceToCheck); } } return(newTileMatchesAdjacentTiles); }
private bool CheckAllFreeFacesOnGameBoard(string tile, out string matchingTile, out TileFace tileFace, out TileFace matchingTileFace) { matchingTile = null; tileFace = TileFace.None; matchingTileFace = TileFace.None; foreach (KeyValuePair <string, List <TileFace> > kv in this.GameManager.GameBoard.tilesWithFreeFaces) { foreach (TileFace freeFace in kv.Value) { if (this.CheckAllFacesForNewTileOnOtherTileFace(tile, kv.Key, freeFace, out tileFace)) { matchingTile = kv.Key; matchingTileFace = freeFace; return(true); } } } return(false); }
public bool GetLocalWinding(TileFace face) { return(FaceLocalWinding[(int)face - 1]); }
public void SetLocalWinding(TileFace face, bool value) { FaceLocalWinding[(int)face - 1] = value; }
/// <summary> /// Determines the orientation of a Tile, which should be placed on the GameBoard, based on another /// tiles orientation, and the faces with which both tiles should be aligned towards each other. /// </summary> /// <param name="otherOrientation">Other tiles orientation.</param> /// <param name="otherFace">Other tiles face.</param> /// <param name="tileFace">New tiles face.</param> /// <returns>the orientation of the new tile.</returns> private TileOrientation GetTileOrienationFromOtherTileOrientationAndFaces(TileOrientation otherOrientation, TileFace otherFace, TileFace tileFace) { if ((otherOrientation == TileOrientation.Straight && otherFace == TileFace.Left && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Right && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Left && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Right && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Left)) { return TileOrientation.Flipped; } else if ((otherOrientation == TileOrientation.Straight && otherFace == TileFace.Left && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Right && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Bottom && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Left && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Right && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Right)) { return TileOrientation.TiltRight; } else if ((otherOrientation == TileOrientation.Straight && otherFace == TileFace.Left && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Right && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Bottom && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Left && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Right && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom)) { return TileOrientation.TiltLeft; } else if ((otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Left && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Right && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Bottom && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Left && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Right && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Left)) { return TileOrientation.DoubleTiltRight; } else if ((otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Left && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Right && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Left && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Right && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Right)) { return TileOrientation.Straight; } else if((otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Left && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Right && tileFace == TileFace.Bottom) || (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Bottom && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Left && tileFace == TileFace.Left) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Right && tileFace == TileFace.Right) || (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom)) { return TileOrientation.DoubleTiltLeft; } throw new ArgumentException("The combination TileOrientation, TileFace, TileFace cannot be determined"); }
/// <summary> /// Determines a place in the tileGrid for a tile according to anothers (other) tile /// coordinates and its face on which the new tile should be placed. /// </summary> /// <param name="otherTileTileGridCoords">The others tile coordinates of the tileGrid.</param> /// <param name="otherFace">The others tile face, on which the new tile should be placed.</param> /// <returns>The coordniates of the tile Grid, next to the other tile.</returns> private Point GetTileGridPositionFromOtherTilePositionAndFace(Point otherTileTileGridCoords, TileFace otherFace) { Point thisTileGridPosition = new Point(-1, -1); Tuple<TileOrientation, TileFace> orientationFaceCombination = new Tuple<TileOrientation, TileFace>( this.tileGrid[otherTileTileGridCoords.Y, otherTileTileGridCoords.X].Orientation, otherFace); if ((orientationFaceCombination.Item1 == TileOrientation.Straight && orientationFaceCombination.Item2 == TileFace.Left) || (orientationFaceCombination.Item1 == TileOrientation.TiltLeft && orientationFaceCombination.Item2 == TileFace.Left) || (orientationFaceCombination.Item1 == TileOrientation.DoubleTiltLeft && orientationFaceCombination.Item2 == TileFace.Right) || (orientationFaceCombination.Item1 == TileOrientation.Flipped && orientationFaceCombination.Item2 == TileFace.Right) || (orientationFaceCombination.Item1 == TileOrientation.DoubleTiltRight && orientationFaceCombination.Item2 == TileFace.Bottom) || (orientationFaceCombination.Item1 == TileOrientation.TiltRight && orientationFaceCombination.Item2 == TileFace.Bottom)) { thisTileGridPosition.X = otherTileTileGridCoords.X - 1; thisTileGridPosition.Y = otherTileTileGridCoords.Y; } else if ((orientationFaceCombination.Item1 == TileOrientation.Straight && orientationFaceCombination.Item2 == TileFace.Right) || (orientationFaceCombination.Item1 == TileOrientation.TiltLeft && orientationFaceCombination.Item2 == TileFace.Bottom) || (orientationFaceCombination.Item1 == TileOrientation.DoubleTiltLeft && orientationFaceCombination.Item2 == TileFace.Bottom) || (orientationFaceCombination.Item1 == TileOrientation.Flipped && orientationFaceCombination.Item2 == TileFace.Left) || (orientationFaceCombination.Item1 == TileOrientation.DoubleTiltRight && orientationFaceCombination.Item2 == TileFace.Left) || (orientationFaceCombination.Item1 == TileOrientation.TiltRight && orientationFaceCombination.Item2 == TileFace.Right)) { thisTileGridPosition.X = otherTileTileGridCoords.X + 1; thisTileGridPosition.Y = otherTileTileGridCoords.Y; } else if ((orientationFaceCombination.Item1 == TileOrientation.Straight && orientationFaceCombination.Item2 == TileFace.Bottom) || (orientationFaceCombination.Item1 == TileOrientation.Flipped && orientationFaceCombination.Item2 == TileFace.Bottom) || (orientationFaceCombination.Item1 == TileOrientation.TiltRight && orientationFaceCombination.Item2 == TileFace.Left)) { thisTileGridPosition.X = otherTileTileGridCoords.X; thisTileGridPosition.Y = otherTileTileGridCoords.Y - 1; } else if ((orientationFaceCombination.Item1 == TileOrientation.TiltLeft && orientationFaceCombination.Item2 == TileFace.Right) || (orientationFaceCombination.Item1 == TileOrientation.DoubleTiltLeft && orientationFaceCombination.Item2 == TileFace.Left) || (orientationFaceCombination.Item1 == TileOrientation.DoubleTiltRight && orientationFaceCombination.Item2 == TileFace.Right)) { thisTileGridPosition.X = otherTileTileGridCoords.X; thisTileGridPosition.Y = otherTileTileGridCoords.Y + 1; } //if (thisTileGridPosition.X == -1 || thisTileGridPosition.Y == -1) //{ // throw new InvalidCastException($"Cannot determine on which side of 'otherTile' ({otherName}) the actual tile ({tile.Name}) should be placed"); //} return thisTileGridPosition; }
private bool TryGetPlacableTileFromDrawBoard(out string placableTile, out string otherTile, out TileFace placableTileFace, out TileFace otherTileFace) { placableTile = null; otherTile = null; placableTileFace = TileFace.None; otherTileFace = TileFace.None; // if its the first turn return tile from drawboard with highest value. placableTile = null; if (this.GameManager.TurnCount == 0) { placableTile = this.GameManager.GetActivePlayersDrawBoard().GetTriominoWithHighestValue(); return(true); } string[] drawBoardTiles = this.GameManager.GetActivePlayersDrawBoard().Tiles.ToArray(); foreach (string tile in drawBoardTiles) { if (this.CheckAllFreeFacesOnGameBoard(tile, out otherTile, out placableTileFace, out otherTileFace)) { placableTile = tile; return(true); } } return(false); }