Esempio n. 1
0
        // Generate map grid in scrollviewer based on user parameters from startup window
        public RandomWorldGeneratorWindow GenerateMapGrid()
        {
            RandomWorldGeneratorWindow generatedWorld = new RandomWorldGeneratorWindow();

            CurrentWorld = new World(TxtName.Text, (int)SldHeight.Value, (int)SldWidth.Value, (int)SldTileSize.Value, (int)SldBiomeSize.Value);

            GrdMap = new Grid();
            GrdMap.SnapsToDevicePixels = true;

            Tile.Afmeting = CurrentWorld.TileSize;

            for (int i = 1; i <= CurrentWorld.Width; i++)
            {
                ColumnDefinition colDef = new ColumnDefinition();
                colDef.Width = new GridLength(CurrentWorld.TileSize);
                GrdMap.ColumnDefinitions.Add(colDef);
            }

            for (int i = 1; i <= CurrentWorld.Height; i++)
            {
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = new GridLength(CurrentWorld.TileSize);
                GrdMap.RowDefinitions.Add(rowDef);
            }

            ScrViewer = new ScrollViewer
            {
                HorizontalScrollBarVisibility = ScrollBarVisibility.Visible,
                VerticalScrollBarVisibility   = ScrollBarVisibility.Visible,
                Content = GrdMap
            };


            generatedWorld.StpContainer.Children.Add(ScrViewer);



            ScrViewer.Height = CurrentWorld.Height * CurrentWorld.TileSize;
            ScrViewer.Width  = CurrentWorld.Width * CurrentWorld.TileSize;

            if (ScrViewer.Height > 900)
            {
                ScrViewer.Height = 900;
            }

            if (ScrViewer.Width > 1480)
            {
                ScrViewer.Width = 1480;
            }

            generatedWorld.StpContainer.Height = ScrViewer.Height + 5;
            generatedWorld.StpContainer.Width  = ScrViewer.Width + 5;

            generatedWorld.Height = ScrViewer.Height + 100;
            generatedWorld.Width  = ScrViewer.Width + 20;

            generatedWorld.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            return(generatedWorld);
        }
Esempio n. 2
0
        // Clicking the button will open a new window with a randomly generated map
        private void BtnGenerate_Click(object sender, RoutedEventArgs e)
        {
            generatedWorldWindow = GenerateMapGrid();

            GenerateEmptyTilesAndCenterPoints();
            FillTilesBasedOnCenterPoints();
            AddRiversToMap();

            generatedWorldWindow.KeyDown += GeneratedWorldWindowOnKeyDown;
            generatedWorldWindow.Show();
        }