public List <HexLogic> GetNeighbors(int x, int y) { Point[] localCoords = new Point[] { new Point(0, 2), new Point(0, -2), new Point(0, 1), new Point(0, -1), new Point(1, 1), new Point(1, -1) }; List <HexLogic> ret = new List <HexLogic>(); foreach (Point p in localCoords) { HexLogic hex = At(x + p.x, y + p.y); if (hex) { ret.Add(hex); } } return(ret); //hexouter[0] = grid.hexagons[x, y + 2]; //hex_up //hexouter[3] = grid.hexagons[x, y - 2]; //hex_down //hexouter[5] = grid.hexagons[x, y + 1]; //hex_left_up //hexouter[4] = grid.hexagons[x, y - 1]; //hex_left_down //hexouter[1] = grid.hexagons[x + 1, y + 1]; //hex_right_up //hexouter[2] = grid.hexagons[x + 1, y - 1]; //hex_right_down }
public void CheckSides() { for (int i = 0; i < sides.Length; i++) { if (sides[i]) { Sides side = (Sides)i; Point dir = side.Direction(y); HexLogic hex = grid.At(x + dir.x, y + dir.y); Sides invertedSide = side.Inverted(); int invertedSideIndex = (int)invertedSide; if (hex && !hex.Active && hex.sides[invertedSideIndex]) { hex.Active = true; } } } }
private void populateFromJson() { string fullJsonPath = Path.Combine(Application.streamingAssetsPath, jsonFile); if (!System.IO.File.Exists(fullJsonPath)) { throw new FileNotFoundException("jsonFile is not found inside StreamingAssets"); } string jsonString = File.ReadAllText(fullJsonPath, Encoding.Default); jsonObject = new JSONObject(JSONObject.Type.ARRAY); jsonObject = new JSONObject(jsonString); foreach (JSONObject j in jsonObject.list) { List <JSONObject> sides = j.GetField("sides").list; long x = j.GetField("x").i; long y = j.GetField("y").i; HexLogic hex = hexagons[x, y]; for (int i = 0; i < sides.Count; i++) { bool side = Convert.ToBoolean(sides[i].i); hex.sides[i] = side; } hex.DrawSides(); //hex.CheckSides(); //if (hex.x == 2) //{ // if (hex.y == 0 || hex.y == 2 || hex.y == 4) // { // //Destroy(hex); // } //} } }
public void Refresh() { //Clear everything EndLine.color = Color.white; Completed = false; for (int x = 0; x < hexagons.GetLength(0); x++) { for (int y = 0; y < hexagons.GetLength(1); y++) { HexLogic hex = At(x, y); if (hex) { hex.Active = false; } } } //Check the begin hex HexLogic beginHex = At(Begin.x, Begin.y); int beginSideIndex = (int)BeginSide; if (beginHex.sides[beginSideIndex]) { beginHex.Active = true; } HexLogic endHex = At(End.x, End.y); int EndSideIndex = (int)EndSide; if (endHex.sides[EndSideIndex] && endHex.Active) { Debug.Log("HOERA"); EndLine.color = Color.red; Completed = true; } }