Ejemplo n.º 1
0
        public void LoadFromFile()
        {
            this.BackgroundImage = Zamki.Properties.Resources.grass;
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream("save.bin", FileMode.OpenOrCreate))
            {
                List <GameElements.Stuff>          stuff = (List <GameElements.Stuff>)formatter.Deserialize(fs);
                GameElements.Stuff.BeautifulSquare z     = new GameElements.Stuff.BeautifulSquare(0, 0, 0, 0, picInvisible);
                GameElements.Stuff.ScenicObject    y     = new GameElements.Stuff.ScenicObject(0, 0, true, 0, 0, picInvisible);
                GameElements.Stuff.Player          x     = new GameElements.Stuff.Player(25, 200, picPlayer);
                GameElements.Stuff.GameProgress    w     = new GameElements.Stuff.GameProgress();

                foreach (GameElements.Stuff s in stuff)
                {
                    if (Object.ReferenceEquals(s.GetType(), z.GetType()))
                    {
                        object zs = s;
                        GameElements.Stuff.BeautifulSquare sz = (GameElements.Stuff.BeautifulSquare)zs;
                        allRooms.Add(sz);
                    }
                    else
                    if (Object.ReferenceEquals(s.GetType(), y.GetType()))
                    {
                        object ys = s;
                        GameElements.Stuff.ScenicObject sy = (GameElements.Stuff.ScenicObject)ys;
                        if (sy.noclip)
                        {
                            allDoors.Add(sy);
                        }
                        allObjects.Add(sy);
                    }
                    else
                    if (Object.ReferenceEquals(s.GetType(), x.GetType()))
                    {
                        object xs = s;
                        GameElements.Stuff.Player sx = (GameElements.Stuff.Player)xs;
                        hero = sx;
                    }
                    else
                    if (Object.ReferenceEquals(s.GetType(), w.GetType()))
                    {
                        object ws = s;
                        GameElements.Stuff.GameProgress sw = (GameElements.Stuff.GameProgress)ws;
                        allGP.Add(sw);
                    }
                }
            }
            currentRoom         = new GameElements.Stuff.BeautifulSquare(0, 0, 0, 0, null);
            previousRoom        = new GameElements.Stuff.BeautifulSquare(0, 0, 0, 0, null);
            picNextPage.Visible = false;

            hideMenuButtons();
            Invalidate();
        }
Ejemplo n.º 2
0
        public static void generateLevel(List <GameElements.Stuff.ScenicObject> allDoors, List <GameElements.Stuff.ScenicObject> allObjects, List <GameElements.Stuff.BeautifulSquare> allRooms, GameElements.Stuff.Player hero)
        {
            Random rnd = new Random();
            int    r   = rnd.Next(5);
            string stream;

            switch (r)
            {
            case 0:
            {
                stream = Path.GetFullPath(System.Windows.Forms.Application.StartupPath + @"\\Levels\\level0.bin");
                break;
            }

            case 1:
            {
                stream = Path.GetFullPath(System.Windows.Forms.Application.StartupPath + @".\\Levels\\level1.bin");
                break;
            }

            case 2:
            {
                stream = Path.GetFullPath(System.Windows.Forms.Application.StartupPath + @".\\Levels\\level2.bin");
                break;
            }

            case 3:
            {
                stream = Path.GetFullPath(System.Windows.Forms.Application.StartupPath + @".\\Levels\\level3.bin");
                break;
            }

            case 4:
            {
                stream = Path.GetFullPath(System.Windows.Forms.Application.StartupPath + @".\\Levels\\level4.bin");
                break;
            }

            default:
            {
                stream = Path.GetFullPath(System.Windows.Forms.Application.StartupPath + @".\\Levels\\level0.bin");
                break;
            }
            }
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream(stream, FileMode.OpenOrCreate))
            {
                List <GameElements.Stuff>          stuff = (List <GameElements.Stuff>)formatter.Deserialize(fs);
                GameElements.Stuff.BeautifulSquare z     = new GameElements.Stuff.BeautifulSquare(0, 0, 0, 0, Zamki.Properties.Resources.invisible);
                GameElements.Stuff.ScenicObject    y     = new GameElements.Stuff.ScenicObject(0, 0, true, 0, 0, Zamki.Properties.Resources.invisible);
                GameElements.Stuff.Player          x     = new GameElements.Stuff.Player(25, 200, Zamki.Properties.Resources.hero);

                foreach (GameElements.Stuff s in stuff)
                {
                    if (Object.ReferenceEquals(s.GetType(), z.GetType()))
                    {
                        object zs = s;
                        GameElements.Stuff.BeautifulSquare sz = (GameElements.Stuff.BeautifulSquare)zs;
                        allRooms.Add(sz);
                    }
                    else
                    if (Object.ReferenceEquals(s.GetType(), y.GetType()))
                    {
                        object ys = s;
                        GameElements.Stuff.ScenicObject sy = (GameElements.Stuff.ScenicObject)ys;
                        if (sy.noclip)
                        {
                            allDoors.Add(sy);
                        }
                        else
                        {
                            allObjects.Add(sy);
                        }
                    }
                    //else
                    //    if (Object.ReferenceEquals(s.GetType(), x.GetType()))
                    //    {
                    //        object xs = s;
                    //        GameElements.Stuff.Player sx = (GameElements.Stuff.Player)xs;
                    //        if (sx.posX == 999)
                    //        {
                    //            sx.posX = 25;
                    //            sx.posY = 25;
                    //        }
                    //        hero = sx;
                    //    }
                }
            }
        }