Ejemplo n.º 1
0
        void DrawMap(int index, Size pictureSize, Size pixelSize)
        {
            Bitmap   image    = new Bitmap(pictureSize.Width, pictureSize.Height);
            Graphics graphics = Graphics.FromImage(image);

            for (int x = 0; x < settings.mapWidth; x++)
            {
                for (int y = 0; y < settings.mapHeight; y++)
                {
                    graphics.FillRectangle(SelectBrush(index, x, y), x * pixelSize.Width, y * pixelSize.Height, pixelSize.Width, pixelSize.Height);
                }
            }

            PictureData data = new PictureData();

            data.image    = image;
            data.fit      = population[index].fitness;
            data.index    = index;
            data.terrains = new int[Program.NumberOfTerrainTypes];
            data.terrains[(int)TerrainType.Grass]    = (int)Math.Floor(population[index].tileAmounts[(int)TerrainType.Grass] * 100);
            data.terrains[(int)TerrainType.Water]    = (int)Math.Floor(population[index].tileAmounts[(int)TerrainType.Water] * 100);
            data.terrains[(int)TerrainType.Forest]   = (int)Math.Floor(population[index].tileAmounts[(int)TerrainType.Forest] * 100);
            data.terrains[(int)TerrainType.Mountain] = (int)Math.Floor(population[index].tileAmounts[(int)TerrainType.Mountain] * 100);
            data.terrains[(int)TerrainType.Sand]     = (int)Math.Floor(population[index].tileAmounts[(int)TerrainType.Sand] * 100);
            data.terrains[(int)TerrainType.Ice]      = (int)Math.Floor(population[index].tileAmounts[(int)TerrainType.Ice] * 100);

            Program.tg_form.SetMapPicture(data);
            graphics.Dispose();
        }
Ejemplo n.º 2
0
        public void SetMapPicture(PictureData data)
        {
            if (this.map1_picturebox.InvokeRequired)
            {
                SetMapPictureDelegate del = new SetMapPictureDelegate(SetMapPicture);
                this.Invoke(del, new object[] { data });
            }
            else
            {
                string     map_name      = "map" + (data.index + 1).ToString();
                PictureBox picture       = this.Controls.Find(map_name + "_picturebox", true).FirstOrDefault() as PictureBox;
                Label      fit_text      = this.Controls.Find(map_name + "_fitness_text", true).FirstOrDefault() as Label;
                Label      water_text    = this.Controls.Find(map_name + "_water_text", true).FirstOrDefault() as Label;
                Label      land_text     = this.Controls.Find(map_name + "_land_text", true).FirstOrDefault() as Label;
                Label      forest_text   = this.Controls.Find(map_name + "_forest_text", true).FirstOrDefault() as Label;
                Label      mountain_text = this.Controls.Find(map_name + "_mountain_text", true).FirstOrDefault() as Label;
                Label      sand_text     = this.Controls.Find(map_name + "_sand_text", true).FirstOrDefault() as Label;
                Label      ice_text      = this.Controls.Find(map_name + "_ice_text", true).FirstOrDefault() as Label;

                if (picture != null)
                {
                    picture.Image = data.image;
                    picture.Refresh();
                }

                if (fit_text != null)
                {
                    fit_text.Text = data.fit.ToString();
                }
                if (water_text != null)
                {
                    water_text.Text = data.terrains[(int)TerrainType.Water].ToString();
                }
                if (land_text != null)
                {
                    land_text.Text = data.terrains[(int)TerrainType.Grass].ToString();
                }
                if (forest_text != null)
                {
                    forest_text.Text = data.terrains[(int)TerrainType.Forest].ToString();
                }
                if (mountain_text != null)
                {
                    mountain_text.Text = data.terrains[(int)TerrainType.Mountain].ToString();
                }
                if (sand_text != null)
                {
                    sand_text.Text = data.terrains[(int)TerrainType.Sand].ToString();
                }
                if (ice_text != null)
                {
                    ice_text.Text = data.terrains[(int)TerrainType.Ice].ToString();
                }
            }
        }