示例#1
0
    /// <summary>
    /// Given the location of a tile with a valid sequence number, check each direction for a valid sequence.
    ///
    /// If there's a valid sequence longer or equal to $minimumSequenceLength then return it.
    ///
    /// Otherwise, return an empty list.
    /// </summary>
    /// <returns>The scoring quads.</returns>
    /// <param name="tiles">Array of tiles with valid sequence numbers.</param>
    /// <param name="locationOfSequenceTile">Location of sequence tile.</param>
    private HashSet <TileController> GetScoringQuads(TileController[,] tiles, Vector2Int locationOfSequenceTile)
    {
        // create iterators for up, down, left, right
        TileControllerEnumerator tilesXDown = new TileControllerEnumerator(tiles, locationOfSequenceTile, -1, 0);
        TileControllerEnumerator tilesXUp   = new TileControllerEnumerator(tiles, locationOfSequenceTile, 1, 0);
        TileControllerEnumerator tilesYDown = new TileControllerEnumerator(tiles, locationOfSequenceTile, 0, -1);
        TileControllerEnumerator tilesYUp   = new TileControllerEnumerator(tiles, locationOfSequenceTile, 0, 1);

        TileControllerEnumerator[] tilesEnumerators =
        {
            tilesXDown,
            tilesXUp,
            tilesYDown,
            tilesYUp
        };

        // for each direction, check to see if there's a Fib seq.
        foreach (TileControllerEnumerator tilesEnumerator in tilesEnumerators)
        {
            HashSet <TileController> potentialScoringQuads = GetValidSequenceQuads(tilesEnumerator);

            //if (potentialScoringQuads.Count > 0 && fibNum >= 5)
            //    Debug.Log("potential " + potentialScoringQuads.Count + ", fibNum: " + fibNum + ", loc " + loc);

            if (potentialScoringQuads.Count >= minimumSequenceLength)
            {
                // add to scoring list
                return(potentialScoringQuads);
            }
        }
        return(new HashSet <TileController>());
    }
示例#2
0
文件: MapManager.cs 项目: eb0920/Gems
    void SetupTiles()
    {
        Transform tiles = GameObject.Find("Tiles").transform;         // container

        int     index;
        Vector3 pos = Vector3.zero;

        m_Tiles = new TileController[m_Height, m_Width];

        for (int y = 0; y < m_Height; y++)
        {
            pos.y = y + 0.5f;
            for (int x = 0; x < m_Width; x++)
            {
                index = y * m_Width + x;

                if (m_Cells[index].type != MapCell.Type.None)
                {
                    var prefab = m_TilePrefabs[(int)m_Cells[index].type - 1];

                    pos.x = x + 0.5f;
                    var tile = Instantiate(prefab, pos, Quaternion.identity);
                    tile.transform.SetParent(tiles, true);

                    m_Tiles[y, x] = tile.GetComponent <TileController>();
                }
                else
                {
                    m_Tiles[y, x] = null;
                }
            }
        }
    }
示例#3
0
    public void CreateField(Vector3 startPosition, int height, int width)
    {
        _width        = width;
        _tempVector.y = startPosition.y;

        tiles = new TileController[height, width];

        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                _tempVector.z = i + startPosition.z;
                _tempVector.x = j + startPosition.x;

                GameObject tile = Instantiate(tilePrefab, _tempVector, Quaternion.identity);
                tile.name = "Tile_" + j + "_" + i;
                TileController tileController = tile.GetComponent <TileController>();
                tileController.x = j;
                tileController.y = i;
                tile.transform.SetParent(gameObject.transform);

                tiles[i, j] = tile.GetComponent <TileController>();

                //  if (j < 1 || i < 1 || i > height - 2 || j > width - 2)
                //  {
                //      tileController.ChangeTileState(TileState.FILLED);
                //  }
                //  else
                //  {
                tileController.ChangeTileState(TileState.EMPTY);
                //  }
            }
        }
    }
    private void addStart(TileController[,] map)
    {
        int ix = 0;
        int iy = Random.Range(0, 15 + 1);

        for (int x = 0; x < 4; x++)
        {
            for (int y = 0; y < 4; y++)
            {
                TileController tile = map[ix + x, iy + y];
                tile.MakeProtected();
                tile.Explore();
            }
        }

        for (int x = 1; x < 3; x++)
        {
            for (int y = 1; y < 3; y++)
            {
                TileController tile = map[ix + x, iy + y];
                tile.MakeFloor();
            }
        }

        TileController entranceTile = map[ix + 3, iy + 2];

        entranceTile.MakeDoor();
        entranceTile.MakeReturnToRoom();
        TileController landingTile = map[ix + 4, iy + 2];

        landingTile.MakeFloor();
        PlayerController.Instance.PutMeDown(ix + 4, iy + 2, landingTile);
    }
