private void bfs(Queue <Utility.Coord> cellQueue, int i, int distance, int movementCells, bool[,] visitedMap)
    {
        while (cellQueue.Count > 0 && distance <= movementCells * 2)
        {
            Utility.Coord currentCell = cellQueue.Dequeue();


            Debug.Log(currentCell.x + " " + currentCell.y);
            if (currentCell.x >= 0 && currentCell.x < mapSize.x && currentCell.y >= 0 && currentCell.y < mapSize.y)
            {
                tileclass = map[currentCell.x, currentCell.y].GetComponent <TileClass>();
                if (tileclass.getType() != 2 && distance <= movementCells)
                {
                    //paint blue
                    Debug.Log("Cell " + currentCell.x + " " + currentCell.y + " is painted BLUE");
                    //cellQueue.Enqueue(currentCell);

                    if (tileclass.getType() == 1)
                    {
                        distance += 2;
                    }
                    else
                    {
                        distance++;
                    }

                    for (int j = 0; j < 8; j++)
                    {
                        cellQueue.Enqueue(currentCell.Add(neighbours[i]));
                        bfs(cellQueue, j, distance, movementCells, visitedMap);
                    }
                }
                else if (tileclass.getType() != 2 && distance <= movementCells * 2)
                {
                    //paint yellow
                    Debug.Log("Cell " + currentCell.x + " " + currentCell.y + " is painted YELLOW");
                    //cellQueue.Enqueue(currentCell);

                    if (tileclass.getType() == 1)
                    {
                        distance += 2;
                    }
                    else
                    {
                        distance++;
                    }

                    for (int j = 0; j < 8; j++)
                    {
                        cellQueue.Enqueue(currentCell.Add(neighbours[i]));
                        bfs(cellQueue, j, distance, movementCells, visitedMap);
                    }
                }
            }
        }
    }
示例#2
0
    private void InstantiateEnemies()
    {
        bool found = false;

        while (!found)
        {
            enemyCoords = GetRandomCoord();
            tileclass   = map[enemyCoords.x, enemyCoords.y].GetComponent <TileClass>();
            if (tileclass.getType() != 2 && !enemyCoords.Equals(playerCoords))
            {
                Enemy1.localScale = new Vector3(1.8f, 1.8f, 1.8f);
                Transform enemy1 = (Transform)Instantiate(Enemy1, CoordToPosition(enemyCoords.x, enemyCoords.y), Quaternion.Euler(Vector3.right * 90)) as Transform;
                found = true;
                combatControllerScript.addEnemy(enemyCoords, enemy1.name, enemy1);
                //Debug.Log("Enemy position is "+enemyCoords.x+" "+enemyCoords.y);
            }
        }
    }
示例#3
0
    private void InstantiatePlayers()
    {
        bool found = false;

        while (!found)
        {
            playerCoords = GetRandomCoord();
            tileclass    = map[playerCoords.x, playerCoords.y].GetComponent <TileClass>();
            if (tileclass.getType() != 2)
            {
                Player1.localScale = new Vector3(1.8f, 1.8f, 1.8f);
                //Player1.name = "Cyka";
                //Player1.tag = "Player";
                Transform player1 = (Transform)Instantiate(Player1, CoordToPosition(playerCoords.x, playerCoords.y), Quaternion.Euler(Vector3.right * 90)) as Transform;
                found = true;
                combatControllerScript.addPlayer(playerCoords, player1.name, player1);
                //Debug.Log("Player position is "+playerCoords.x+" "+playerCoords.y);
            }
        }
    }