/// <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); }
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; }
/// <summary> /// Create the object. /// </summary> /// <param name="speed">The speed of the belt. Values are 1 or 2.</param> /// <param name="direction">The direction the belt exits at.</param> /// <param name="entry">The direction(s) the converyor belt enters from.</param> public Conveyor(int speed, MapSquare.DIRECTION direction, MapSquare.SIDE entry) { Speed = speed; Direction = direction; Entry = entry; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="src">Initialize with the values in this object.</param> public MapSquare(MapSquare src) { Type = src.Type; Walls = src.Walls; Conveyor = src.Conveyor == null ? null : new Conveyor(src.Conveyor); Laser = src.Laser == null ? null : new Laser(src.Laser); Flag = src.Flag; }
/// <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; }
public LaserMove(MapSquare.SIDE wallExit, MapSquare.SIDE wallEnter, int xAdd, int yAdd) { this.wallExit = wallExit; this.wallEnter = wallEnter; this.xAdd = xAdd; this.yAdd = yAdd; }
private MOVE_RESULT MoveRobot(Player playerOn, MapSquare.DIRECTION dir, Player origPlayer) { Utilities.MovePoint mp = Utilities.Move(MainMap, playerOn.Robot.Location.MapPosition, dir); // if dead, handle that if (mp.Dead) { playerOn.DecreaseLives(); if (playerOn.Mode == Player.MODE.DEAD) { Trace.WriteLine(string.Format("Player {0} has been killed", playerOn.Name)); framework.mainWindow.StatusMessage(string.Format("Player {0} has been killed", playerOn.Name)); } else Trace.WriteLine(string.Format("destroyed - Player {0}, Lives {1}", playerOn.Name, playerOn.Lives)); if (PlaySounds) pitPlayer.Play(); return MOVE_RESULT.DEAD; } // if can't move we're done if (mp.Location.MapPosition == playerOn.Robot.Location.MapPosition) return MOVE_RESULT.STUCK; // if hitting a robot, can we move it? Player plyrMoveRobot = Players.Where(pl => (pl.IsVisible) && (pl.Robot.Location.MapPosition == mp.Location.MapPosition)).FirstOrDefault(); if (plyrMoveRobot != null) { Trace.WriteLine(string.Format(" push - Player: {0} at {1} trying {2} at {3}", playerOn.Name, playerOn.Robot.Location, plyrMoveRobot.Name, plyrMoveRobot.Robot.Location)); if (MoveRobot(plyrMoveRobot, dir, origPlayer) == MOVE_RESULT.STUCK) { Trace.WriteLine(string.Format(" push failed - Player: {0} at {1} blocked by {2} at {3}", playerOn.Name, playerOn.Robot.Location, plyrMoveRobot.Name, plyrMoveRobot.Robot.Location)); ValidateData(); return MOVE_RESULT.STUCK; } origPlayer.Score += 2; if (plyrMoveRobot.Mode == Player.MODE.DEAD || plyrMoveRobot.Mode == Player.MODE.DESTROYED) origPlayer.Score += 5; Trace.WriteLine(string.Format(" push successful - Player: {0} at {1} moved {2} at {3}", playerOn.Name, playerOn.Robot.Location, plyrMoveRobot.Name, plyrMoveRobot.Robot.Location)); ValidateData(); } playerOn.Robot.Location = new BoardLocation(mp.Location.MapPosition, playerOn.Robot.Location.Direction); return MOVE_RESULT.OK; }