Пример #1
0
        private bool LoadLevel(string path)
        {
            OpenFileDialog a = new OpenFileDialog();

            a.AddExtension     = false;
            a.DefaultExt       = ".bin";
            a.Filter           = "binary files (*.bin) | *.bin";
            a.FilterIndex      = 1;
            a.InitialDirectory = path;
            a.RestoreDirectory = true;
            if (a.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream          loader = File.OpenRead(a.FileName);
                    BinaryFormatter deserz = new BinaryFormatter();
                    KulaLevel       lvl    = (KulaLevel)deserz.Deserialize(loader);
                    loader.Close();
                    loader.Dispose();
                    return(LoadKulaLevel(lvl));
                }
                catch (Exception e)
                {
                    MessageBox.Show("Sembrano esserci problemi nel caricamento, infatti l'eccezione scaturita dice: \n" + e.ToString());
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        private void FillGrid(KulaLevel lvl)
        {
            Pair <byte> placer;

            foreach (KulaLevel.Block b in lvl.Blocks)
            {
                if (!lvlGrid.ContainsKey(placer = new Pair <byte>(b.X, b.Y)))
                {
                    lvlGrid.Add(placer, b);
                }
            }

            foreach (KulaLevel.Placeable p in lvl.Placeables)
            {
                if (!lvlGrid.ContainsKey(placer = new Pair <byte>(p.X, p.Y)))
                {
                    lvlGrid.Add(placer, p);
                }
            }

            foreach (KulaLevel.Enemy e in lvl.Enemies)
            {
                if (!lvlGrid.ContainsKey(placer = new Pair <byte>(e.X, e.Y)))
                {
                    lvlGrid.Add(placer, e);
                }
            }
        }
Пример #3
0
        private bool SaveLevel(string path)
        {
            SaveFileDialog a = new SaveFileDialog();

            a.AddExtension     = false;
            a.DefaultExt       = ".bin";
            a.FileName         = "NewLevel";
            a.InitialDirectory = path;
            a.RestoreDirectory = true;
            if (a.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    KulaLevel       lvl   = ExportAll();
                    Stream          saver = File.Create(a.FileName);
                    BinaryFormatter serz  = new BinaryFormatter();
                    serz.Serialize(saver, lvl);
                    saver.Close();
                    saver.Dispose();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Sembrano esserci problemi nel salvataggio, infatti l'eccezione scaturita dice: \n" + e.ToString());
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Пример #4
0
 private bool LoadKulaLevel(KulaLevel lvl)
 {
     if (lvl == null)
     {
         return(false);
     }
     else
     {
         InitGrid(lvl);
         FillGrid(lvl);
         this.Invalidate();
         return(true);
     }
 }
Пример #5
0
        private bool RequestNewLevel()
        {
            string v  = "10";
            string v1 = "10";

            if (Interaction.DoubleTextInputBox("Insert the level size", "Width (2 - 100): ", "Height (2 - 100): ", ref v, ref v1) == DialogResult.OK)
            {
                byte w;
                byte h;
                try
                {
                    w = Byte.Parse(v);
                    h = Byte.Parse(v1);
                }
                catch (Exception e)
                {
                    e.ToString();
                    w = 0;
                    h = 0;
                }

                if ((w >= 2) && (h >= 2) && (w <= 100) && (h <= 100))
                {
                    KulaLevel l = new KulaLevel();
                    l.Width           = w;
                    l.Height          = h;
                    l.NextLevel       = "";
                    l.IsBonus         = false;
                    l.StartingSeconds = 60;
                    l.Theme           = "Egypt";
                    l.LossPenalty     = 100;

                    InitGrid(l);
                    FillGrid(l);
                    isLoaded = true;
                    this.Invalidate();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #6
0
 /// <summary>
 /// Carica il livello bonus indicato dal corrente LoadResourceItem, restituisce TRUE se e solo se il livello bonus è stato caricato
 /// correttamente. Il LoadResourceItem, se il caricamento ha avuto buon termine, elimina qualsiasi riferimento al livello bonus da caricare.
 /// Sarà quindi necessario reimpostare il LoadResourceItem prima di ricaricare un bonus.
 /// </summary>
 /// <returns></returns>
 public bool ProcessBonusLevel()
 {
     if (nextBonusToLoad != null)
     {
         ResourceInfo rInfo       = nextBonusToLoad;
         KulaLevel    lv          = InsertLevel(rInfo);
         string       neededTheme = lv.Theme;
         if (!root.ContainsDirectory(neededTheme))
         {
             LoadEntireTheme(neededTheme);
         }
         nextBonusToLoad = null;
         return(true);
     }
     return(false);
 }
Пример #7
0
 private bool load(string path)
 {
     try
     {
         Stream          loading = File.OpenRead(path);
         BinaryFormatter bf      = new BinaryFormatter();
         content = (KulaLevel)bf.Deserialize(loading);
         loading.Close();
         loading.Dispose();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine("Ci sono stati problemi nel caricare e processare il livello " + path + ":\n" + e.ToString());
         return(false);
     }
 }
Пример #8
0
 private void InitGrid(KulaLevel lvl)
 {
     this.lvlGrid    = new SortedDictionary <Pair <byte>, KulaLevel.MapTile>();
     lvlGrid         = new SortedDictionary <Pair <byte>, KulaLevel.MapTile>();
     isMouseDown     = false;
     TileToBeAdded   = null;
     isReadyToInsert = false;
     ChangePointer(new Pair <byte>(0, 0));
     isLoaded           = true;
     lvlH               = lvl.Height;
     lvlW               = lvl.Width;
     IsABonusLevel      = lvl.IsBonus;
     LvlStartingSeconds = lvl.StartingSeconds;
     LvlTheme           = lvl.Theme;
     LvlLossPenalty     = lvl.LossPenalty;
     LvlNextLevel       = lvl.NextLevel;
     Mode               = EditorMode.LvlPropMode;
 }
Пример #9
0
 /// <summary>
 /// Carica il livello indicato dal corrente LoadResourceItem, restituisce TRUE se e solo se il livello è stato caricato
 /// correttamente E il livello ha un successore. Il LoadResourceItem, se il caricamento ha avuto buon termine, si imposta automaticamente
 /// al livello successivo (se il livello successivo non esiste, sarà necessario reimpostare il LoadResourceItem).
 /// </summary>
 /// <returns></returns>
 public bool ProcessNormalLevel()
 {
     if (nextNormalToLoad != null)
     {
         ResourceInfo rInfo       = nextNormalToLoad;
         KulaLevel    lv          = InsertLevel(rInfo);
         string       neededTheme = lv.Theme;
         if (!root.ContainsDirectory(neededTheme))
         {
             LoadEntireTheme(neededTheme);
         }
         if (lv.NextLevel == "")
         {
             nextNormalToLoad = null;
             return(false);
         }
         SetNextNormalLevelToLoad(lv.NextLevel);
         return(true);
     }
     return(false);
 }
Пример #10
0
        private KulaLevel ExportAll()
        {
            KulaLevel res = new KulaLevel();

            res.IsBonus         = IsABonusLevel;
            res.Height          = LvlHeight;
            res.Width           = LvlWidth;
            res.StartingSeconds = LvlStartingSeconds;
            res.Theme           = LvlTheme;
            if (IsABonusLevel)
            {
                res.Theme = "Bonus";
            }
            res.LossPenalty = LvlLossPenalty;
            if (!IsABonusLevel)
            {
                res.NextLevel = LvlNextLevel;
            }
            foreach (Pair <byte> p in lvlGrid.Keys.ToList <Pair <byte> >())
            {
                KulaLevel.MapTile got;
                if (lvlGrid.TryGetValue(p, out got))
                {
                    if (got.TileType == KulaLevel.TileType.Block)
                    {
                        res.Blocks.Add((KulaLevel.Block)got);
                    }
                    else if (got.TileType == KulaLevel.TileType.Enemy)
                    {
                        res.Enemies.Add((KulaLevel.Enemy)got);
                    }
                    else
                    {
                        res.Placeables.Add((KulaLevel.Placeable)got);
                    }
                }
            }
            return(res);
        }
Пример #11
0
 /// <summary>
 /// Scarica il contenuto della risorsa
 /// </summary>
 public override void Unload()
 {
     content = null;
     GC.Collect();
 }
Пример #12
0
 /// <summary>
 /// Restituisce una risorsa che contiene un livello a partire da un path di un file.
 /// </summary>
 /// <param name="path">Path del file</param>
 public LevelResourceItem(string path)
 {
     content = null;
     Load(path);
 }