Beispiel #1
0
 public override void DeleteNestedObjects()
 {
     WorldLogic.DeleteNestedObjects();
     WorldLogic = null;
     Grid.DeleteNestedObjects();
     Grid = null;
 }
        public WorldLogic(World world, WorldGrid grid, Vector2i startInIndices, Vector2i finishInIndices, PlayInterface playInterface)
        {
            this.world         = world;
            this.grid          = grid;
            this.playInterface = playInterface;
            cells = grid.Cells as Cell[, ];
            this.startInIndices  = startInIndices;
            this.finishInIndices = finishInIndices;
            graph = new Graph();
            for (var y = 0; y < grid.CellCount.Y; y++)
            {
                for (var x = 0; x < grid.CellCount.X; x++)
                {
                    var neighbors = GetNeighbors(new Vector2i(x, y));
                    if (neighbors != null)
                    {
                        switch (neighbors.Count)
                        {
                        case 1: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>()
                            {
                                { neighbors[0], neighbors[0].Weight }
                            }); break;

                        case 2: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>()
                            {
                                { neighbors[0], neighbors[0].Weight }, { neighbors[1], neighbors[1].Weight }
                            }); break;

                        case 3: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>()
                            {
                                { neighbors[0], neighbors[0].Weight }, { neighbors[1], neighbors[1].Weight }, { neighbors[2], neighbors[2].Weight }
                            }); break;

                        case 4: graph.AddVertex(cells[y, x], new Dictionary <Cell, int>()
                            {
                                { neighbors[0], neighbors[0].Weight }, { neighbors[1], neighbors[1].Weight }, { neighbors[2], neighbors[2].Weight }, { neighbors[3], neighbors[3].Weight }
                            }); break;
                        }
                    }
                }
            }
            path = new List <Cell>();

            SpawnStart(cells[startInIndices.Y, startInIndices.X]);
            SpawnMan(cells[startInIndices.Y, startInIndices.X]);
            SpawnFinish(cells[finishInIndices.Y, finishInIndices.X]);

            logicState = WorldLogicState.FindingPath;
        }
Beispiel #3
0
 public World(PlayInterface playInterface)
 {
     Grid       = new WorldGrid(ResourceLoader.GridSize, CellSize);
     WorldLogic = new WorldLogic(this, Grid, ResourceLoader.StartPositionIndices, ResourceLoader.FinishPositionIndices, playInterface);
 }