Beispiel #1
0
 /// <summary>
 /// Create the map from the passed across XML
 /// </summary>
 /// <param name="element">The parent map node.</param>
 public GameMap(XElement element)
 {
     int width = int.Parse(element.Attribute("width").Value);
     int height = int.Parse(element.Attribute("height").Value);
     Squares = new MapSquare[width][];
     for (int x = 0; x < width; x++)
     {
         Squares[x] = new MapSquare[height];
         for (int y = 0; y < height; y++)
         {
             XElement elemSquare =
                 (from sq in element.Elements("square")
                  where ((int) sq.Attribute("x") == x) && ((int) sq.Attribute("y") == y)
                  select sq).First();
             Squares[x][y] = new MapSquare(elemSquare);
         }
     }
 }
Beispiel #2
0
        public Map(XElement elemMap, List<Company> companies)
        {
            int width = Convert.ToInt32(elemMap.Attribute("width").Value);
            int height = Convert.ToInt32(elemMap.Attribute("height").Value);
            UnitsPerTile = Convert.ToInt32(elemMap.Attribute("units-tile").Value);

            Squares = new MapSquare[width][];
            for (int x = 0; x < width; x++)
                Squares[x] = new MapSquare[height];

            foreach (XElement elemTile in elemMap.Elements("tile"))
            {
                int x = Convert.ToInt32(elemTile.Attribute("x").Value);
                int y = Convert.ToInt32(elemTile.Attribute("y").Value);
                Squares[x][y] = new MapSquare(elemTile);
            }

            foreach (var cmpyOn in companies)
                Squares[cmpyOn.BusStop.X][cmpyOn.BusStop.Y].ctor(cmpyOn);
        }
 /// <summary>
 /// Create the object
 /// </summary>
 /// <param name="mapPosition">The board square loacted on.</param>
 /// <param name="direction">The direction pointed to on the board.</param>
 public BoardLocation(Point mapPosition, MapSquare.DIRECTION direction)
 {
     _mapPosition = mapPosition;
     _direction = direction;
 }
Beispiel #4
0
        private static int _CalcLaserDamage(GameMap map, Point position, int xAdd, int yAdd, MapSquare.DIRECTION laserDirection, MapSquare.SIDE wallExit, MapSquare.SIDE wallEnter)
        {
            int damage = 0;
            int x = position.X;
            int y = position.Y;
            bool startSquare = true;

            while ((0 <= x) && (x < map.Width) && (0 <= y) && (y < map.Height))
            {
                MapSquare sq = map.Squares[x][y];
                // can we move into this square?
                if ((! startSquare) && ((sq.Walls & wallEnter) != 0))
                    break;
                startSquare = false;

                if ((sq.Laser != null) && (sq.Laser.Location.Direction == laserDirection))
                {
                    damage++;
                    break;
                }

                // can we move out of this square?
                if ((sq.Walls & wallExit) != 0)
                    break;
                x += xAdd;
                y += yAdd;
            }
            return damage;
        }
Beispiel #5
0
        /// <summary>
        /// Move a unit one square in the requested direction. Ignores all robots on the map but does take into account walls, conveyor belts and gears.
        /// </summary>
        /// <param name="map">The game map.</param>
        /// <param name="position">The map square to start the move from.</param>
        /// <param name="direction">The direction to move.</param>
        /// <returns>The final location of the move.</returns>
        public static MovePoint Move(GameMap map, Point position, MapSquare.DIRECTION direction)
        {
            // watch for wall in this direction
            MapSquare.SIDE sideExit = sideMoveOut[(int) direction];
            MapSquare.SIDE sideEnter = sideMoveIn[(int) direction];
            BoardLocation location = new BoardLocation(position, direction);

            // can we exit this square?
            MapSquare sq = map.GetSquare(position);
            if ((sq.Walls & sideExit) != 0)
                return new MovePoint(location);
            BoardLocation moveTo = location.Move(1);

            // did we go off the board?
            if ((moveTo.MapPosition.X < 0) || (map.Width <= moveTo.MapPosition.X) ||
                (moveTo.MapPosition.Y < 0) || (map.Height <= moveTo.MapPosition.Y))
                return new MovePoint(location, true);

            // did we go into a pit?
            if (map.GetSquare(moveTo.MapPosition).Type == MapSquare.TYPE.PIT)
                return new MovePoint(moveTo, true);

            // can we enter the new square?
            sq = map.GetSquare(moveTo.MapPosition);
            if ((sq.Walls & sideEnter) != 0)
                return new MovePoint(location);

            return new MovePoint(moveTo);
        }