//Connect rooms which are horizontal neighbours (In the rogue grid of rooms)
        private static void connectHorz(RogueRoom lefty, RogueRoom righty)
        {
            int leftyOffset = MyRandom.Random.Next(0, lefty.Realpos.Height);
            lefty.RoomField.DoorPositions.PositionsArray[lefty.Realpos.Width - 1, leftyOffset, (int)DoorPos.right] = 10;

            int rightyOffset = MyRandom.Random.Next(0, righty.Realpos.Height);
            righty.RoomField.DoorPositions.PositionsArray[0, rightyOffset, (int)DoorPos.left] = 10;

            last = new Point(lefty.Realpos.Right - 1, lefty.Realpos.Y + leftyOffset);
            current = new Point(last.X + 1, last.Y);
            end = new Point(righty.Realpos.X, righty.Realpos.Y + rightyOffset);

            if (end.Y > last.Y)
            {
                maxY = (end.Y + 1) * (int)Globals.Screensize.Y;
                minY = (last.Y) * (int)Globals.Screensize.Y;
            }
            else
            {
                maxY = (last.Y + 1) * (int)Globals.Screensize.Y;
                minY = (end.Y) * (int)Globals.Screensize.Y;
            }

            minX = lefty.RoomField.Bounds.Right;
            maxX = righty.RoomField.Bounds.Left;

            MakewholeCor();
            makeVertDoors(lefty, righty,leftyOffset,rightyOffset);
            corridor.AddEndBit(new Vector2(current.X, current.Y), (int)Globals.EndBitInfo.Left);
            corridor.AddEndBit(new Vector2(end.X - 1, end.Y), (int)Globals.EndBitInfo.Right);
            joinVert();
            joinHorz();
        }
        //Connect 2 given rooms together
        public static void Connect2rooms(RogueRoom room1, RogueRoom room2, Level level, Game game, List<Coord> occupiedlist)
        {
            _occupiedList = occupiedlist;
            var colours = RandomColour.RoomColours();
            _colour = colours[0];
            _lightcolour = colours[1];
            _game = game;
            _level = level;
            halfwidth = MyRandom.Random.Next(1, 7);

            if (room1.Gridpos.X < room2.Gridpos.X)
            {
                connectHorz(room1, room2);
            }
            else if (room1.Gridpos.X > room2.Gridpos.X)
            {
                connectHorz(room2, room1);
            }
            else if (room1.Gridpos.Y < room2.Gridpos.Y)
            {
                connectVert(room1, room2);
            }
            else
            {
                connectVert(room2, room1);
            }
        }
 //connect rooms one by one in a path
 private void connectpath()
 {
     while (true)
     {
         _currentroom.Connected = true;
         unconnectedRooms -= 1;
         var unconnectedneighbourlist = new List<Tuple<int,int>>();
         foreach (var coord in _currentroom.neighbourlist)
         {
             if ( _rogueroomlist[coord].Connected == false)
             {
                 unconnectedneighbourlist.Add(coord);
             }
         }
         if (unconnectedneighbourlist.Count == 0)
         {
             _newLvl.EndRoom = _currentroom.RoomField;
             break;
         }
         var newroomcoord = unconnectedneighbourlist[MyRandom.Random.Next(0, unconnectedneighbourlist.Count())];
         Connector.Connect2rooms(_currentroom, _rogueroomlist[newroomcoord],_newLvl,_game);
         _currentroom = _rogueroomlist[newroomcoord];
     }
 }
 /*
 private List<RogueRoom> ReturnNeighbours(RogueRoom room)
 {
     List<RogueRoom> neighbourlist = new List<RogueRoom>();
     foreach (RogueRoom rogueroom in _rogueroomlist)
     {
         if (((rogueroom.xy.Item1 == room.xy.Item1-1 ||rogueroom.xy.Item1 == room.xy.Item1+1)&&(rogueroom.xy.Item2 == room.xy.Item2))
             || ((rogueroom.xy.Item2 == room.xy.Item2 - 1 || rogueroom.xy.Item2 == room.xy.Item2 + 1) && (rogueroom.xy.Item1 == room.xy.Item1)))
         {
             neighbourlist.Add(rogueroom);
         }
     }
     return neighbourlist;
 }
 */
 //HIgh lvl method to connect all the newly created rooms together according to the Rogue rules
 private void ConnectAllRooms()
 {
     _currentroom = _rogueroomlist[new Tuple<int, int>(MyRandom.Random.Next(0,_xdiv-1),MyRandom.Random.Next(0,_ydiv-1))];
     _newLvl.StartRoom = _currentroom.RoomField;
     connectpath();
     connectrest();
 }
        private void generateMainRooms()
        {
            int gencount = 0;
            for (int x = 0; x < _size; x += _xgrid)
            {
                for (int y = 0; y < _size; y += _ygrid)
                {
                    //HACK made roomchance always true
                    int isroom = MyRandom.Random.Next(2, _roomchance);
                    if (isroom == 1)
                    {
                        continue;
                    }
                    else
                    {
                        int xsize = MyRandom.Random.Next(1, _xgrid);
                        int ysize = MyRandom.Random.Next(1, _ygrid);

                        int xpos = MyRandom.Random.Next(0, _xgrid- xsize);
                        int ypos = MyRandom.Random.Next(0, _ygrid - ysize);

                        var rogueroom = _rogueroomlist[new Tuple<int, int>(x / _xgrid, y / _ygrid)] =
                            new RogueRoom(x / _xgrid, y / _ygrid,x+xpos,y+ypos,_xdiv,_ydiv,xsize,ysize,false);

                        /*
                        if (xsize == 1 && ysize == 1)
                        {
                            var _room = new SmallRoom(_game, new Vector2(x+xpos, y+ypos)
                          , RandomColour.NewColour()
                          , RandomColour.NewColour()
                          );
                            _occupiedGrid[x + xpos, y + ypos] = true;
                            _newLvl.Roomlist.Add(_room);
                            rogueroom.RoomField = _room;
                        }
                        else
                        {*/
                        var roomcolours = RandomColour.RoomColours();
                             var _room = new BigRoom(_game, new Vector2(x + xpos, y + ypos)
                                     , roomcolours[0]
                                     , roomcolours[1]
                                      , new Vector2(xsize, ysize));

                            for (int x1 = x+xpos; x1 < x+xpos+xsize ; x1++)
                            {
                                for (int y1 = y+ypos; y1 < y+ypos+ysize; y1++)
                                {
                                    _occupiedGrid[x1,y1] = true;
                                }
                            }
                            //}
                            //adddoors(_room);
                            _newLvl.Roomlist.Add(_room);
                            rogueroom.RoomField = _room;
                                gencount++;
                    }
                }
            }
        }
        private static void makeVertDoors(RogueRoom lefty, RogueRoom righty,int leftyOffset,int rightyOffset)
        {
            DoorVert thedoor = new DoorVert(_game, new Vector2(righty.RoomField.Bounds.Left
                ,righty.RoomField.Bounds.Top+(Globals.Screensize.Y*rightyOffset) +(Globals.SmallGridSize.Y*10)));
            _level.Doorlist.Add(thedoor);
            righty.RoomField._doorList.Add(thedoor);
            corridor._doorList.Add(thedoor);

            DoorVert thedoor2 = new DoorVert(_game, new Vector2(lefty.RoomField.Bounds.Right
            ,lefty.RoomField.Bounds.Top + (Globals.Screensize.Y * leftyOffset) + (Globals.SmallGridSize.Y * 10)));
            _level.Doorlist.Add(thedoor2);
            lefty.RoomField._doorList.Add(thedoor2);
            corridor._doorList.Add(thedoor2);
        }
        private static void makeHorzDoors(RogueRoom uppy, RogueRoom downy,int uppyOffset,int downyOffset)
        {
            DoorHorz thedoor = new DoorHorz(_game, new Vector2(downy.RoomField.Bounds.Left
                + (Globals.Screensize.X * downyOffset) + (Globals.SmallGridSize.X * 15)
               , downy.RoomField.Bounds.Top-Globals.SmallGridSize.Y));

            _level.Doorlist.Add(thedoor);
            downy.RoomField._doorList.Add(thedoor);
            corridor._doorList.Add(thedoor);

            DoorHorz thedoor2 = new DoorHorz(_game, new Vector2(uppy.RoomField.Bounds.Left
             + (Globals.Screensize.X * uppyOffset) + (Globals.SmallGridSize.X * 15)
            , uppy.RoomField.Bounds.Bottom - Globals.SmallGridSize.Y));

            _level.Doorlist.Add(thedoor2);
            uppy.RoomField._doorList.Add(thedoor2);
            corridor._doorList.Add(thedoor2);
        }
        //Connect rooms which are vertical neighbours (In the rogue grid of rooms)
        private static void connectVert(RogueRoom uppy, RogueRoom downy)
        {
            int uppyOffset = MyRandom.Random.Next(0, uppy.Realpos.Width);
            uppy.RoomField.DoorPositions.PositionsArray[uppyOffset, uppy.Realpos.Height - 1, (int)DoorPos.bottom] = 14;

            int downyOffset = MyRandom.Random.Next(0, downy.Realpos.Width);
            downy.RoomField.DoorPositions.PositionsArray[downyOffset, 0, (int)DoorPos.top] = 14;

            last = new Point(uppy.Realpos.Left + uppyOffset, uppy.Realpos.Bottom - 1);
            current = new Point(last.X, last.Y + 1);
            end = new Point(downy.Realpos.Left + downyOffset, downy.Realpos.Top);

            if (end.X > last.X)
            {
                maxX = (end.X + 1) * (int)Globals.Screensize.X;
                minX = (last.X) * (int)Globals.Screensize.X;
            }
            else
            {
                maxX = (last.X + 1) * (int)Globals.Screensize.X;
                minX = (end.X) * (int)Globals.Screensize.X;
            }

            minY = uppy.RoomField.Bounds.Bottom;
            maxY = downy.RoomField.Bounds.Top;

            MakewholeCor();
            makeHorzDoors(uppy, downy,uppyOffset,downyOffset);
            corridor.AddEndBit(new Vector2(current.X, current.Y), (int)Globals.EndBitInfo.Top);
            corridor.AddEndBit(new Vector2(end.X, end.Y - 1), (int)Globals.EndBitInfo.Bottom);

            joinHorz();
            joinVert();
        }