Esempio n. 1
0
 public MainWindow()
 {
     InitializeComponent();
     ThemeChange("lightTheme");
     Drawer                          = new ImageDrawer();
     Drawer.View                     = MapImage;
     Manager                         = new AlgorithmManager();
     Manager.DataView                = AlgorithmEditor;
     Manager.Tools                   = Tools;
     Manager.ObjectsTools            = ObjectsTools;
     Manager.CommandTools            = CommandsTools;
     Manager.ButtonSaveAlgorithm     = ButtonSaveAlgorithm;
     Manager.ButtonOpenAlgorithm     = ButtonOpenAlgorithm;
     Manager.ButtonExecute           = ButtonExecute;
     Manager.ButtonExecuteStep       = ButtonExecuteStep;
     Manager.ButtonExecuteByPosition = ButtonExecuteByPosition;
     KeyDown                        += AnyKeyDown;
     KeyUp += AnyKeyUp;
 }
Esempio n. 2
0
 public GameObject(Bitmap tile, int x, int y)
 {
     ImageControl = ImageDrawer.BitmapToControl(tile);
     X            = x;
     Y            = y;
 }
Esempio n. 3
0
        /// <summary>
        /// Создание карты из файла
        /// </summary>
        /// <param name="path"></param>
        public Map(string path)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(path);
            // получим корневой элемент
            XmlElement xRoot = xDoc.DocumentElement;

            // обход всех узлов в корневом элементе
            TileWidth  = Convert.ToInt32(xRoot.GetAttributeNode("tilewidth").Value);
            TileHeight = Convert.ToInt32(xRoot.GetAttributeNode("tileheight").Value);
            MapWidth   = Convert.ToInt32(xRoot.GetAttributeNode("width").Value);
            MapHeight  = Convert.ToInt32(xRoot.GetAttributeNode("height").Value);

            MapString   = new string[MapWidth, MapHeight];
            Tiles       = new List <int[]>(4);
            LayersNames = new List <string>(4);
            Tractors    = new List <Tractor>();
            Targets     = new List <GameObject>();

            // парсинг xml-файла карта
            int countTilesets = 0;

            foreach (XmlNode xnode in xRoot)
            {
                if (xnode.Name == "tileset")
                {
                    countTilesets++;
                    Tileset = xnode.Attributes.GetNamedItem("source").Value;
                }
                // получаем атрибут name
                if (xnode.Name == "layer")
                {
                    LayersNames.Add(xnode.Attributes.GetNamedItem("name").Value);
                    XmlNode data  = xnode.FirstChild;
                    int[]   tiles = new int[MapHeight * MapWidth];
                    int     index = 0;
                    foreach (XmlNode childnode in data.ChildNodes)
                    {
                        if (childnode.Attributes.Count > 0)
                        {
                            tiles[index] = Convert.ToInt32(childnode.Attributes.GetNamedItem("gid").Value);
                        }
                        else
                        {
                            tiles[index] = 0;
                        }

                        index++;
                    }
                    Tiles.Add(tiles);
                }
                if (xnode.Name == "objectgroup")
                {
                    foreach (XmlNode childnode in xnode.ChildNodes)
                    {
                        // name //x //y
                    }
                }
            }

            LoadMap();
            MapBackground = ImageDrawer.BitmapToControl(MapBackgroundBitmap);
        }