示例#5
0
    //void Update() {	/* Debug */	if (true) { string thing = null; } }

    bool Initialize()
    {
        // Quits if board dimensions are zero, or if there are no tiles set to populate it with
        if (numOfRows < 1 || numOfColumns < 1 || Tiles.Count < 1)
        {
            return(false);
        }

        // Assigns parent to this object if not chosen
        if (tileHolder == null)
        {
            tileHolder = this.transform;
        }
        if (boardHolder == null)
        {
            boardHolder = this.transform;
        }

        adjustedBFootprint = (boardHolder.localScale.x + boardHolder.localScale.y) / 2f;

        // Generates probability range for each tile
        FixProbability();
        RegisterTileTypes();

        spawnedTiles = new TileController[numOfColumns, numOfRows];

        return(true);
    }
示例#6
0
    private void ClearAllPassiveMatchesHandler(List <TileController> listGO, TileController[,] tilesList)
    {
        // Debug.LogFormat("ClearAllPassiveMatchesHandler");
        List <TileController> passivelyClearTileList = new List <TileController>();

        foreach (var go in listGO)
        {
            for (int x = 0; x < tilesList.GetLength(0); x++)
            {
                for (int y = tilesList.GetLength(1) - 1; y >= 0; y--)
                {
                    if (tilesList[x, y] == go)
                    {
                        if (!passivelyClearTileList.Contains(tilesList[x, y]))
                        {
                            foreach (var tile in FindMatchesPassivelyHandler(tilesList[x, y], x, y, tilesList))
                            {
                                if (!passivelyClearTileList.Contains(tile))
                                {
                                    passivelyClearTileList.Add(tile);
                                }
                            }
                        }
                    }
                }
            }
        }
        // Debug.LogFormat("ClearAllPassiveMatchesHandler Count = {0}", passivelyClearTileList.Count);
        if (passivelyClearTileList.Count > 0)
        {
            StartCoroutine(AllTilesFadeOut(passivelyClearTileList));
        }
    }
示例#7
0
 public BoardGrid(string[] gridInfo, GameObject[] tilePrefabs, float tileSize, float tileWidth, float tileHeight)
 {
     _height           = gridInfo.Length;
     _width            = (gridInfo[0].Length + 1) / 2;
     _gridArray        = new TileController[_width, _height];
     _designerTileSize = tileSize;
     _tileWidth        = tileWidth;
     _tileHeight       = tileHeight;
     _isDesignerMode   = false;
     for (int y = 0; y < _gridArray.GetLength(0); y++)
     {
         string[] gridLine = gridInfo[y].Split(',');
         for (int x = 0; x < _gridArray.GetLength(1); x++)
         {
             foreach (GameObject g in tilePrefabs)
             {
                 TileController tc = g.GetComponent <TileController>();
                 if (gridLine[x] == tc.GetLetter())// do zmiany
                 {
                     GridPosition   tempGridPosition   = new GridPosition(x, y);
                     TileController tempTileController = Object.Instantiate(g, GetWorldPosition(tempGridPosition), Quaternion.identity).GetComponent <TileController>();
                     tempTileController.InitializeTile(tempGridPosition, this);
                     _gridArray[x, y] = tempTileController;
                 }
             }
             if (_gridArray[x, y] == null)
             {
                 Debug.Log("Error: Tile" + x.ToString() + ", " + y.ToString() + " not initialized");
             }
         }
     }
 }
示例#8
0
    Awake()
    {
        trueColumns = columns * tileDivisions;
        trueRows    = rows * tileDivisions;

        tileControllers = new TileController[trueColumns, trueRows];

        for (
            int columnIndex = 0;
            columnIndex < trueColumns;
            ++columnIndex)
        {
            for (
                int rowIndex = 0;
                rowIndex < trueRows;
                ++rowIndex)
            {
                TileController groundTileController = CreateTile(
                    columnIndex,
                    rowIndex);

                groundTileController.DestroyIfCollidingWithBuilding();

                tileControllers[columnIndex, rowIndex] = groundTileController;
            }
        }
    }
