public RoomOpeningLever(Game game, Point Tile, MapRoom Target, bool flipped = false) : base(game)
        {
            Ani            = new Animation(AnimationLoader._this.GetAnimation("images/misc/lever"));
            Ani.ImageSpeed = 0;
            Block          = Tile;
            var T = game.TM.GetTile(Tile.X, Tile.Y);

            TEST = this;
            if (T != null && T.solid)
            {
                if (Target != null)
                {
                    this.Room = Target;
                }
                T.Breakable = false;
                T.CanSlope  = false;
                var R = T.GetHitbox();
                if (flipped)
                {
                    Ani.Position.X = R.left - 16;
                    Ani.Flipped    = true;
                }
                else
                {
                    Ani.Position.X = R.right;
                }
                Ani.Position.Y = R.top;
            }
            else
            {
                Alive = false;
            }
        }
        /*public static void BoxyGenerate(Game game)
         * {
         *  Helper.Log("boxy generate");
         *  var player = game.player;//player character
         *  var map = game.TM;//the tilemap to generate
         *  var bounds = game.stageBounds;//the bounds to stay within
         *  MapRoom.PlacedRooms = new List<MapRoom>();
         *  MapRoom.OpenRooms = new List<MapRoom>();
         *
         *  var SX = map.columns / 2;
         *  var SY = map.rows / 3;
         *  var root = new MapRoom();
         *  root.SX = SX;
         *  root.SY = SY;
         *  root.EX = SX + 6 + (int)(Math.Random() * 10);
         *  root.EY = SY + 6 + (int)(Math.Random() * 10);
         *
         *  root.game = game;
         *  rootroom = root;
         *
         *  //var roomtotal = 12+(int)(Math.Random() * 10);
         *  //var roomtotal = 16 + (int)(Math.Random() * 16);
         *
         *  //var roomMinimum = 16;
         *  var roomMinimum = 10+Math.Min(game.level,4);
         *  var roomtotal = roomMinimum + (int)(Math.Random() * (roomMinimum));
         *  //var rooms = 0;
         *
         *  var attempts = 400;
         *  var R = root;
         *  if (!root.PlaceAndExpand())
         *  {
         *      Helper.Log("Couldn't generate root room.");
         *      return;
         *  }
         *  while (MapRoom.OpenRooms.Count < roomtotal && attempts > 0)
         *  {
         *      var L = MapRoom.FindValidUnplacedRooms().Pick();
         *      if (L.PlaceAndExpand())
         *      {
         *          //rooms++;
         *      }
         *      attempts--;
         *  }
         *  var RR = game.stageBounds - game.TM.position;
         *  RR.width -= game.TM.tilesize;
         *  RR.height -= game.TM.tilesize;
         *  game.TM.DrawRect(RR);
         *  game.TM.ApplyBreakable();
         *  var secrets = Math.Random()<0.3 ? 1 : 0;
         *  if (secrets > 0 && Math.Random() < 0.3)
         *  {
         *      secrets++;
         *  }
         *  while (secrets > 0)
         *  {
         *      var L = MapRoom.FindValidUnplacedRooms().Pick();
         *      if (L.PlaceAndExpand())
         *      {
         *          L.MakeSecret();
         *          var lever = AttemptCreateLever(game, L);
         *          game.AddEntity(lever);
         *          Helper.Log("Placed secret room at:" + L.SX + "," + L.SY);
         *      }
         *      secrets--;
         *  }
         *  var V = FindEmptySpace(game);
         *  keyroom = null;
         *  if (V != null)
         *  {
         *      game.Door.Position.CopyFrom(V);
         *      game.Door.DropToGround();
         *      doorroom = MapRoom.FindRoom(game.Door.Position);
         *      if (doorroom == null)
         *      {
         *          Helper.Log("Door room could not be determined...");
         *      }
         *
         *      var PC = (PlayerCharacter)player;
         *      //PC.MoveToNewSpawn(V);
         *      PC.MoveToNewSpawn(game.Door.Position);
         *      Helper.Log("spawning at:" + (int)V.X + "," + (int)V.Y);
         *  }
         *  else
         *  {
         *      Helper.Log("cannot locate a spawn point...");
         *  }
         *
         * }*/
        public static RoomOpeningLever AttemptCreateLever(Game game, MapRoom Target)
        {
            var i = 0;

            while (i < 20)
            {
                var lever = RoomOpeningLever.FindAndPlaceOnWall(game, MapRoom.FindAnyEmptySpot(), Target);
                if (lever != null)
                {
                    return(lever);
                }
            }
            return(null);
        }
        public static RoomOpeningLever FindAndPlaceOnWall(Game game, Vector2 P, MapRoom Target)
        {
            var T = game.TM.CheckForTile(P);

            if (T != null)
            {
                var X = T.column;
                var Y = T.row;

                var XD = Math.Random() < 0.5 ? -1 : 1;
                while (true)
                {
                    X += XD;
                    var T2 = game.TM.GetTile(X, Y);
                    if (T2 != null)
                    {
                        if (T2.enabled && T2.solid)
                        {
                            var T3 = game.TM.GetTile(X - XD, Y + 1);
                            if (!(T3 != null && T3.enabled && T3.solid))//too close to the floor, the lever could become obscured...
                            {
                                var ret = new RoomOpeningLever(game, new Point(X, Y), Target, XD == 1);
                                return(ret.Alive ? ret : null);
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }