/// <summary>
        /// Add a map to the repository. Optionally it can be saved on the disk
        /// immidiately as well.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="saveImmidiately"></param>
        /// <returns></returns>
        public Boolean AddToRepository(Map map, Boolean saveImmidiately)
        {
            this.Repository.Add(map);
            Boolean addingSuccessful = true;
            if (saveImmidiately)
            {
                String fullPath = String.Concat(this.RepositoryPath, "//", map.Id);
                if (this.DirectoryHelper.TryToCreateIfNotExists(fullPath))
                {
                    map.UpdateXmlDocument();

                    String fullMapXmlPath = String.Concat(fullPath, "//map.xml");
                    map.XElementMapTree.Save(fullMapXmlPath);

                    String fullMapImgPath = String.Concat(fullPath, "//map.jpg");
                    map.Image.Save(fullMapImgPath);

                    addingSuccessful = true;
                }
                else
                {
                    addingSuccessful = false;
                }
            }

            return addingSuccessful;
        }
Пример #2
0
 /// <summary>
 /// Car constructor
 /// </summary>
 /// <param name="playerPosition">Aka id or so</param>
 /// <param name="driver"></param>
 /// <param name="color"></param>
 /// <param name="map"></param>
 public Car(int playerPosition, Player driver, Color color, Map map)
 {
     this.SpeedHandlerUtility = new SpeedHandlerUtility();
     this.CarDirectionHandlerUtility = new CarDirectionHandlerUtility();
     this.PlayerPosition = playerPosition;
     this.Driver = driver;
     this.Color = color;
     this.Speed = map.CarStartSpeed;
     this.CarDirection = map.CarStartDirection;
     this.PreviousLocation = null;
     this.CurrentLocation = map.CarStartPositions[playerPosition];
     this.PossibleNextLocations = map.CalculatePossibleNextLocations(this.CurrentLocation, this.CarDirection, this.Speed);
     this.Map = map;
 }
        /// <summary>
        /// SingleplayerModeGameView constructor.
        /// </summary>
        /// <param name="applicationController"></param>
        /// <param name="car"></param>
        /// <param name="map"></param>
        public SingleplayerModeGameView(ApplicationController applicationController, Car car, Map map)
        {
            InitializeComponent();
            this.ApplicationController = applicationController;
            this.Car = car;
            this.Map = map;
            this.RawMapGrid = this.Map.GetDrawMapGrid();
            this.DrawUtility = new DrawUtility();

            this.CustomInitializeComponent();
            this.Refresh();

            this.RunGame();
        }
        /// <summary>
        /// Loads maps from defined directory into cache. You can use the
        /// attribute "LastExceptions" to check whether any exceptions occured
        /// during the loading process. Despite every exception is logged.
        /// </summary>
        public void LoadFromDirectoryIntoCache(Boolean loadPublishedOnly)
        {
            this.LastExceptions.Clear();

            foreach (String directory in Directory.GetDirectories(this.RepositoryPath))
            {
                String xmlMapPath = String.Concat(directory, "//map.xml");
                String imageMapPath = String.Concat(directory, "//map.jpg");

                try
                {
                    // Load current map details
                    XDocument xmlMap = XDocument.Load(xmlMapPath);
                    Image mapThumbnailOriginal = Image.FromFile(imageMapPath);
                    Image mapThumbnail = (Image) mapThumbnailOriginal.Clone();
                    mapThumbnailOriginal.Dispose();
                    Map map = new Map(directory, xmlMap, mapThumbnail);

                    if (loadPublishedOnly && map.Published == false)
                    {
                        continue;
                    }

                    this.Repository.Add(map);
                }
                catch(OutOfMemoryException outOfMemoryException)
                {
                    this.LastExceptions.Add(outOfMemoryException);
                }
                catch (FileNotFoundException fileNotFoundException)
                {
                    this.LastExceptions.Add(fileNotFoundException);
                }
                catch (ArgumentException argumentException)
                {
                    this.LastExceptions.Add(argumentException);
                }
            }
        }
 public void StartSingleplayerModeGame(Car car, Map map)
 {
     this.SingleplayerMode.Hide();
     this.SingleplayerModeGameView = new SingleplayerModeGameView(this, car, map);
     this.SingleplayerModeGameView.Show();
 }
 public bool AddMapToRepository(Map map)
 {
     return this.MapRepository.AddToRepository(map, true);
 }
        private void SetSettings(Map map)
        {
            this.rTextBoxMapId.Text = map.Id;
            this.rTextBoxTitle.Text = map.Title;
            this.richTextBoxDescription.Text = map.Description;
            this.numericUpDownFieldsize.Value = map.FieldSize;
            this.numericUpDownStartSpeed.Value = map.CarStartSpeed;
            this.numericUpDownHitbox.Value = map.Hitbox;
            this.comboBoxStartDirection.Text = map.CarStartDirection;
            this.checkBoxPublish.Checked = map.Published;

            // CLEAR DATA-BIND
            this.listBoxStartpositions.ValueMember = "";
            this.listBoxStartpositions.DataSource = null;
            this.listBoxEndpositions.DataSource = null;
            this.listBoxEndpositions.ValueMember = "";
            this.listBoxForbiddenPositions.DataSource = null;
            this.listBoxForbiddenPositions.ValueMember = "";

            // UPATE
            this.CarStartPositions = map.CarStartPositions;
            this.RoundFinishedPositions = map.RoundFinishedPositions;
            this.ForbiddenPositions = map.ForbiddenPositions;

            // LIST BOX RE-DATA-BIND
            this.listBoxStartpositions.DataSource = this.CarStartPositions;
            this.listBoxStartpositions.ValueMember = "ListDisplay";
            this.listBoxStartpositions.Refresh();

            this.listBoxEndpositions.DataSource = this.RoundFinishedPositions;
            this.listBoxEndpositions.ValueMember = "ListDisplay";

            this.listBoxForbiddenPositions.DataSource = this.ForbiddenPositions;
            this.listBoxForbiddenPositions.ValueMember = "ListDisplay";
        }
        private void rButtonSaveWholeMap_Click(object sender, EventArgs e)
        {
            String id = this.rTextBoxMapId.GetValue();
            String title = this.rTextBoxTitle.GetValue();
            String description = this.richTextBoxDescription.Text;

            int fieldsize = 0;
            Int32.TryParse(this.numericUpDownFieldsize.Value.ToString(), out fieldsize);

            int carStartSpeed = 0;
            Int32.TryParse(this.numericUpDownStartSpeed.Value.ToString(), out carStartSpeed);

            int hitbox = 0;
            Int32.TryParse(this.numericUpDownHitbox.Value.ToString(), out hitbox);

            String carStartDirection = this.comboBoxStartDirection.SelectedItem.ToString();
            Boolean published = this.checkBoxPublish.Checked;

            Image image = this.pictureBoxMapPicture.Image;

            Map newMap = new Map(id, id, title, description, fieldsize, hitbox, carStartSpeed, carStartDirection, published, this.CarStartPositions, this.RoundFinishedPositions, this.ForbiddenPositions, image);
            if (this.applicationController.AddMapToRepository(newMap))
            {
                MessageBox.Show("Map saved.");
            }
            else
            {
                MessageBox.Show("Could not save the map.");
            }
        }
        private void rButtonImportWholeMap_Click(object sender, EventArgs e)
        {
            DialogResult dr = this.folderBrowserDialogWholeMap.ShowDialog();
            if (dr == DialogResult.OK)
            {
                String path = this.folderBrowserDialogWholeMap.SelectedPath;
                String mapSettingsPath = String.Concat(path, "//map.xml");

                XDocument xmlMap = XDocument.Load(mapSettingsPath);
                Map map = new Map("settings", xmlMap, new Bitmap(1, 1, PixelFormat.Format32bppPArgb));
                this.SetSettings(map);

                String mapImgPath = String.Concat(path, "//map.jpg");
                this.pictureBoxMapPicture.Image = Image.FromFile(mapImgPath);
            }
        }
 private void rButtonImportSettingsFromDisk_Click(object sender, EventArgs e)
 {
     DialogResult dr = this.openFileDialogLoadMapSettings.ShowDialog();
     if (dr == DialogResult.OK)
     {
         XDocument xmlMap = XDocument.Load(this.openFileDialogLoadMapSettings.FileName);
         Map map = new Map("settings", xmlMap, new Bitmap(1, 1, PixelFormat.Format32bppPArgb));
         this.SetSettings(map);
     }
 }