示例#9
0
    // ----------------- EVENTS -----------------
    void Awake()
    {
        EventBus.Subscribe <BoardExpansionRequestEvent>(_OnBoardExpansionRequest);

        Debug.Assert(instance == null);
        instance = this;

        map_width = (int)Mathf.Floor(map_height * map_width_ratio / 2) * 2;

        tile_map   = new TileController[map_width, map_height];
        free_tiles = new List <TileController>();

        // instantiate the gameobjects for the board
        for (int y = 0; y < map_height; ++y)
        {
            for (int x = 0; x < map_width; ++x)
            {
                GameObject go = Instantiate(TilePrefab, new Vector3(x, y, 0), Quaternion.identity);
                go.transform.parent = gameObject.transform;
                tile_map[x, y]      = go.GetComponent <TileController>();
            }
        }

        ClearBoard();
    }
 private void addCorridors(TileController[,] map, int n)
 {
     for (int i = 0; i < n; i++)
     {
         addCorridor(map, 15, 5);
     }
 }
示例#11
0
 public TileControllerEnumerator(TileController[,] tiles, Vector2Int origin, int xDiff, int yDiff)
 {
     this.tiles  = tiles;
     this.origin = origin;
     this.xDiff  = xDiff;
     this.yDiff  = yDiff;
 }
 private void addRooms(TileController[,] map, int n)
 {
     for (int i = 0; i < n; i++)
     {
         addRoom(map, 6, 2);
     }
 }
    private bool hasInVicinity(int x, int y, int mode, TileController[,] map)
    {
        bool found = false;
        // mode 0: protected, mode 1: air, mode 2: door
        int minx = Math.Max(x - 1, 0);
        int miny = Math.Max(y - 1, 0);
        int maxx = Math.Min(x + 1, 19);
        int maxy = Math.Min(y + 1, 19);

        for (int ix = minx; ix <= maxx; ix++)
        {
            for (int iy = miny; iy <= maxy; iy++)
            {
                if (ix != x || iy != y)
                {
                    switch (mode)
                    {
                    case 0:
                        found = found || map[ix, iy].IsProtected();
                        break;

                    case 1:
                        found = found || (!map[ix, iy].IsWall() && !map[ix, iy].IsDoor());
                        break;

                    case 2:
                        found = found || map[ix, iy].IsDoor();
                        break;
                    }
                }
            }
        }

        return(found);
    }
