コード例 #1
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();
 }
コード例 #2
0
        /// <summary>
        /// Состояние клетки карты
        /// </summary>
        /// <param name="Cell">Клетка</param>
        /// <param name="Point">Координаты</param>
        public MapCellState(MapCell Cell, MapPoint Point)
        {
            if (Cell == null) throw new ArgumentNullException("Cell", "Cell of MapCellState cannot be null");

            this.Point = Point;
            this.Cell = Cell;
            this.Place = (Cell.Place != null) ? new MapPlaceState(Cell.Place) : null;

            if (Cell.Walls != null)
            {
                foreach (KeyValuePair<MapDirection, MapWall> wall in Cell.Walls)
                {
                    if (wall.Value == null) continue;
                    MapWallState wallState = new MapWallState(wall.Value, wall.Key);
                    wallState.Destroying += (sender, args) => { OnWallDestroying(args.Wall); };
                    wallState.Destroyed += (sender, args) => { OnWallDestroyed(args.Wall); };
                    this.SetWall(wall.Key, wallState);
                }
            }
        }
コード例 #3
0
 public MapCellState CreateCell(MapPlace place, Dictionary<MapDirection, MapWall> walls, MapPoint point)
 {
     MapCellState currentCell = this[point];
     if (currentCell != null)
     {
         if (currentCell.ActiveObjects != null)
         {
             foreach (var activeObject in currentCell.ActiveObjects)
                 this.RemoveActiveObject(GetIdOfActiveObject(activeObject));
         }
     }
     MapCell cell = Map[point] = new MapCell(place, walls);
     return (this[point] = new MapCellState(cell, point));
 }
コード例 #4
0
        public void TestCellsMatrix()
        {
            MapSize size = new MapSize(1000, 1000);
            MapPlace place = new MapPlace(new MapImage(MapImageType.Bmp, null), 1);
            MapCell cell = new MapCell(place, null);

            MapMatrix<MapCell> matrix1 = new MapMatrix<MapCell>(size);
            MapCell[,] matrix2 = new MapCell[size.Width, size.Height];

            for (int x = 0; x < size.Width; x++)
                for (int y = 0; y < size.Height; y++)
                {
                    matrix1[x, y] = cell;
                    matrix2[x, y] = cell;
                }

            DateTime start1 = DateTime.Now;

            for (int i = 0; i < 1000000; i++)
            {
                cell = matrix1[25, 68];
            }

            DateTime finish1 = DateTime.Now;

            DateTime start2 = DateTime.Now;

            for (int i = 0; i < 1000000; i++)
            {
                cell = matrix2[25, 68];
            }

            DateTime finish2 = DateTime.Now;

            double result1 = (finish1 - start1).TotalMilliseconds;
            double result2 = (finish2 - start2).TotalMilliseconds;

            Assert.IsTrue(result1 < 100);
        }