コード例 #1
0
 public bool DoRevert()
 {
     for (int i = 0; i < nodes.GetLength(0); i++)
     {
         for (int j = 0; j < nodes.GetLength(1); j++)
         {
             nodes[i, j].IsWalkable = true;
             nodes[i, j].Color      = Color.White;
             nodes[i, j].Weight     = 1;
         }
     }
     isSetUpComplete            = false;
     chosenPathFindingAlgorithm = PathFindingSelector.NOTHING;
     currentSetupState          = SetupStateSequence.SELECTPATHALGORITHM;
     return(true);
 }
コード例 #2
0
 public Grid(Texture2D texture, int _gridSize, GameState gameState, SpriteFont _text, int _simSpeed, Algorithms _selected)
 {
     tex               = texture;
     gridSize          = _gridSize;
     text              = _text;
     nodes             = new Node[_gridSize, _gridSize];
     this.gameState    = gameState;
     simSpeed         /= _simSpeed;
     selectedAlgorithm = _selected;
     currentSetupState = SetupStateSequence.SETUPSTART;
     ConstructGrid();
     aStar    = new AStar(this);
     bfs      = new BFS(this);
     dfs      = new DFS(this);
     dijkstra = new Dijkstra(this);
 }
コード例 #3
0
        private bool RunSetupStateSequence(Node node)
        {
            oldKeyInput = keyInput;
            keyInput    = Keyboard.GetState();
            switch (currentSetupState)
            {
            case SetupStateSequence.SELECTPATHALGORITHM:
                if (chosenPathFindingAlgorithm == 0)
                {
                    if (chosenPathFindingAlgorithm != 0)
                    {
                        currentSetupState = SetupStateSequence.SETUPSTART;
                    }
                }
                break;

            case SetupStateSequence.SETUPSTART:
                if (!SetUpNodes(Color.Green, node))
                {
                    currentSetupState = SetupStateSequence.SETUPTARGET;
                }
                break;

            case SetupStateSequence.SETUPTARGET:

                if (!SetUpNodes(Color.Red, node))
                {
                    currentSetupState = SetupStateSequence.SETUPOBSTACLES;
                }
                break;

            case SetupStateSequence.SETUPOBSTACLES:
                if (!SetUpNodes(Color.Black, node))
                {
                    currentSetupState = SetupStateSequence.COMPLETE;
                }
                break;

            case SetupStateSequence.COMPLETE:
                IsSearching = true;
                return(true);

            default:
                break;
            }
            return(false);
        }