示例#14
0
    //public List<GameObject> FindMatchesPassively(GameObject go, int IndexX, int IndexY, TileController[,] tilesList)
    //{
    //    //Debug.LogFormat("Execute FindMatchPassiveLy");
    //    List<GameObject> checkingMatchListVertical = new List<GameObject>();
    //    List<GameObject> checkingMatchListHorizontal = new List<GameObject>();
    //    List<GameObject> totalList = new List<GameObject>();
    //    // Scanning up
    //    for (int i = 1; i <= IndexY; i++)
    //    {
    //        if (tilesList[IndexX, IndexY].name == tilesList[IndexX, IndexY - i].name)
    //        {
    //            //Debug.LogFormat("gameObject {0} tiles [{1}, {2}]", tiles[IndexX, IndexY - i].name, IndexX, IndexY - 1);
    //            checkingMatchListVertical.Add(tilesList[IndexX, IndexY - i].gameObject);
    //        }
    //        else
    //            break;
    //    }
    //    //scanning down
    //    for (int i = 1; i < tilesList.GetLength(1) - IndexY; i++)
    //    {
    //        if (tilesList[IndexX, IndexY].name == tilesList[IndexX, IndexY + i].name)
    //        {
    //            //Debug.LogFormat("gameObject {0} tiles [{1}, {2}]", tiles[IndexX, IndexY + i].name, IndexX, IndexY + 1);
    //            checkingMatchListVertical.Add(tilesList[IndexX, IndexY + i].gameObject);
    //        }
    //        else
    //            break;
    //    }
    //    if (checkingMatchListVertical.Count >= 2)
    //        totalList.AddRange(checkingMatchListVertical);
    //    // SCANNING LEFT
    //    for (int i = 1; i <= IndexX; i++)
    //    {
    //        if (tilesList[IndexX, IndexY].name == tilesList[IndexX - i, IndexY].name)
    //        {
    //            //Debug.LogFormat("gameObject {0} tiles [{1}, {2}]", tiles[IndexX - i, IndexY].name, IndexX - i, IndexY);
    //            checkingMatchListHorizontal.Add(tilesList[IndexX - i, IndexY].gameObject);
    //        }
    //        else
    //            break;
    //    }
    //    // SCANNING RIGHT
    //    for (int i = 1; i < tilesList.GetLength(0) - IndexX; i++)
    //    {
    //        if (tilesList[IndexX, IndexY].name == tilesList[IndexX + i, IndexY].name)
    //        {
    //            //Debug.LogFormat("gameObject {0} tiles [{1}, {2}]", BoardController.instance.tiles[IndexX + i, IndexY].name, IndexX + i, IndexY);
    //            checkingMatchListHorizontal.Add(tilesList[IndexX + i, IndexY].gameObject);
    //        }
    //        else
    //            break;
    //    }
    //    if (checkingMatchListHorizontal.Count >= 2)
    //        totalList.AddRange(checkingMatchListHorizontal);

    //    if (totalList.Count >= 2)
    //        totalList.Add(go);

    //    return totalList;
    //}


    public bool GetTheAdjacentTile(float radiant, int xIndex, int yIndex, TileController[,] tilesList)
    {
        bool findTheAdjacent;

        if (radiant > -45 && radiant < 45)
        {
            //Debug.LogFormat("Right");
            if (xIndex < tilesList.GetLength(0) - 1)
            {
                if (tilesList[xIndex + 1, yIndex] != null)
                {
                    secondTile = tilesList[xIndex + 1, yIndex];
                }
            }
        }
        else if (radiant > 45 && radiant < 135)
        {
            //Debug.LogFormat("Up");
            if (yIndex > 0)
            {
                if (tilesList[xIndex, yIndex - 1] != null)
                {
                    secondTile = tilesList[xIndex, yIndex - 1];
                }
            }
        }
        else if (radiant > 135 || radiant < -135)
        {
            //Debug.LogFormat("Left");
            if (xIndex > 0)
            {
                if (tilesList[xIndex - 1, yIndex] != null)
                {
                    secondTile = tilesList[xIndex - 1, yIndex];
                }
            }
        }
        else if (radiant > -135 && radiant < -45)
        {
            // Debug.LogFormat("Down");
            if (yIndex < tilesList.GetLength(1) - 1)
            {
                if (tilesList[xIndex, yIndex + 1] != null)
                {
                    secondTile = tilesList[xIndex, yIndex + 1];
                }
            }
        }
        if (secondTile != null)
        {
            findTheAdjacent = true;
        }
        else
        {
            findTheAdjacent = false;
        }

        return(findTheAdjacent);
    }
示例#15
0
    void InitBoard()
    {
        string levelData = PlayerPrefs.GetString("StoredLevelData");

        Debug.Log(levelData);
        string[] levelValues = levelData.Split(':');

        tileCountX = int.Parse(levelValues [0]);
        tileCountY = int.Parse(levelValues [1]);
        int lifeTime  = int.Parse(levelValues [2]);
        int deathTime = int.Parse(levelValues [3]);

        tiles = new TileController[tileCountX, tileCountY];

        RectTransform rectTrans        = GetComponent <RectTransform> ();
        Vector2       boardDimmensions = new Vector2(rectTrans.rect.width, rectTrans.rect.height);

        Vector2 newTileSizes = boardDimmensions;

        newTileSizes.x /= tileCountX;
        newTileSizes.y /= tileCountY;
        //tileSizes = newTileSizes;

        // Set the initial tiles that the player will click on to plant
        if (gridTile)
        {
            for (int x = 0; x < tileCountX; x++)
            {
                for (int y = 0; y < tileCountY; y++)
                {
                    GameObject    newTile = Instantiate(gridTile);
                    RectTransform newRect = newTile.GetComponent <RectTransform> ();

                    // put the tile in the array
                    tiles [x, y] = newTile.GetComponent <TileController> ();

                    // add the new tile to the board
                    newTile.transform.SetParent(transform);

                    // position the tile
                    newRect.transform.position = new Vector2(
                        newTileSizes.x * x,
                        newTileSizes.y * y
                        );

                    // resize the tile
                    newRect.sizeDelta = new Vector2(newTileSizes.x, newTileSizes.y);

                    // init the tileController script
                    TileController tc = newTile.GetComponent <TileController> ();
                    tc.Init(x, y, lifeTime, deathTime);
                }
            }
        }
        else
        {
            Debug.Log("Grid Tile undefined in GridController");
        }
    }
