コード例 #1
0
 public MapViewModel(GameMap map)
     : base(map.Map.Map)
 {
     Source = map;
     TileSet = new TileSetViewModel(Map.Map.TileSet);
     TileSet.Saved += (s, e) => OnPropertyChanged("TileSet");
 }
コード例 #2
0
 public void Render(MapObject mapObject)
 {
     MapPoint cellPoint = new MapPoint(0, 0, 0);
         Map map = new Map(1, MapSize.One);
         map[cellPoint] = new MapCell(new MapPlace(), null);
         if (mapObject is MapPlace)
         {
             map[cellPoint].Place = mapObject as MapPlace;
         }
         if (mapObject is MapWall)
         {
             map[cellPoint].SetWall(MapDirection.North, mapObject as MapWall);
             map[cellPoint].SetWall(MapDirection.East, mapObject as MapWall);
             map[cellPoint].SetWall(MapDirection.West, mapObject as MapWall);
             map[cellPoint].SetWall(MapDirection.South, mapObject as MapWall);
         }
         MapState mapState = new MapState(map);
         if (mapObject is MapActiveObject)
         {
             mapState.AddActiveObject(mapObject as MapActiveObject, cellPoint);
         }
         GameMap gameMap = new GameMap(mapState);
         Renderer.SetMap(gameMap, new MapCellRange(cellPoint, cellPoint));
         Renderer.Render();
 }
コード例 #3
0
        /// <summary>
        /// Тест создания карты
        /// </summary>
        /// <param name="MapWidth">Ширина карты (в клетках)</param>
        /// <param name="MapHeight">Высота карты (в клетках)</param>
        /// <param name="LevelsCount">Количество уровней</param>
        /// <param name="WallsCountOnWalledCells">Количество стен в клетке, на которой будут размещаться стены (0..4)</param>
        /// <param name="WalledCellProbability">Вероятность того, что на клетке будут размещаться стены (0..1)</param>
        /// <returns>Занимаемая память</returns>        
        public static Int64 MapCreation(UInt16 MapWidth, UInt16 MapHeight, UInt16 LevelsCount, UInt16 WallsCountOnWalledCells, double WalledCellProbability)
        {
            GameMap game;
            Map map;

            Random rand = new Random();
            try
            {
                MapImage image = new MapImage(MapImageType.Bmp, null);
                MapPlace place = new MapPlace(image, (float)0.8);
                MapWall destroyedWall = new MapWall(image, MapDirection.North, 200);
                MapWall wall = new MapWall(image, MapDirection.North, 200);
                Dictionary<MapDirection, MapWall> walls = new Dictionary<MapDirection, MapWall>();

                if (WallsCountOnWalledCells > 0)
                    walls.Add(MapDirection.North, wall);
                if (WallsCountOnWalledCells > 1)
                    walls.Add(MapDirection.South, wall);
                if (WallsCountOnWalledCells > 2)
                    walls.Add(MapDirection.West, wall);
                if (WallsCountOnWalledCells > 3)
                    walls.Add(MapDirection.East, wall);

                bool isWall = false;
                int probability = (int)Math.Round(WalledCellProbability * 100.0);

                map = new Map(LevelsCount, new MapSize(MapWidth, MapHeight));
                for (int z = 0; z < map.LevelsCount; z++)
                    for (int x = 0; x < map.Size.Width; x++)
                        for (int y = 0; y < map.Size.Height; y++)
                        {
                            isWall = rand.Next(0, 100) < probability;
                            map.Levels[z].Cells[x, y] = new MapCell(place, isWall ? walls : null);
                        }
                game = new GameMap(new MapState(map));
            }
            catch
            {
            }

            Int64 memory = GC.GetTotalMemory(false);

            map = null;
            game = null;
            GC.Collect();

            return memory;
        }
