Example #1
0
 // Because this is the edge the wall is on (rather than the edge the laser is pointing) it will be
 // backwards from what you might expect
 private static Orientation LaserWallEdgeOrientation(SerializedLaser laser)
 {
     if (laser.Row == laser.EndRow)
         return laser.Column > laser.EndColumn ? Orientation.Right : Orientation.Left;
     else
         return laser.Row > laser.EndRow ? Orientation.Bottom : Orientation.Top;
 }
Example #2
0
        private static void AddTileToMap(ITile tile, int row, int column, SerializedMap serializedMap)
        {
            if (tile.GetType() == typeof (Conveyer) || tile.GetType() == typeof (ExpressConveyer))
            {
                var conveyor = new SerializedConveyor()
                {
                    Row = row,
                    Column = column,
                    In = (tile as Conveyer).Entrances.Select(o => o.ToString().ToLowerInvariant()).ToList(),
                    Out = (tile as Conveyer).Exit.ToString().ToLowerInvariant(),
                    Type = (tile.GetType() == typeof (ExpressConveyer) ? "express" : null)
                };
                serializedMap.Conveyors.Add(conveyor);
            }
            else if (tile.GetType() == typeof (Gear))
            {
                var gear = new SerializedGear()
                {
                    Row = row,
                    Column = column,
                    Type = (tile as Gear).Direction.ToString().ToLowerInvariant()
                };
                serializedMap.Gears.Add(gear);
            }
            else if (tile.GetType() == typeof (Wrench) || tile.GetType() == typeof (WrenchHammer))
            {
                var wrench = new SerializedWrench()
                {
                    Row = row,
                    Column = column,
                    Type = (tile.GetType() == typeof (WrenchHammer) ? "option" : null)
                };
                serializedMap.Wrenches.Add(wrench);
            }
            else if (tile.GetType() == typeof (Pit))
            {
                var pit = new SerializedPit()
                {
                    Row = row,
                    Column = column
                };
                serializedMap.Pits.Add(pit);
            }
            //else if (tile.GetType() == typeof(Flag))
            //{
            //	var flag = new SerializedFlag()
            //	{
            //		Row = row,
            //		Column = column,
            //		Order = (tile as Flag).Order
            //	};
            //	serializedMap.Flags.Add(flag);
            //}

            // Any flor type can have walls/lasers
            if (tile is Floor)
            {
                if ((tile as Floor).Edges.Any())
                {
                    var wall = new SerializedWall()
                    {
                        Row = row,
                        Column = column,
                        Edges = (tile as Floor).Edges.Select(p => p.Item1.ToString().ToLowerInvariant()).ToList()
                    };
                    serializedMap.Walls.Add(wall);
                }

                var laserWallEdge = (tile as Floor).Edges.FirstOrDefault(p => p.Item2 is WallLaserEdge);
                if (laserWallEdge != null)
                {
                    // Little bit of a hack around converting directions from "wall edge orientation" to "laser direction"
                    var laserDirection = (Orientation) (((int) laserWallEdge.Item1 + 2)%4);
                    var laser = new SerializedLaser()
                    {
                        Row = row,
                        Column = column,
                        Damage = (laserWallEdge.Item2 as WallLaserEdge).Lasers,
                        Direction = laserDirection
                    };
                    if (laserWallEdge.Item1 == Orientation.Left || laserWallEdge.Item1 == Orientation.Right)
                        laser.EndRow = laser.Row;
                    else
                        laser.EndColumn = laser.Column;
                    serializedMap.Lasers.Add(laser);
                }

                var pusherWallEdge = (tile as Floor).Edges.FirstOrDefault(p => p.Item2 is WallPusherEdge);
                if (pusherWallEdge != null)
                {
                    var pusher = new SerializedPusher()
                    {
                        Row = row,
                        Column = column,
                        Registers = (pusherWallEdge.Item2 as WallPusherEdge).Registers,
                        Wall = pusherWallEdge.Item1.ToString().ToLowerInvariant()
                    };
                    serializedMap.Pushers.Add(pusher);
                }
            }
        }