示例#16
0
 private void DestroyDisplayTiles()
 {
     foreach (TileController controller in displayTiles)
     {
         Destroy(controller.gameObject);
     }
     displayTiles = null;
 }
示例#17
0
 public void CheckAdjacent(Vector2 firstPosition, Vector2 lastPosition, TileController[,] tilesList)
 {
     //Debug.LogFormat("Execute CheckAdjacent");
     if (Vector2.Distance(firstPosition, lastPosition) >= 0.5f)
     {
         //Debug.LogFormat("first = {0}, last = {1}", firstPosition, lastPosition);
         FindAdjacentAndMatchIfPossible(firstPosition, lastPosition, tilesList);
     }
 }
 void Awake()
 {
     TileSwapHandler.AnyPhysicalSwapMade += OnAnyPhysicalSwapMade;
     TileSwapHandler.AnyBoardSwapMade    += OnAnyBoardSwapMade;
     minAmountForMatch = tileBoardVals.GetVariable("minAmountForMatch")
                         as IntegerVariable;
     tiles = boardGenerator.GenerateBoard(this);
     UpdateColumnsAndRows();
 }
    // Initalizes the Constants.NUM_ROWS x Constants.NUM_COLS tile map in the game.
    void InitalizeMap()
    {
        // Instantiate tile map
        m_TileMap = new TileController[Constants.NUM_ROWS, Constants.NUM_COLS];

        // Create starting enemies

        List <Faction> startingFactions = GameManager.instance.state.enemyFactions;

        // Instantiate factions
        for (int i = 0; i < Constants.NUM_STARTING_ENEMIES; i++)
        {
            Faction newFaction = Faction.GenerateFaction();
            startingFactions.Add(newFaction);
        }

        // Calculate bottom right starting corner
        Vector3 bottomRight = m_MapCenter;

        bottomRight.x -= m_TileSize * (Constants.NUM_ROWS - 1) / 2f;
        bottomRight.y -= m_TileSize * (Constants.NUM_COLS - 1) / 2f;

        // Instantiate tiles
        for (int x = 0; x < Constants.NUM_ROWS; x += 1)
        {
            for (int y = 0; y < Constants.NUM_COLS; y += 1)
            {
                Vector3 tilePosition = bottomRight;
                tilePosition.x += m_TileSize * x;
                tilePosition.y += m_TileSize * y;
                GameObject tile = Instantiate(m_TilePrefab, tilePosition, Quaternion.identity, transform);
                m_TileMap[x, y] = tile.GetComponent <TileController>();
                m_TileMap[x, y].SetAttributes(x, y, TileController.TileType.NONE);
            }
        }

        // Instantiate player faction
        (int, int)playerFactionPosition = (m_Random.Next(Constants.NUM_ROWS), m_Random.Next(Constants.NUM_COLS));
        SetTileFaction(playerFactionPosition, Faction.GetPlayer());

        // Instantiate enemy factions
        for (int i = 0; i < Constants.NUM_STARTING_ENEMIES; i++)
        {
            RandomSpawnFaction(startingFactions[i]);
        }

        // Make the first mines
        for (int i = 0; i < Constants.NUM_STARTING_MINES; i++)
        {
            RandomSpawnMine(true);
        }
    }
    private bool addItems(TileController[,] map)
    {
        for (int i = 0; i < 5; i++)
        {
            addItem(ItemController.Item.Lemonade, map);
        }
        for (int i = 0; i < 5; i++)
        {
            addItem(ItemController.Item.Treat, map);
        }

        return(true);
    }
