示例#1
0
        public static void DrawMap(Graphics gfx, MapGraph kb, float scale)
        {
            var offsetX = scale;
            var offsetY = scale;

            var brush = new SolidBrush(Color.FromArgb(150, 0, 255, 0));
            var brushTreasure = new SolidBrush(Color.FromArgb(255, 255, 255, 0));
            var brushEntry = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
            var brushWall = new SolidBrush(Color.FromArgb(255, 0, 0, 0));

            foreach (var state in kb.States)
            {
            var b = brush;
            switch (state.Type)
            {
            case Tile.Treasure: b = brushTreasure; break;
            case Tile.Entry: b = brushEntry; break;
            case Tile.Wall: b = brushWall; break;
            }

            gfx.FillRectangle(b, offsetX + (state.X * scale) - 10, offsetY + (state.Y * scale) - 10, 20, 20);
            }

            // Draw routes
            var pen = new Pen(Color.Black) { Width = 3 };
            foreach (var action in kb.Actions)
            gfx.DrawLine(pen, offsetX + action.StateA.X * scale, offsetY + action.StateA.Y * scale, offsetX + action.StateB.X * scale, offsetY + action.StateB.Y * scale);
        }
示例#2
0
        public static MapGraph Parse(Map map)
        {
            var kb = new MapGraph();
            kb.Actions = new List<Action>();
            kb.States = new List<State>();

            for (var i = 0; i < map.Tiles.Count; i++)
            {
            Console.WriteLine(i);
            var row = map.Tiles[i];
            for (var j = 0; j < row.Count; j++)
            {
            var tile = row[j];

            // skip wall tiles
            if (tile.Equals(Tile.Wall)) continue;

            var state = kb.GetOrCreateState(j, i, tile, map);

            // adjacent tiles
            var n = kb.GetOrCreateState(j, i-1, map.TileAt(j, i-1), map);
            var e = kb.GetOrCreateState(j+1, i, map.TileAt(j+1, i), map);
            var s = kb.GetOrCreateState(j, i+1, map.TileAt(j, i+1), map);
            var w = kb.GetOrCreateState(j-1, i, map.TileAt(j-1, i), map);

            // actions between tile and adjacent
            kb.GetOrCreateAction(state, n, "N");
            kb.GetOrCreateAction(state, e, "E");
            kb.GetOrCreateAction(state, s, "S");
            kb.GetOrCreateAction(state, w, "W");
            }
            }

            return kb;
        }
示例#3
0
        public ProgramB()
        {
            var mapString =
            @"###I####
            #$#    #
            # ####$#
            #  $   #
            #### $ #
            #$ #   #
            # $# $ #
            ########";
            var map = Map.Parse(mapString);
            this.kb = MapGraph.Parse(map);

             	this.Paint += new PaintEventHandler(this.OnPaint);
        }