Exemple #1
0
        public SaveClass LoadGame(FileStream file)
        {
            StreamReader reader = new StreamReader(file);

            try
            {
                Game g = new Game();
                Dictionary <string, Texture> textures = new Dictionary <string, Texture>();

                // Number of textures
                int num = int.Parse(reader.ReadLine());

                // For each texture
                for (int i = 0; i < num; i++)
                {
                    string  key   = reader.ReadLine();
                    Texture value = StringToTexture(reader.ReadLine());

                    textures.Add(key, value);
                }

                // Number of rooms
                num = int.Parse(reader.ReadLine());

                // For each room
                for (int q = 0; q < num; q++)
                {
                    string name = reader.ReadLine();

                    int tile_x = int.Parse(reader.ReadLine());
                    int tile_y = int.Parse(reader.ReadLine());

                    Room r = new Room(name, tile_x, tile_y);

                    // For each tile
                    for (int j = 0; j < tile_y; j++)
                    {
                        for (int i = 0; i < tile_x; i++)
                        {
                            // For each layer
                            for (int f = 0; f < 2; f++)
                            {
                                string      sourceTexture = reader.ReadLine();
                                string      textureTypeS  = reader.ReadLine();
                                TextureType textureType;

                                switch (textureTypeS)
                                {
                                case "None":
                                    textureType = TextureType.None;
                                    break;

                                case "Base":
                                    textureType = TextureType.Base;
                                    break;

                                case "AutoTile":
                                    textureType = TextureType.AutoTile;
                                    break;

                                case "Wall":
                                    textureType = TextureType.Wall;
                                    break;

                                default:
                                    textureType = TextureType.None;
                                    break;
                                }

                                string        animationTypeS = reader.ReadLine();
                                AnimationType animationType;

                                switch (animationTypeS)
                                {
                                case "None":
                                    animationType = AnimationType.None;
                                    break;

                                case "AutoTile":
                                    animationType = AnimationType.AutoTile;
                                    break;

                                case "Waterfall":
                                    animationType = AnimationType.Waterfall;
                                    break;

                                default:
                                    animationType = AnimationType.None;
                                    break;
                                }

                                int startX = int.Parse(reader.ReadLine());
                                int startY = int.Parse(reader.ReadLine());
                                int sizeX  = int.Parse(reader.ReadLine());
                                int sizeY  = int.Parse(reader.ReadLine());

                                Rectangle[] rects = new Rectangle[4];
                                for (int h = 0; h < 4; h++)
                                {
                                    int rect_x      = int.Parse(reader.ReadLine());
                                    int rect_y      = int.Parse(reader.ReadLine());
                                    int rect_size_x = int.Parse(reader.ReadLine());
                                    int rect_size_y = int.Parse(reader.ReadLine());

                                    rects[h] = new Rectangle(rect_x, rect_y, rect_size_x, rect_size_y);
                                }

                                GameTexture gameTexture = new GameTexture(sourceTexture, textureType, startX, startY, sizeX, sizeY, rects);
                                r.Tiles[i, j].SetLayer(f, (GameTexture)(gameTexture.Clone()));
                            }
                        }
                    }

                    g.AddRoom(r);
                }

                reader.Close();
                reader.Dispose();

                SaveClass save = new SaveClass(g, textures);
                return(save);
            }
            catch (Exception e)
            {
                reader.Close();
                reader.Dispose();

                return(null);
            }
        }
Exemple #2
0
        public void SetLayer(int layer, GameTexture texture)
        {
            GameTexture t = (GameTexture)texture.Clone();

            this.layers[layer].GameTexture = t;
        }