示例#21
0
    void SetupTile(GameObject tile, IntVector2 posInArray, TileController[,] array)
    {
        TileController tileController = tile.GetComponent <TileController>();

        tileController.size.x = tile.GetComponent <RectTransform>().sizeDelta.x;
        tileController.size.y = tile.GetComponent <RectTransform>().sizeDelta.y;

        tileController.posInArray.x = posInArray.x;
        tileController.posInArray.y = posInArray.y;

        tileController.arrayPosToBoardPos = new Vector2(posInArray.x * tileController.size.x, -posInArray.y * tileController.size.x);
        array[posInArray.x, posInArray.y] = tileController;
    }
示例#22
0
    public void GenerateConnections(TileController[,] matrix)
    {
        int leftConecction, topConnection, rightConnection, bottomConnection = 0;

        for (int w = 0; w < width; w++)
        {
            for (int h = 0; h < height; h++)
            {
                leftConecction = w;
                leftConecction--;
                topConnection = h;
                topConnection++;
                rightConnection = w;
                rightConnection++;
                bottomConnection = h;
                bottomConnection--;

                if (leftConecction >= 0)
                {
                    Connection c = new Connection();
                    c.tileA = matrix[w, h];
                    c.tileB = matrix[leftConecction, h];
                    matrix[w, h].connections.Add(c);
                }

                if (rightConnection < width)
                {
                    Connection c = new Connection();
                    c.tileA = matrix[w, h];
                    c.tileB = matrix[rightConnection, h];
                    matrix[w, h].connections.Add(c);
                }

                if (bottomConnection >= 0)
                {
                    Connection c = new Connection();
                    c.tileA = matrix[w, h];
                    c.tileB = matrix[w, bottomConnection];
                    matrix[w, h].connections.Add(c);
                }

                if (topConnection < height)
                {
                    Connection c = new Connection();
                    c.tileA = matrix[w, h];
                    c.tileB = matrix[w, topConnection];
                    matrix[w, h].connections.Add(c);
                }
            }
        }
    }
示例#23
0
    public void CreateTiles()
    {
        tileMap = new TileController[maxWidth, maxHeight];

        for (int y = 0; y < maxHeight; y++)
        {
            for (int x = 0; x < maxWidth; x++)
            {
                TileController tile = tilePool.GetItem(tileRoot, GetPosition(x, y));
                tile.Init(x, y);
                tileMap[x, y] = tile;
            }
        }
    }
示例#24
0
    IEnumerator SpawnTiles()
    {
        tiles = new TileController[mazeWidth, mazeLength];

        for (int x = 0; x < mazeWidth; x++)
        {
            for (int y = 0; y < mazeLength; y++)
            {
                tiles[x, y] = Instantiate(tilePrefab, new Vector3(x * 16, 0, y * 16), Quaternion.identity, mazeRoot).GetComponent <TileController>();
            }
        }
        tilesSpawned = true;
        yield return(null);
    }
示例#25
0
    // public void move() {
    //     // NEXT: Vector2.Lerp + time.deltaTime
    //     this.transform.position = new Vector3(position.x, position.y, 0);
    // }

    public void changePosition()
    {
        /*
         *  make (static public) tilecontroller accessible to PlayerController.
         *  find "next" tile
         *  change move speed according to type of tile.
         *  if fn in tile --> move player
         *  pick up hat
         */

        TileController[,] tiles = GameController.tcArray;

        int toX = 0;
        int toY = 0;

        if (Input.GetKey("w"))  // || Input.GetKeyDown(KeyCode.Joystick1Button0)){ //|| Input.GetAxis("Vertical") == -1) {
        {
            toY = 1;
        }
        else if (Input.GetKey("a"))  //|| Input.GetAxis("Horizontal") == -1) {
        {
            toX = -1;
        }
        else if (Input.GetKey("s"))  //|| Input.GetAxis("Vertical") == 1) {
        {
            toY = -1;
        }
        else if (Input.GetKey("d"))  //|| Input.GetAxis("Horizontal") == 1) {
        {
            toX = 1;
        }

        if (Mathf.Abs(toX) > 0 || Mathf.Abs(toY) > 0)
        {
            Vector2Int toPosition = new Vector2Int((int)position.x + toX, (int)position.y + toY);

            if (toPosition.x >= 0 && toPosition.y >= 0 && toPosition.y < GameController.rows && toPosition.x < GameController.columns)
            {
                TileController tc = tiles[toPosition.x, toPosition.y];
                if (tc.tileType != Globals.ROCK && (!this.hasItem() || !tc.hasItem()))
                {
                    float speed     = findSpeedMultipler(tc);
                    bool  isDigging = findIfDigging(tc);
                    StartCoroutine(Move(tc, (int)toPosition.x, (int)toPosition.y, speed, isDigging));
                }
            }
        }
    }
