コード例 #1
0
        public void ActivatePressurePlateWithBox()
        {
            (var map, var hero) = GetSimpleMap(5, new Point(0, 0));
            var box = new Box(map, new Point(0, 1));

            map[0, 1] = box;
            var @in  = new Hatch(map, new Point(0, 2));
            var @out = new Hatch(map, new Point(0, 3));

            @in.Out   = @out;
            @out.Out  = @in;
            map[0, 3] = @in;
            map[0, 4] = @out;
            var plate = new PressurePlate(map, new Point(0, 2))
            {
                Target = @in
            };

            @in.Close();
            map[0, 2] = plate;
            Assert.IsFalse(@in.IsOpened);
            Assert.IsFalse(@out.IsOpened);
            hero.TryMove(Direction.Right);
            Assert.IsTrue(@in.IsOpened);
            Assert.IsTrue(@out.IsOpened);
        }
コード例 #2
0
        private static IEnumerable <Level> GetLevels(IEnumerable <Data> levelsData)
        {
            foreach (var data in levelsData)
            {
                var boxes = new HashSet <int> {
                    100, 15, 16, 17, 32, 33, 34, 50, 51, 52, 101, 102, 116
                };
                var hatches = new HashSet <int> {
                    78, 150
                };
                var floors = new HashSet <int> {
                    8, 9, 10, 11, 12, 13, 14, 25, 26, 27, 28, 29, 30,
                    31, 43, 44, 45, 46, 47, 48, 49, 61, 62, 63, 64, 65, 66, 67, 71, 72, 88, 87, 166, 150
                };
                var plateCode = 158;

                var map = new GameObject[Height, Width];
                for (var i = 0; i < map.GetLength(0); i++)
                {
                    for (var j = 0; j < map.GetLength(1); j++)
                    {
                        var code = data.Matrix[i, j];
                        if (boxes.Contains(code))
                        {
                            map[i, j] = new Box(map, new Point(i, j), textures[code]);
                        }
                        else if (hatches.Contains(code))
                        {
                            map[i, j] = new Hatch(map, new Point(i, j));
                        }
                        else if (floors.Contains(code))
                        {
                            map[i, j] = new Floor(map, new Point(i, j), textures[code]);
                        }
                        else if (code == plateCode)
                        {
                            map[i, j] = new PressurePlate(map, new Point(i, j), textures[code]);
                        }
                        else
                        {
                            map[i, j] = new Wall(map, new Point(i, j), textures[code]);
                        }
                    }
                }

                for (var i = 0; i < data.Hatches.Length; i++)
                {
                    for (var j = 1; j < data.Hatches[i].Length; j++)
                    {
                        var inHatchLocation  = data.Hatches[i][0];
                        var inHatch          = (Hatch)map[inHatchLocation.X, inHatchLocation.Y];
                        var outHatchLocation = data.Hatches[i][j];
                        var outHatch         = (Hatch)map[outHatchLocation.X, outHatchLocation.Y];
                        inHatch.Out  = outHatch;
                        outHatch.Out = inHatch;
                    }
                }

                for (var i = 0; i < data.PressurePlates.Length; i++)
                {
                    for (var j = 1; j < data.PressurePlates[i].Length; j++)
                    {
                        var platLocation     = data.PressurePlates[i][0];
                        var plate            = (PressurePlate)map[platLocation.X, platLocation.Y];
                        var outHatchLocation = data.PressurePlates[i][j];
                        var outHatch         = (Hatch)map[outHatchLocation.X, outHatchLocation.Y];
                        plate.Target = outHatch;
                        outHatch.Close();
                    }
                }

                var hero   = new Hero(map, data.Start);
                var finish = new Finish(map, data.Finish);
                map[data.Finish.X, data.Finish.Y] = finish;
                map[data.Start.X, data.Start.Y]   = hero;
                yield return(new Level(map, hero, data.Finish));
            }
        }