예제 #1
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();

             // Implement the Gruenes Schaf
             new Thread(() => {
            while (true) {
               GC.Collect();
               Thread.Sleep(5000);
            }
             }).Start();

             var gridWidth = 2;
             var gridHeight = 2;

             var grid = new GridFactory().Create(gridWidth, gridHeight);
             var manipulator = new GridManipulator(grid, new Random(0));
             var spiral = new SpiralParametricFunction(1, 10, 3, (float)gridWidth / 2, (float)gridHeight / 2, 0);
             manipulator.CutParametric(spiral.TInitial, spiral.TFinal, 20f, spiral.PointAt);
             var lastSpiralPoint = spiral.PointAt(spiral.TFinal - 30);
             var v = new Vector2D(lastSpiralPoint, new Point2D(gridWidth / 2.0f, gridHeight / 2.0f));
             v = v.ToUnitVector();
             var cutDestination = lastSpiralPoint + v * 3;
             manipulator.CutLine(new Line2D(lastSpiralPoint, cutDestination));
             var entranceCell = grid.Cells[(gridHeight / 2) * grid.Width + (gridWidth / 2)];
             var cells = manipulator.FillRegion(entranceCell);

             var graphicsConfiguration = new GraphicsConfiguration { Width = 1600, Height = 900 };
             var gridletFactory = new GridletFactory();
            //         IReadOnlyList<NavigationGridlet> gridlets = CreateGridletsFromDungeonGrid(grid, gridletFactory);
             IReadOnlyList<NavigationGridlet> gridlets = new List<NavigationGridlet> {
            gridletFactory.Quad(0, 0, 0, 0, 0, 0, 60, 60),
            //            gridletFactory.Quad(37, 0, 2, -0.3f, 0, 0, 15, 7),
            //            gridletFactory.Quad(47.60f, -9.0f, 4.22f, 0, 0, 0, 7, 25),
            //            gridletFactory.Quad(58.05f, -18.0f, 4.22f, 0, 0, 0, 15, 7)
             };
             var navigationGrid = new NavigationGrid(gridlets);
             navigationGrid.Initialize();
             var pathfinder = new Pathfinder(navigationGrid);
             var renderer = new Renderer();

             CommandFactory commandFactory = new CommandFactory(pathfinder);
             var entityFactory = new EntityFactory();
             var entitySystem = new EntitySystem();
             entitySystem.AddEntity(entityFactory.CreateUnitCubeEntity());
             navigationGrid.Gridlets.ForEach(gridlet => entitySystem.AddEntity(entityFactory.CreateAndAssociateGridletEntity(navigationGrid, gridlet, pathfinder, commandFactory)));
             var characterEntity = entityFactory.CreateCharacterEntity(pathfinder);
             entitySystem.AddEntity(characterEntity);
             entitySystem.AddEntity(entityFactory.CreateCameraEntity(graphicsConfiguration, characterEntity));
             entitySystem.AddBehavior(new PhysicsBehavior(navigationGrid));
             entitySystem.AddBehavior(new CommandQueueBehavior());

             // Dungeon Stuff
             DungeonKeyInventory dungeonKeyInventory = new DungeonKeyInventory();
            //         entitySystem.AddEntity(entityFactory.CreateDungeonKeyEntity(new Vector3(5, 10, 0), new Vector4(1, 0, 0, 1), commandFactory, dungeonKeyInventory));
            //         entitySystem.AddEntity(entityFactory.CreateDungeonLockEntity(new Vector3(0, 35, 0), new Vector4(1, 0, 0, 1), commandFactory, dungeonKeyInventory));
            //         entitySystem.AddBehavior(new DungeonLockDisablesGroundPathingBehavior(navigationGrid));
             foreach (var cell in cells) {
            if (cell.KeyColor != Color.Empty) {
               var color = new Vector4(cell.KeyColor.R / 255f, cell.KeyColor.G / 255f, cell.KeyColor.B / 255f, 1);
               entitySystem.AddEntity(entityFactory.CreateDungeonKeyEntity(new Vector3(cell.X * 70 + 5, cell.Y * 70 + 10, 0), color, commandFactory, dungeonKeyInventory));
            }
            if (cell.LockColor != Color.Empty) {
               var color = new Vector4(cell.LockColor.R / 255f, cell.LockColor.G / 255f, cell.LockColor.B / 255f, 1);
               entitySystem.AddEntity(entityFactory.CreateDungeonLockEntity(new Vector3(cell.X * 70, cell.Y * 70, 0), color, commandFactory, dungeonKeyInventory, navigationGrid));
            }
             }

             using (var game = new ShadeGame(graphicsConfiguration, renderer, entitySystem)) {
            game.Run();
             }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var width = 45;
             var height = 30;
             var grid = new GridFactory().Create(width, height);
             var manipulator = new GridManipulator(grid, new Random());
            //         manipulator.CutLine(new Line2D(new Point2D(0, 0), new Point2D(20, 40)));

             Renderer renderer = null;//new Renderer(grid);//.RenderGrid(grid);
             var spiral = new SpiralParametricFunction(1, 9, 3, width / 2.0f, height / 2.0f, 0);
             manipulator.CutParametric(spiral.TInitial, spiral.TFinal, 20f, spiral.PointAt, renderer);
             var lastSpiralPoint = spiral.PointAt(spiral.TFinal - 30);
             var v = new Vector2D(lastSpiralPoint, new Point2D(width / 2.0f, height / 2.0f));
             v = v.ToUnitVector();
             var cutDestination = lastSpiralPoint + v * 3;
             manipulator.CutLine(new Line2D(lastSpiralPoint, cutDestination), renderer);

             Application.DoEvents();
             var entranceCell = grid.Cells[(height / 2) * grid.Width + (width / 2)];
             var cells = manipulator.FillRegion(entranceCell, renderer);

             renderer = new Renderer(grid);//.RenderGrid(grid);

             manipulator.PlaceLocksAndKeys(entranceCell, cells, new[] {
            Color.Red,
            Color.Blue,
            Color.DarkGreen,
            Color.DeepPink,
            Color.Magenta,
            Color.Cyan,
            Color.Yellow,
            Color.Gold,
            Color.Black,
            Color.DarkOrange,
            Color.Gray,
            Color.Aquamarine,
            Color.AliceBlue,
            Color.Azure,
            Color.DodgerBlue,
            Color.Indigo,
            Color.DeepSkyBlue,
            Color.PaleGreen,
            Color.PaleGoldenrod,
            Color.PaleTurquoise});

             Console.WriteLine("Cell Count: " + cells.Count);
             entranceCell.Type = CellType.Entrance;
             while (true) {
            renderer.RenderGrid(grid);
            Application.DoEvents();
             }
        }