Exemplo n.º 1
0
    public void Write(string fileName)
    {
        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
        {
            writer.Write(this.Id);
            writer.Write(this.Name); //length-prefixed with uint
            WorldVersion.Write(writer);
            GameVersion.Write(writer);
            writer.Write(this.AuthorId);

            writer.Write(this.DefaultCells.Count); //numberOfDefaultCells
            foreach (KeyValuePair <int, Cell> entry in this.DefaultCells)
            {
                writer.Write(entry.Key);
                entry.Value.Write(writer);
            }
            Dictionary <Cell, HashSet <Coordinates> > inverseMap = MapToInverse(this.Map);

            writer.Write(inverseMap.Count);
            foreach (KeyValuePair <Cell, HashSet <Coordinates> > entry in inverseMap)
            {
                entry.Key.Write(writer);
                writer.Write(entry.Value.Count);
                foreach (Coordinates coordinates in entry.Value)
                {
                    coordinates.Write(writer);
                }
            }
        }
    }
Exemplo n.º 2
0
    public bool Equals(World other)
    {
        bool eq = Id == other.Id &&
                  Name.Equals(other.Name) &&
                  WorldVersion.Equals(other.WorldVersion) &&
                  GameVersion.Equals(other.GameVersion) &&
                  AuthorId == other.AuthorId;

        if (eq)
        {
            foreach (KeyValuePair <int, Cell> entry in this.DefaultCells)
            {
                if (!(other.DefaultCells.ContainsKey(entry.Key) &&
                      other.DefaultCells[entry.Key].Equals(entry.Value)))
                {
                    Debug.Log("Default Cells " + entry);
                    return(false);
                }
            }
        }

        if (eq)
        {
            foreach (KeyValuePair <Coordinates, Cell> entry in this.Map)
            {
                if (!(other.Map.ContainsKey(entry.Key) &&
                      other.Map[entry.Key].Equals(entry.Value)))
                {
                    Debug.Log("Map " + entry);
                    return(false);
                }
            }
            return(true);
        }
        return(false);
    }