public void addHexNbr(int location) { int x = this.coords.x; int y = this.coords.y; if (location != 3 && location != 0) { if (location < 3) { x++; } else { x--; } } if (location != 1 && location != 4) { if (location < 4 && location > 1) { y--; } else { y++; } } HexNbrs[location] = new HexNode(); if (!HexNbrs[location].initCoords(x, y)) { HexNbrs[location] = NodeHolder.instance().HexList[new Point(x, y)]; } HexNbrs[location].HexNbrs[(location + 3) % 6] = this; }
void Start() { hx = new HexNode(); hx.initCoords(0, 0); hx.addHexNbrs(); HexNode[] hhh = new HexNode[hx.HexNbrs.Count]; hx.HexNbrs.Values.CopyTo(hhh, 0); foreach (HexNode h in hhh) { h.addHexNbrs(); } foreach (HexNode h in NodeHolder.instance().HexList.Values) { GameObject go = GameObject.Instantiate(hex); go.transform.position = h.coordTransform(); h.addSettNbrs(); /* Debug.Log ("Hex at " + h.coords.asString() + " with neighbours at " + * h.HexNbrs[0].coords.asString() + ", " + * h.HexNbrs[1].coords.asString() + ", " + * h.HexNbrs[2].coords.asString() + ", " + * h.HexNbrs[3].coords.asString() + ", " + * h.HexNbrs[4].coords.asString() + ", " + * h.HexNbrs[5].coords.asString() + ", ");*/ } foreach (SettNode s in NodeHolder.instance().SettList.Values) { GameObject whamo = GameObject.Instantiate(sett); whamo.transform.position = s.coordTransform(); } }
public bool initCoords(int x, int y) { if (!NodeHolder.instance().HexList.ContainsKey(new Point(x, y))) { coords.x = x; coords.y = y; NodeHolder.instance().HexList.Add((new Point(x, y)), this); Debug("Hex created at " + x + "," + y); updateNbrs(); return(true); } Debug("Already a Hex at " + x + "," + y); return(false); }
public void updateNbrs() { if (direction == 0) { if (NodeHolder.instance().SettList.ContainsKey(new Point(coords.x + 1, coords.y + 1))) { SettNbrs[0] = NodeHolder.instance().SettList[new Point(coords.x + 1, coords.y + 1)]; SettNbrs[0].SettNbrs[1] = this; Debug("Connecting " + this.coords.asString() + " to " + SettNbrs[0].coords.asString() + " (0)"); } if (NodeHolder.instance().SettList.ContainsKey(new Point(coords.x, coords.y - 2))) { SettNbrs[1] = NodeHolder.instance().SettList[new Point(coords.x, coords.y - 2)]; SettNbrs[1].SettNbrs[2] = this; Debug("Connecting " + this.coords.asString() + " to " + SettNbrs[1].coords.asString() + " (1)"); } if (NodeHolder.instance().SettList.ContainsKey(new Point(coords.x - 1, coords.y + 1))) { SettNbrs[2] = NodeHolder.instance().SettList[new Point(coords.x - 1, coords.y + 1)]; SettNbrs[2].SettNbrs[0] = this; Debug("Connecting " + this.coords.asString() + " to " + SettNbrs[2].coords.asString() + " (2)"); } } else { if (NodeHolder.instance().SettList.ContainsKey(new Point(coords.x + 1, coords.y - 1))) { SettNbrs[0] = NodeHolder.instance().SettList[new Point(coords.x + 1, coords.y - 1)]; SettNbrs[0].SettNbrs[2] = this; Debug("Connecting " + this.coords.asString() + " to " + SettNbrs[0].coords.asString() + " (0)"); } if (NodeHolder.instance().SettList.ContainsKey(new Point(coords.x - 1, coords.y - 1))) { SettNbrs[1] = NodeHolder.instance().SettList[new Point(coords.x - 1, coords.y - 1)]; SettNbrs[1].SettNbrs[0] = this; Debug("Connecting " + this.coords.asString() + " to " + SettNbrs[1].coords.asString() + " (1)"); } if (NodeHolder.instance().SettList.ContainsKey(new Point(coords.x, coords.y + 2))) { SettNbrs[2] = NodeHolder.instance().SettList[new Point(coords.x, coords.y + 2)]; SettNbrs[2].SettNbrs[1] = this; Debug("Connecting " + this.coords.asString() + " to " + SettNbrs[2].coords.asString() + " (2)"); } } }
public void addSettNbr(int location) { int x = coords.x * 2 + coords.y; int y = coords.y * 3; if (location > 0 && location < 4) { y--; } else { y++; } if (location == 2) { y--; } if (location == 5) { y++; } if (location < 2) { x++; } if (location > 2 && location < 5) { x--; } SettNbrs[location] = new SettNode(); int direction = location % 2; if (location == 0) { direction = 0; } SettNbrs[location].direction = direction; if (!SettNbrs[location].initCoords(x, y)) { SettNbrs[location] = NodeHolder.instance().SettList[new Point(x, y)]; } //SettNbrs[location].direction = direction; SettNbrs[location].updateNbrs(); }
public void updateNbrs() { for (int i = 0; i < 6; i++) { int x = this.coords.x; int y = this.coords.y; if (i != 3 && i != 0) { if (i < 3) { x++; } else { x--; } } if (i != 1 && i != 4) { if (i < 4 && i > 1) { y--; } else { y++; } } if (NodeHolder.instance().HexList.ContainsKey(new Point(x, y))) { HexNbrs[i] = NodeHolder.instance().HexList[new Point(x, y)]; HexNbrs[i].HexNbrs[(i + 3) % 6] = this; Debug("Connecting " + this.coords.asString() + " to " + HexNbrs[i].coords.asString() + " (" + i + ")"); } else { HexNbrs[i] = this; } } }