コード例 #4
0
        public static void PathTest()
        {
            GameMap game;
            Map map;

            Random rand = new Random();
            try
            {
                MapImage image = new MapImage(MapImageType.Bmp, null);
                MapPlace place = new MapPlace(image, (float)0.8) { Name = "1" };
                //MapWall destroyedWall = new MapWall("2", image, MapDirection.North, 200);
                MapWall wall = new MapWall(image, MapDirection.North, 200) { Name = "3" };
                Dictionary<MapDirection, MapWall> walls = new Dictionary<MapDirection, MapWall>();

                map = new Map(1, new MapSize(16, 16)) { Name = "Map" };
                for (int z = 0; z < map.LevelsCount; z++)
                    for (int x = 0; x < map.Size.Width; x++)
                        for (int y = 0; y < map.Size.Height; y++)
                        {
                            map.Levels[z].Cells[x, y] = new MapCell(place, null);
                        }
                MapAreas areas= new MapAreas();
             //   MapAreaTransitionPoint pnt1=new MapAreaTransitionPoint("", "",
                areas.Areas.Add(new MapArea(new MapPoint(0, 0, 0), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 4, 0), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 8, 0), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 12, 0), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 0, 4), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 4, 4), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 8, 4), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 12, 4), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 0, 8), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 4, 8), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 8, 8), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 12, 8), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 0, 12), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 4, 12), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 8, 12), new MapSize(4, 4)));
                areas.Areas.Add(new MapArea(new MapPoint(0, 12, 12), new MapSize(4, 4)));
                MapAreaTransitionPoint[] tr0 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[0], areas.Areas[1], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[0], areas.Areas[5], new MapPoint(0, 1, 1), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr1 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[1], areas.Areas[0], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr5 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[5], areas.Areas[0], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[5], areas.Areas[2], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr2 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[2], areas.Areas[5], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[2], areas.Areas[7], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr3 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[3], areas.Areas[6], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr4 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[4], areas.Areas[8], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr6 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[6], areas.Areas[3], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[6], areas.Areas[10], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr7 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[7], areas.Areas[2], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[7], areas.Areas[10], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr8 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[8], areas.Areas[4], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[8], areas.Areas[9], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[8], areas.Areas[12], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr13 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[13], areas.Areas[9], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[13], areas.Areas[14], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[13], areas.Areas[10], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr9 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[9], areas.Areas[8], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[9], areas.Areas[13], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr12 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[12], areas.Areas[8], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr14 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[14], areas.Areas[13], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr15 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[15], areas.Areas[10], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr11 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[11], areas.Areas[10], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                MapAreaTransitionPoint[] tr10 = new MapAreaTransitionPoint[] { new MapAreaTransitionPoint(areas.Areas[10], areas.Areas[6], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[10], areas.Areas[7], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[10], areas.Areas[11], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[10], areas.Areas[15], new MapPoint(0, 0, 0), new MapSize(1, 1)), new MapAreaTransitionPoint(areas.Areas[10], areas.Areas[13], new MapPoint(0, 0, 0), new MapSize(1, 1)) };
                areas.Areas[0].TransitionPoints.AddRange(tr0);
                areas.Areas[1].TransitionPoints.AddRange(tr1);
                areas.Areas[2].TransitionPoints.AddRange(tr2);
                areas.Areas[3].TransitionPoints.AddRange(tr3);
                areas.Areas[4].TransitionPoints.AddRange(tr4);
                areas.Areas[5].TransitionPoints.AddRange(tr5);
                areas.Areas[6].TransitionPoints.AddRange(tr6);
                areas.Areas[7].TransitionPoints.AddRange(tr7);
                areas.Areas[8].TransitionPoints.AddRange(tr8);
                areas.Areas[9].TransitionPoints.AddRange(tr9);
                areas.Areas[10].TransitionPoints.AddRange(tr10);
                areas.Areas[11].TransitionPoints.AddRange(tr11);
                areas.Areas[12].TransitionPoints.AddRange(tr12);
                areas.Areas[13].TransitionPoints.AddRange(tr13);
                areas.Areas[14].TransitionPoints.AddRange(tr14);
                areas.Areas[15].TransitionPoints.AddRange(tr15);

                map.Areas = areas;

                MapState state = new MapState(map);

                game = new GameMap(new MapState(map));

            }
            catch
            {
            }

            Int64 memory = GC.GetTotalMemory(false);

            map = null;
            game = null;
            GC.Collect();
        }
コード例 #5
0
 public void SetMap(GameMap map, MapCellRange range)
 {
     TargetMap = map;
     TargetRange = range;
 }