Ejemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            /*
             * Den Ordner festlegen, in dem die Bilddateien liegen
             * System.IO.Directory.GetCurrentDirectory() gibt das Verzeichnis zurück, in dem die .exe liegt.
             * */
            MapParser.ImagePath = System.IO.Directory.GetCurrentDirectory() + "\\Ressources";
            //MapParser.Load läd eine Map aus der angegebenen XML-Datei (hier: "Testmap.xml" im Anwendungsverzeichnis
            map = CTMapUtils.MapParser.Load(50, 50,MapParser.SpecialMapElement.RiverCrossing);
            //var map = MapParser.Load(System.IO.Directory.GetCurrentDirectory() + "\\Testmap.xml");
            //Die Map ist ein UserControl, verhält sich also wie jedes Steuerelement auf einer Form (z.B. TextBox, Label, ...)
            //DockStyle.Fill sorgt dafür, dass sie die komplette Form ausfüllt
            //map.Dock = DockStyle.Fill;
            //Die Initialize-Methode sorgt dafür, dass die Map ihre einzelnen Bilder erstellt und richtig anordnet
            //Da sie die Größe der Form kennt, kann sie alle Bilder richtig skalieren
            //map.Initialize(this.Size);
            //Hier wird die Map noch als UserControl zum Form hinzugefügt
            //Controls.Add(map);

            var size = new Size(this.Width - 10, this.Height - 10);
            map.Initialize(size);
            pb = new PictureBox() { Image = map.DrawImage(size), Size = size };

            if (B_SAVEIMAGE)
            {
                Image saveImage = map.DrawImage(new Size(4096, 4096));
                saveImage.Save(@"C:\"+DateTime.Now.Ticks.ToString()+".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            this.Controls.Add(pb);

            ////Zum Testen der Kollisionserkennung
            //map.Collision.SetDebugTarget(this);
            //var entity = map.Collision.AddEntity(new Size(50, 80));
            //t = new System.Threading.Timer(tCallback, entity, 1000, 100);
        }
Ejemplo n.º 2
0
        public Map GenerateRandomMap(int width, int height, MapParser.SpecialMapElement specialMapElement)
        {
            //Map deklarieren
            Map returnvalue = null;
            //Zugehöriges Grid erzeugen:
            Grid tempGrid = new Grid();

            tileCountX = width;
            tileCountY = height;

            theSpecialMapElement = specialMapElement;
            if (theSpecialMapElement == MapParser.SpecialMapElement.CentralPark)
            {
                theCentralParkCreator = new CentralParkCreator(tileCountX, tileCountY);
                ParkGridElementPossibilitiesList = GetListFromXML(@"ParkElementList.xml");
            }

            else if (theSpecialMapElement == MapParser.SpecialMapElement.RiverCrossing)
            {
                theRiverCrossingCreator = new RiverCrossingCreator(tileCountX, tileCountY);
            }

            //Die Elementliste aus der Xml "ElementList.xml" ziehen:
            GridElementPossibilitiesList = GetListFromXML(@"ElementList.xml");

            //Im Folgenden das Grid in der in den Parametern zugewiesenen Dimension als Jagged Array erzeugen.
            tempGrid.GridElementCollection = new GridElement[height][];

            for (int i = 0; i < height; i++)
            {
                tempGrid.GridElementCollection[i] = new GridElement[width];
            }

            tileWidth = width;
            tileHeight = height;
            SetMapProperties(width, height);
            tempGrid = SetMapBoundaries(width, height);
            SetTileIds(tempGrid.GridElementCollection);
            returnvalue = new Map(tempGrid);

            return returnvalue;
        }
Ejemplo n.º 3
0
        private void loadMap()
        {
            DateTime start;
            gameSize = new Size(size.Width * 10, size.Height * 10);
            //Bilderordner angebe
            MapParser.ImagePath = string.Format(@"{0}{1}MapImages", Directory.GetCurrentDirectory(), Path.DirectorySeparatorChar);
            start = DateTime.Now;

            Random rnd = new Random();
            int random = rnd.Next(0, 3);
            switch (random)
            {
                case 0:
                    map = MapParser.Load(100, 100, MapParser.SpecialMapElement.RiverCrossing);
                    break;
                case 1:
                    map = MapParser.Load(100, 100, MapParser.SpecialMapElement.None);
                    break;
                case 2:
                    map = MapParser.Load(100, 100, MapParser.SpecialMapElement.CentralPark);
                    break;
            }

            Console.WriteLine("MapParser.Load:" + (System.DateTime.Now - start).ToString());
            //Karte vergrößert sich automatisch mit GUI
            //Karte im GUI anzeigen
            start = DateTime.Now;
            map.Initialize(gameSize);
            Console.WriteLine("MapParser.init:" + (System.DateTime.Now - start).ToString());
            //Karte an Größe des GUIs anpassen
            start = DateTime.Now;
            miniMap = map.DrawImage(size);
            Console.WriteLine("MapParser.draw:" + (System.DateTime.Now - start).ToString());

            int entityHeight = size.Height / 39;
            int entityWidth = size.Width / 120;
            Size entitySize = new Size(entityWidth, entityHeight);
            Size carSize = new Size(entityHeight, entityWidth);
            entity = map.Collision.AddEntity(entitySize);
            car = new CarImpl(size, gameSize, entity, carSize);
            car.Location = map.GetRandomTilePosition(true, gameSize);

            loaded = true;
        }
Ejemplo n.º 4
0
        public static Map Load(string path)
        {
            Map returnvalue = null;

            Grid grid = null;
            try
            {
                using (var fileStream = System.IO.File.Open(path, System.IO.FileMode.Open))
                {
                    var serializer = new XmlSerializer(typeof(Grid));
                    grid = (Grid)serializer.Deserialize(fileStream);
                }

                returnvalue = new Map(grid);
            }
            catch (Exception)
            {
            }

            return returnvalue;
        }
Ejemplo n.º 5
0
        public Map GenerateRandomMap(int width, int height)
        {
            //Map deklarieren
            Map returnvalue = null;
            //Zugehöriges erzeugen:
            Grid tempGrid = new Grid();

            //Die Elementliste aus der Xml "ElementList.xml" ziehen:
            GridElementPossibilitiesList = GetListFromXML();

            //Im Folgenden das Grid in der in den Parametern zugewiesenen Dimension als Jagged Array erzeugen.
            tempGrid.GridElementCollection = new GridElement[height][];

            for (int i = 0; i < height; i++)
            {
                tempGrid.GridElementCollection[i] = new GridElement[width];
            }

            tileWidth = width;
            tileHeight = height;

            SetMapProperties(width, height);
            tempGrid = SetMapBoundaries(width, height);

            SetTileIds(tempGrid.GridElementCollection);

            returnvalue = new Map(tempGrid);

            return returnvalue;
        }
Ejemplo n.º 6
0
        private void Initilize()
        {
            if (!_initialized)
            {
                Fullscreen();
                _Dimension = GetResolution();
                Size size = new Size((int)(_Dimension[0] * 1.2), (int)(_Dimension[1] * 1.2));
                img = Properties.Resources._3;
                img = CT_Helper.resizeImage(img, size);

                #region Menu
                int drawingPointWidth = _Dimension[0] / 2;
                int drawingPointHeight = _Dimension[1] / 2;
                Point menu = new Point(drawingPointWidth - 683 / 2, drawingPointHeight - 384 / 2);
                menuContainer = new DoubleBufferedPanel(menu);

                menuContainer.Width = _Dimension[0];
                menuContainer.Height = _Dimension[1];

                menuContainer.Location = new Point(0, 0);
                menuContainer.Name = "Menu";

                menuHolder = new DoubleBufferedPanel();

                string[] buttonTexts = { "Starten", "Laden", "Speichern", "Fortsetzen", "Beenden", "Highscore" };
                int positionMultiplicator = 1;
                int offset = 10;
                foreach (string text in buttonTexts)
                {

                    VistaButton button = new VistaButton();
                    button.ButtonText = text;

                    button.Width = 136;
                    button.Height = 38;
                    button.Location = new Point(offset + button.Width / 4, (button.Height + offset) * positionMultiplicator);
                    menuHolder.Controls.Add(button);
                    positionMultiplicator++;
                    button.Click += Button_Click;
                    button.KeyDown += CT_UI_KeyDown;
                    button.KeyUp += CT_UI_KeyUp;
                    button.BackColor = Color.Transparent;
                    button.BaseColor = Color.Transparent;
                    button.ButtonColor = Color.FromArgb(155, Color.DarkSlateGray);
                    button.GlowColor = Color.LightGray;
                    button.Font = new System.Drawing.Font("Pricedown", 16.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    button.CornerRadius = 8;
                }

                this.Controls.Add(menuContainer);
                this.Controls.Add(menuHolder);
                menuHolder.BringToFront();
                menuHolder.BorderStyle = BorderStyle.Fixed3D;
                menuHolder.Width = 683;
                menuHolder.Height = 384;
                menuHolder.Location = menu;
                menuHolder.BackColor = Color.Black;
                menuContainer.BackColor = Color.FromArgb(150, Color.Black);

                #endregion

                #region car
                carpanel = new CarPanel(_Dimension);
                //this.Controls.Add(carpanel);
                #endregion

                setCursor();
                this.Focus();

                //Bilderordner angeben
                MapParser.ImagePath = string.Format(@"{0}{1}MapImages", Directory.GetCurrentDirectory(), Path.DirectorySeparatorChar);
                //Karte aus XML laden
                //map = MapParser.Load(@"C:\Users\Bongo\Desktop\Berufsschule\Diagramme AE\Game\CrazyTaxi\testmap.xml");
                map = MapParser.Load(20, 20);
                //Karte vergrößert sich automatisch mit GUI
                //Karte im GUI anzeigen

                //Karte an Größe des GUIs anpassen
                map.Initialize(new Size(_Dimension[0], _Dimension[1]));
                this.BackgroundImage = map.DrawImage(new Size(_Dimension[0],_Dimension[1]));
                this.TransparencyKey = Color.FromArgb(255, 255, 254);
                this.Controls.Add(carpanel);
                map.Collision.SetDebugTarget(this);
                entity = map.Collision.AddEntity(new Size(12,23));

                _initialized = true;
            }
        }