Exemplo n.º 1
0
        public void GetCellBounds(int cellX, int cellY, int cellW, int cellH, int x, int y, int w, int h)
        {
            var floorPlan = new TestGridFloorPlan();

            floorPlan.InitSize(5, 5, 5, 3);
            Rect bounds        = floorPlan.GetCellBounds(new Rect(cellX, cellY, cellW, cellH));
            Rect compareBounds = new Rect(x, y, w, h);

            Assert.That(bounds, Is.EqualTo(compareBounds));
        }
Exemplo n.º 2
0
        public static TestGridFloorPlan InitGridToContext(string[] inGrid, int widthPerCell, int heightPerCell)
        {
            // transposes
            if (inGrid.Length % 2 == 0 || inGrid[0].Length % 2 == 0)
            {
                throw new ArgumentException("Bad input grid!");
            }
            var floorPlan = new TestGridFloorPlan();

            floorPlan.InitSize((inGrid[0].Length / 2) + 1, (inGrid.Length / 2) + 1, widthPerCell, heightPerCell);
            GridRoomPlan[] addedRooms = new GridRoomPlan[26];

            for (int xx = 0; xx < inGrid[0].Length; xx++)
            {
                for (int yy = 0; yy < inGrid.Length; yy++)
                {
                    char val = inGrid[yy][xx];
                    int  x   = xx / 2;
                    int  y   = yy / 2;

                    // rooms
                    if (xx % 2 == 0 && yy % 2 == 0)
                    {
                        if (val >= 'A' && val <= 'Z')
                        {
                            floorPlan.Rooms[x][y] = val - 'A';
                            if (addedRooms[val - 'A'] == null)
                            {
                                addedRooms[val - 'A'] = new GridRoomPlan(new Rect(x, y, 1, 1), new TestGridRoomGen(val));
                            }
                            addedRooms[val - 'A'].Bounds = Rect.IncludeLoc(addedRooms[val - 'A'].Bounds, new Loc(x, y));
                        }
                        else if (val == '0')
                        {
                            floorPlan.Rooms[x][y] = -1;
                        }
                        else
                        {
                            throw new ArgumentException($"Bad input grid val at room {x},{y}!");
                        }
                    }
                    else if (xx % 2 == 0 && yy % 2 == 1)
                    {
                        // vhalls
                        if (val == '#')
                        {
                            floorPlan.VHalls[x][y].SetGen(new TestGridRoomGen());
                        }
                        else if (val == '.')
                        {
                            floorPlan.VHalls[x][y].SetGen(null);
                        }
                        else
                        {
                            throw new ArgumentException($"Bad input grid val at vertical hall {x},{y}!");
                        }
                    }
                    else if (xx % 2 == 1 && yy % 2 == 0)
                    {
                        // hhalls
                        if (val == '#')
                        {
                            floorPlan.HHalls[x][y].SetGen(new TestGridRoomGen());
                        }
                        else if (val == '.')
                        {
                            floorPlan.HHalls[x][y].SetGen(null);
                        }
                        else
                        {
                            throw new ArgumentException($"Bad input grid val at horizontal hall {x},{y}!");
                        }
                    }
                    else if (xx % 2 == 1 && yy % 2 == 1)
                    {
                        // blank
                        if (val != ' ')
                        {
                            throw new ArgumentException("Bad input grid val at blank zone!");
                        }
                    }
                }
            }

            for (int ii = 0; ii < 26; ii++)
            {
                if (addedRooms[ii] != null)
                {
                    floorPlan.ArrayRooms.Add(addedRooms[ii]);
                }
            }

            return(floorPlan);
        }