Esempio n. 1
0
    public static void ChageType(Grid grid, GridType gridType)
    {
        switch (gridType)
        {
        case GridType.Wall:
            grid.currentType = GridType.Ground;
            squareGrid.RemoveWall(grid);
            grid.GetComponent <MeshRenderer>().material.color = Color.white;
            break;

        case GridType.Forest:
            grid.currentType = GridType.Wall;
            squareGrid.RemoveForest(grid);
            squareGrid.AddWall(grid);
            grid.GetComponent <MeshRenderer>().material.color = Color.yellow;
            break;

        case GridType.Ground:
            grid.currentType = GridType.Forest;
            squareGrid.AddForest(grid);
            grid.GetComponent <MeshRenderer>().material.color = Color.green;
            break;

        default:
            break;
        }
    }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();

            // TODO: Разобраться с файлом настроек и не городить такие безобразные строчки
            GlobalSettings.EightWay = Properties.Settings.Default.EightWay;

            // Data
            _searchingAlg = new DijkstraSearch();
            _nodeGrid     = SquareGrid.CreateWithForest();
            _start        = _nodeGrid[3, 3];
            _start.Type   = NodeType.Start;
            _goal         = _nodeGrid[8, 7];
            _goal.Type    = NodeType.Goal;
            _nodeGrid.AddWall(8, 1);
            _history = _history = _searchingAlg.SearchWithHistory(_nodeGrid, _start, _goal);

            // View
            GridView.Init(_history);
            GridView.ShowStep(-1);

            GridView.WallAdded    += GridView_WallAdded;
            GridView.WallRemoved  += GridView_WallRemoved;
            GridView.StartChanged += GridView_StartChanged;
            GridView.GoalChanged  += GridView_GoalChanged;
        }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        //SimplePriorityQueue<string> simPriQueue = new SimplePriorityQueue<string>();
        //simPriQueue.Enqueue("111", 1);
        //simPriQueue.Enqueue("111", 1);
        //simPriQueue.Enqueue("111", 1);
        //while (simPriQueue.Count>0)
        //{
        //    Debug.Log(simPriQueue.Dequeue());
        //}
        Grid[,] Grids = new Grid[weight, length];
        squareGrid    = new SquareGrid(weight, length);
        int count = 0;

        for (int i = 0; i < length; i++)
        {
            for (int j = 0; j < weight; j++)
            {
                count++;
                GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                go.name = count.ToString();
                go.transform.position    = new Vector3(i, 0, j);
                go.transform.localScale *= 0.7f;
                go.GetComponent <MeshRenderer>().material.color = Color.white;
                Grid grid = go.AddComponent <Grid>();
                grid.x = i; grid.y = j;
                squareGrid.AddEdge(grid);
                if (i == 0 && j == 0)
                {
                    start = grid;
                    grid.gameObject.GetComponent <MeshRenderer>().material.color = Color.black;
                }
                if (i == 15 && j == 15)
                {
                    end = grid;
                    grid.gameObject.GetComponent <MeshRenderer>().material.color = Color.black;
                }
                Grids[i, j]      = grid;
                grid.currentType = GridType.Ground;
            }
        }
        for (int i = 0; i < 100; i++)
        {
            int x = Random.Range(0, 19);
            int y = Random.Range(0, 19);
            if (x == 0 && y == 0)
            {
                continue;
            }
            if (x == 15 && y == 15)
            {
                continue;
            }
            Grid grid = Grids[x, y];
            grid.currentType = GridType.Wall;
            grid.gameObject.GetComponent <MeshRenderer>().material.color = Color.yellow;
            squareGrid.AddWall(grid);
        }
        for (int i = 0; i < 50; i++)
        {
            int x = Random.Range(0, 19);
            int y = Random.Range(0, 19);
            if (x == 0 && y == 0)
            {
                continue;
            }
            if (x == 15 && y == 15)
            {
                continue;
            }
            Grid grid = Grids[x, y];
            grid.currentType = GridType.Forest;
            if (squareGrid.Passable(grid))
            {
                grid.gameObject.GetComponent <MeshRenderer>().material.color = Color.green;
                squareGrid.AddForest(grid);
            }
        }
        astar = new Astar(squareGrid);
    }
Esempio n. 4
0
 private void GridView_WallAdded(object sender, WallAddedEventArgs e)
 {
     _nodeGrid.AddWall(e.X, e.Y);
     UpdateSearch();
     UpdateCurrentStepView();
 }