示例#26
0
    public void BuildField(int h, int w)
    {
        _fieldHeight = h;
        FIELD_HEIGHT = h;
        _fieldWidth  = w;
        FIELD_WIDTH  = w;

        //build tiles
        _field = new TileController[_fieldHeight, _fieldWidth];
        for (int height = 0; height < _fieldHeight; height++)
        {
            for (int width = 0; width < _fieldWidth; width++)
            {
                //create tile and place tile
                TileController tile = Instantiate(_references.MASTER_TILE).GetComponent <TileController> ();
                tile.transform.position   = new Vector3(height * HEXSCALE + height * .01f, 0, width * HEXSCALE + width * .01f);
                tile.transform.localScale = new Vector3(HEXSCALE, 1, HEXSCALE);

                //register tile with the field
                _field [height, width] = tile;

                //register adjacent tiles

                if (height > 0)
                {
                    tile.u   = _field [height - 1, width];
                    tile.u.d = tile;
                    if (width > 0)
                    {
                        tile.ul    = _field [height - 1, width - 1];
                        tile.ul.dr = tile;
                    }
                    if (width < _fieldWidth - 1)
                    {
                        tile.ur    = _field [height - 1, width + 1];
                        tile.ur.dl = tile;
                    }
                }
                if (width > 0)
                {
                    tile.l   = _field [height, width - 1];
                    tile.l.r = tile;
                }
            }
        }

        _references.RegisterTiles(_field);
    }
 private int crawlAsLongAsPossible(int n, int x, int y, int xStep, int yStep, TileController[,] map)
 {
     if (n <= 0)
     {
         return(n);
     }
     if (x > 0 && x < 19 && y > 0 && y < 19)
     {
         if (!map[x, y].IsProtected())
         {
             map[x, y].MakeFloor();
             n = crawlAsLongAsPossible(n - 1, x + xStep, y + yStep, xStep, yStep, map);
         }
     }
     return(n);
 }
示例#28
0
    // ------------ PRIVATE METHODS -------------------

    private void GrowBoard()
    {
        // Calculate new height and width
        int new_map_height = map_height + 2;
        int new_map_width  = (int)Mathf.Floor(new_map_height * map_width_ratio / 2) * 2; // must always be a multiple of 2

        // create new tilemap
        TileController[, ] new_tile_map = new TileController[new_map_width, new_map_height];

        // Reassign old values
        for (int y = 0; y < map_height; ++y)
        {
            for (int x = 0; x < map_width; ++x)
            {
                new_tile_map[x, y] = tile_map[x, y];
            }
        }

        // instantiate new tiles
        for (int y = map_height; y < new_map_height; ++y)
        {
            for (int x = 0; x < new_map_width; ++x)
            {
                GameObject go = Instantiate(TilePrefab, new Vector3(x, y, 0), Quaternion.identity);
                go.transform.parent = gameObject.transform;
                new_tile_map[x, y]  = go.GetComponent <TileController>();
            }
        }

        for (int y = 0; y < map_height; ++y)
        {
            for (int x = map_width; x < new_map_width; ++x)
            {
                GameObject go = Instantiate(TilePrefab, new Vector3(x, y, 0), Quaternion.identity);
                go.transform.parent = gameObject.transform;
                new_tile_map[x, y]  = go.GetComponent <TileController>();
            }
        }

        // update values
        map_width  = new_map_width;
        map_height = new_map_height;
        tile_map   = new_tile_map;

        ClearBoard();
        EventBus.Publish <BoardGeneratedEvent>(new BoardGeneratedEvent());
    }
示例#29
0
    private void Awake()
    {
        tiles = new TileController[MapWidth, MapHeight];
        TileController[] ftiles = FindObjectsOfType <TileController>();

        foreach (TileController tile in ftiles)
        {
            //Resource newtile = new Resource(tile.gameObject, newlatlong, true, newobj.GetComponent<TileController>(), 100, 10);
            //newtile.tileController.Change(TileController.tiletype.Resource, 100);

            //tiles[(int)tile.transform.position.x, (int)tile.transform.position.y] = newtile;

            tiles[tile.myTile.xPos, tile.myTile.yPos] = tile;
        }

        Init();
    }
