private void GenerateTile(Tile.Type type, Tile.Team color) { // Create and add tile GameObject tileGameObject = Instantiate(tilePrefab) as GameObject; GameObject baseObject = color == Tile.Team.White ? whiteBase : blackBase; tileGameObject.transform.SetParent(baseObject.transform); Tile t = tileGameObject.GetComponent <Tile>(); t.Setup(this, type, color); // Place the tile. // Bases are not on the normal map. They float. As such they only have q and y cords in their hex. List <Tile.Type> types = new List <Tile.Type>(TileCounts.Keys); int q = types.Count / 2 - types.IndexOf(t.type); int i = 0; Hex hex; GameArea area = color == Tile.Team.Black ? GameArea.BlackBase : GameArea.WhiteBase; do { hex = new Hex(-q, 0, q, i, area); if (pieces.ContainsKey(hex)) { i++; } else { pieces.Add(hex, t); t.Hex = hex; //Debug.Log("H - " + hex); return; } } while (true); }
private void ResetTurn() { // Show which tiles can be moved Tile.Team team = turn % 2 == 0 ? Tile.Team.Black : Tile.Team.White; GameArea homebase = team == Tile.Team.Black ? GameArea.BlackBase : GameArea.WhiteBase; // First determine if the queen has been placed bool queenMustHaveBeenPlaced = (turn / 2.0 >= 2.0); Hex queenLocation = FindQueen(team); if (queenMustHaveBeenPlaced && queenLocation.area != GameArea.Board) { pieces[queenLocation].State = Tile.TileState.CanBeSelected; // Only valid move is the queen return; } // First highlight the pieces in the base foreach (Hex h in pieces.Keys.Where(h => (h.area == homebase))) { Hex higherHex = h.Up(); if (!pieces.ContainsKey(higherHex)) { pieces[h].State = Tile.TileState.CanBeSelected; } } if (queenLocation.area == GameArea.Board) { // Highlight valid moves on the board foreach (KeyValuePair <Hex, Tile> kv in pieces.Where(kv => (kv.Value.team == team))) { // Cannot be under another tile Hex higherHex = kv.Key.Up(); if (pieces.ContainsKey(higherHex)) { continue; } // Cannot create islands List <Hex> boardHexes = BoardHexes(); boardHexes.Remove(kv.Key); HashSet <Hex> continuousHexes = BreadthFirstSearch(boardHexes); if (continuousHexes.Count != boardHexes.Count) { continue; } // Great, it can be selected pieces[kv.Key].State = Tile.TileState.CanBeSelected; } } }
private Hex FindQueen(Tile.Team team) { return(pieces.Where(kv => (kv.Value.type == Tile.Type.Queen && kv.Value.team == team)).First().Key); }