示例#30
0
    /// <summary>
    /// Find tiles that are in a valid sequence
    /// </summary>
    /// <returns>The scoring tiles.</returns>
    /// <param name="tileGameObjects">Tile game objects.</param>
    public HashSet <TileController> FindScoringTiles(TileController[,] tileGameObjects)
    {
        // create a clone so we don't affect the real tiles
        tileGameObjects = (TileController[, ])tileGameObjects.Clone();

        // we're going to check each tile and if they 'score', then store
        // them in this set and return them
        HashSet <TileController> scoringTiles = new HashSet <TileController>();

        // find fib numbers
        SortedList <long, HashSet <Vector2Int> > mapSequenceNumsToLocations = FindSequenceNumbersAndLocations(tileGameObjects);

        // step 2
        // check for fib sequences

        // only worth checking out if there are more than 4 distinct potential fibs
        // e.g. if the board is covered with 1s, then there's not going to be a sequence
        if (mapSequenceNumsToLocations.Keys.Count >= minimumSequenceLength - 1)
        {
            List <long> sequenceNumbers = new List <long>(mapSequenceNumsToLocations.Keys);
            // sort it, so we check the highest fibs first
            sequenceNumbers.Sort(new LongDescendingComparer());

            // for each found fib number,
            // check for sequences
            foreach (long sequenceNumber in sequenceNumbers)
            {
                // for each location of this fib number
                // check for fib sequences
                foreach (Vector2Int locationOfSequenceNumber in mapSequenceNumsToLocations[sequenceNumber])
                {
                    HashSet <TileController> scoringQuadsForLocation = GetScoringQuads(tileGameObjects, locationOfSequenceNumber);

                    // add the scoring quads of this location to the total list
                    scoringTiles.UnionWith(scoringQuadsForLocation);

                    // we're done with this quad now
                    // remove it
                    // (maybe this improves performance?)
                    tileGameObjects[locationOfSequenceNumber.x, locationOfSequenceNumber.y] = null;
                }
            }
        }

        return(scoringTiles);
    }
        protected void GenerateTiles(Size size, int amountOfMines)
        {
            tiles = new TileController[size.Width, size.Height];
            int amountOfTilesToDo = size.Width * size.Height;
            Random random = new Random();

            int maxPathLength = Math.Min(size.Width + size.Height, amountOfTilesToDo - amountOfMines);
            int minPathLength = Math.Max(maxPathLength / 2, 2);
            int pathLength = random.Next(minPathLength, maxPathLength + 1);

            List<Point> path = new List<Point>();
            path.Add(new Point(random.Next(size.Width), random.Next(size.Height)));
            bool corner = true;
            int stuckCounter = 500;
            while (path.Count < pathLength)
            {
                stuckCounter--;
                if (stuckCounter < 0)
                {
                    break;
                }
                Point p;
                if (corner)
                {
                    p = GetRandomNeighbour(path[path.Count - 1], random);

                }
                else
                {
                    Point diff = path[path.Count - 1] - new Size(path[path.Count - 2]);
                    p = diff + new Size(path[path.Count - 1]);
                }

                if (path.Contains(p) || !FieldSize.Contains(p))
                    continue;

                corner = !corner;
                path.Add(p);
            }

            Player = new PlayerController(path[0], this);
            tiles[path[path.Count - 1].X, path[path.Count - 1].Y] = new ExitController(path[path.Count - 1],this );

            for (int i = 0; i < path.Count -1; i++)
            {
                tiles[path[i].X, path[i].Y] = new TileController(path[i], this);
                amountOfTilesToDo--;
            }

            for (int x = 0; x < size.Width; x++)
            {
                for (int y = 0; y < size.Height; y++)
                {
                    if (tiles[x, y] != null)
                    {
                        continue;
                    }
                    bool isMine = random.Next(amountOfTilesToDo) < amountOfMines;
                    if (isMine)
                    {
                        tiles[x, y] = new MineController(new Point(x, y), this);
                    }
                    else
                    {
                        tiles[x, y] = new TileController(new Point(x, y), this);
                    }
                    amountOfTilesToDo--;
                    if (isMine)
                    {
                        amountOfMines--;
                    }
                }
            }
        }