当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadInt16方法代码示例

本文整理汇总了C#中BinaryReader.ReadInt16方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadInt16方法的具体用法?C# BinaryReader.ReadInt16怎么用?C# BinaryReader.ReadInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadInt16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IDX

            /// <summary>
            ///     Parse an IDX file
            /// </summary>
            /// <param name="streamIdx">stream that contains IDX data</param>
            /// <param name="streamImg">stream that contains IMG data</param>
            public IDX(Stream streamIdx, Stream streamImg)
            {
                var reader = new BinaryReader(streamIdx);

                // First 4 bytes are the entries count
                filesCount = reader.ReadInt32();
                idx = new FileIdx[filesCount];

                // Parse IDX file
                for (int i = 0; i < filesCount; i++)
                {
                    idx[i].hash32 = reader.ReadInt32();
                    idx[i].hash16 = reader.ReadInt16();
                    idx[i].clength = reader.ReadInt16();
                    idx[i].position = reader.ReadInt32();
                    idx[i].length = reader.ReadInt32();

                    idx[i].compressed = (idx[i].clength & 0x4000) != 0;
                    idx[i].streamed = (idx[i].clength & 0x8000) != 0;
                    idx[i].clength = (idx[i].clength & 0x3FFF)*0x800 + 0x800;
                    idx[i].position *= 0x800;
                }

                // Get the stream of IMG
                this.streamImg = streamImg;
            }
开发者ID:Truthkey,项目名称:OpenKH,代码行数:31,代码来源:IDX.cs

示例2: Parse

    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseConvergePriorAttempt response = new ResponseConvergePriorAttempt();

        using (BinaryReader br = new BinaryReader(dataStream, Encoding.UTF8)) {
            int playerId = br.ReadInt32 ();
            int ecosystemId = br.ReadInt32 ();
            int attemptId = br.ReadInt32 ();
            bool allowHints = br.ReadBoolean ();
            int hintId = br.ReadInt32 ();
            short fldSize = br.ReadInt16 ();
            String config = System.Text.Encoding.UTF8.GetString (br.ReadBytes (fldSize));
            fldSize = br.ReadInt16 ();
            String csv = System.Text.Encoding.UTF8.GetString (br.ReadBytes (fldSize));

            ConvergeAttempt attempt = new ConvergeAttempt (playerId,
                                                           ecosystemId,
                                                           attemptId,
                                                           allowHints,
                                                           hintId,
                                                           config,
                                                           csv
                                                           //null
                                                           );

            response.attempt = attempt;
        }

        return response;
    }
开发者ID:hunvil,项目名称:ConvergeGame_Client,代码行数:30,代码来源:ConvergePriorAttemptProtocol.cs

示例3: using

    /*public static Texture2D LoadTGA(string fileName)
    {
        using (var imageFile = File.OpenRead(fileName))
        {
            return LoadTGA(imageFile);
        }
    }*/
    public static Texture2D LoadTGA(Stream TGAStream)
    {
        using (BinaryReader r = new BinaryReader(TGAStream))
        {
            // Skip some header info we don't care about.
            // Even if we did care, we have to move the stream seek point to the beginning,
            // as the previous method in the workflow left it at the end.
            r.BaseStream.Seek(12, SeekOrigin.Begin);

            short width = r.ReadInt16();
            short height = r.ReadInt16();
            int bitDepth = r.ReadByte();

            // Skip a byte of header information we don't care about.
            r.BaseStream.Seek(1, SeekOrigin.Current);

            Texture2D tex = new Texture2D(width, height);
            Color32[] pulledColors = new Color32[width * height];
            int length = width * height;

            if (bitDepth == 32)
            {
                for (int row = 1; row <= height; row++)
                {
                    for (int col = 0; col < width; col++)
                    {
                        byte red = r.ReadByte();
                        byte green = r.ReadByte();
                        byte blue = r.ReadByte();
                        byte alpha = r.ReadByte();

        //					pulledColors [i] = new Color32(blue, green, red, alpha);
                        pulledColors [length - (row * width) + col] = new Color32(blue, green, red, alpha);
                    }
                }
            } else if (bitDepth == 24)
            {
                for (int row = 1; row <= height; row++)
                {
                    for (int col = 0; col < width; col++)
                    {
                        byte red = r.ReadByte();
                        byte green = r.ReadByte();
                        byte blue = r.ReadByte();

                        pulledColors [length - (row * width) + col] = new Color32(blue, green, red, 1);
                    }
                }
            } else
            {
                throw new Exception("TGA texture had non 32/24 bit depth.");
            }

            tex.SetPixels32(pulledColors);
            tex.Apply();
            return tex;

        }
    }
开发者ID:cmdr2,项目名称:unity-obj-loader,代码行数:66,代码来源:TGALoader.cs

示例4: Packet

    // For Read
    public Packet(byte[] data)
    {
        m_stream = new MemoryStream(data);
        m_reader = new BinaryReader(m_stream);

        m_packetID = m_reader.ReadInt16();
        m_dataSize = m_reader.ReadInt16();
    }
开发者ID:westhyena,项目名称:gamepark,代码行数:9,代码来源:Packet.cs

示例5: SetExpertMode

 private static void SetExpertMode(string source, string dest, bool expertMode)
 {
     BinaryReader reader = new BinaryReader(new FileStream(source, FileMode.Open));
     int version = reader.ReadInt32();
     if (version < 149) {
         MessageBox.Show("Error: Outdated terraria version");
         return;
     }
     ulong magic = reader.ReadUInt64();
     if ((magic & 72057594037927935uL) != 27981915666277746uL) {
         MessageBox.Show("Error: Invalid header");
         return;
     }
     // Skip other file metadata...
     reader.ReadBytes(12);
     int positionCount = reader.ReadInt16();
     int afterMetadataPos = reader.ReadInt32();
     int afterHeaderPos = reader.ReadInt32();
     // Skip positions...
     reader.ReadBytes((positionCount - 2) * 4);
     // Skip frame importance...
     reader.ReadBytes(reader.ReadInt16() / 8 + 1);
     if (reader.BaseStream.Position != afterMetadataPos) {
         MessageBox.Show("After Metadata Position Mismatch: expected " +
             afterMetadataPos + ", was " + reader.BaseStream.Position);
         return;
     }
     // Skip the first part of the header...
     reader.ReadString();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     // Get the offset...
     long expertModeFlagOffset = reader.BaseStream.Position;
     bool wasExpertMode = reader.ReadBoolean();
     reader.Dispose();
     // Notify the user if the world is changed...
     if (wasExpertMode == expertMode) {
         MessageBox.Show(expertMode ? "World was already Expert Mode." : "World was already not Expert Mode.");
         return;
     }
     BinaryWriter writer = new BinaryWriter(new FileStream(dest, FileMode.Open));
     writer.BaseStream.Position = expertModeFlagOffset;
     writer.Write(expertMode);
     writer.Dispose();
     MessageBox.Show(expertMode ? "World is now Expert Mode!" : "World is no longer Expert Mode!");
 }
开发者ID:antag99,项目名称:TNoob,代码行数:51,代码来源:TNoob.cs

示例6: Load

    public static void Load(string Path)
    {
        if (!File.Exists(Configuration.GameResources + "\\" + Path + "\\" + "cache.bin"))
            throw new FileNotFoundException("Файл бэйсов не найден. Проверьте правильность пути.");

        BinReader = new BinaryReader(File.OpenRead(Configuration.GameResources + "\\" + Path + "\\" + "cache.bin"));

        if (BinReader.ReadInt16() != 500)
            throw new FileLoadException("Неверная сигнатура файла.");

        if (BinReader.ReadInt32() != BinReader.BaseStream.Length)
            throw new FileLoadException("В заголовке указан неверный размер файла.");

        BinReader.BaseStream.Seek(4, SeekOrigin.Current); // Константа - 01 00 00 00

        while (BinReader.BaseStream.Position < BinReader.BaseStream.Length)
        {
            long TmpPosition = BinReader.BaseStream.Position;

            if (BinReader.ReadInt16() != 1000)
                throw new FileLoadException("Неверная сигнатура бейса. " + BinReader.BaseStream.Position);

            int BlockSize = BinReader.ReadInt32();
            GameObject Base = GameObject.Find(new string(BinReader.ReadChars(BinReader.ReadInt32())));

            BinReader.BaseStream.Seek(0x4C, SeekOrigin.Current); // unknown

            while (BinReader.BaseStream.Position < (TmpPosition + BlockSize))
            {
                if (BinReader.ReadInt16() != 2000)
                    throw new FileLoadException("Неверная сигнатура объекта." + BinReader.BaseStream.Position);

                BinReader.BaseStream.Seek(4, SeekOrigin.Current);

                string ObjectName = new string(BinReader.ReadChars(BinReader.ReadInt32()))
                    .Replace(".I3D", "").Replace(".i3d", "");

                GameObject Object = ModelSceneLoader.Load("models" + "\\" + ObjectName);
                Object.transform.parent = Base.transform;

                Object.transform.position = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle()) * Configuration.ScaleFactor;
                Object.transform.rotation = new wxyz_s(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle()).ToQuat();
                Object.transform.localScale = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle());

                BinReader.BaseStream.Seek(16, SeekOrigin.Current); // unknown
            }
        }
    }
开发者ID:nkarpey,项目名称:Mafia-Resources-Loader,代码行数:48,代码来源:CacheBinLoader.cs

示例7: Load

    public void Load()
    {
        const string path = DIRECTORY + FILE_NAME;

        if (!Directory.Exists(DIRECTORY))
        {
            Directory.CreateDirectory(DIRECTORY);
        }

        if (File.Exists(path + ".sav"))
        {
            var reader = new BinaryReader(File.Open(path + ".sav", FileMode.Open));
            XmlHandler.locale = ( XmlHandler.Locale ) reader.ReadInt16();

            for(var i = 0; i < Application.levelCount; i++)
            {
                var data = new LevelSavedData
                               {
                                   levelId = i,
                                   highScore = reader.ReadInt32()
                               };

                _saveData.Add(i, data);
            }
        }
        else
        {
            SetupDefaultSaveFile();
            Save ();
        }
    }
开发者ID:Avatarchik,项目名称:Mind-Hero,代码行数:31,代码来源:SaveManager.cs

示例8: SkipExeSection

	public static void SkipExeSection(FileStream fs, BinaryReader br)
	{
		//skips over the exe section of an exe
		//skip dos stub
		fs.Seek(60, SeekOrigin.Begin);
		int e_lfanew = br.ReadInt32();
		//MessageBox.Show(e_lfanew.ToString());
		fs.Seek(e_lfanew + 4, SeekOrigin.Begin);
		//IMAGE_FILE_HEADER
		fs.Seek(2, SeekOrigin.Current);
		int NumberOfSections = br.ReadInt16();
		fs.Seek(16, SeekOrigin.Current);
		//end of IMAGE_FILE_HEADER
		//IMAGE_OPTIONAL_HEADER
		fs.Seek(224, SeekOrigin.Current);
		//end of IMAGE_OPTIONAL_HEADER
		//section directories
		int Size = 0; // size of section
		int Pos = 0;  // position of section
		for (int i=0; i<NumberOfSections; i++)
		{
			fs.Seek(16, SeekOrigin.Current);
			Size = br.ReadInt32();
			Pos = br.ReadInt32();
			fs.Seek(16, SeekOrigin.Current);
		}
		//end of section directories
		fs.Seek(Pos+Size, SeekOrigin.Begin);
	}
开发者ID:winch,项目名称:winch.pinkbile.com-c-sharp,代码行数:29,代码来源:proExe.cs

示例9: ReadField

    object ReadField(BinaryReader Reader, object Obj, FieldInfo Info)
    {
        //string name = Reader.ReadString();
        object value = null;

        if (Info.FieldType == typeof(System.String))
        {
            value = Reader.ReadString();
        }
        else if (Info.FieldType == typeof(System.Int16))
        {
            value = Reader.ReadInt16();
        }
        else if (Info.FieldType == typeof(System.Single))
        {
            value = Reader.ReadSingle();
        }
        else if (Info.FieldType == typeof(System.Int32))
        {
            value = Reader.ReadInt32();
        }
        else if(Info.FieldType == typeof(System.Enum) || Info.FieldType.BaseType == typeof(System.Enum))
        {
            value = Reader.ReadInt32();
        }

        return value;
    }
开发者ID:przemyslaw-szymanski,项目名称:dungeonworld,代码行数:28,代码来源:ItemSerializer.cs

示例10: Parse

    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseConvergeHint response = new ResponseConvergeHint();

        using (BinaryReader br = new BinaryReader(dataStream, Encoding.UTF8)) {
            int hintId = br.ReadInt32 ();
            short fldSize = br.ReadInt16 ();
            String text = System.Text.Encoding.UTF8.GetString (br.ReadBytes (fldSize));

            ConvergeHint hint = null;
            if (hintId != Constants.ID_NOT_SET) {
                hint = new ConvergeHint (hintId, text);
            }

            response.hint = hint;
        }

        return response;
    }
开发者ID:hunvil,项目名称:ConvergeGame_Client,代码行数:19,代码来源:ConvergeHintProtocol.cs

示例11: DecodeRSAPrivateKey

    private static RSACryptoServiceProvider DecodeRSAPrivateKey(byte[] privkey)
    {
        byte[] MODULUS, E, D, P, Q, DP, DQ, IQ;

            // ---------  Set up stream to decode the asn.1 encoded RSA private key  ------
            MemoryStream mem = new MemoryStream(privkey);
            BinaryReader binr = new BinaryReader(mem);    //wrap Memory Stream with BinaryReader for easy reading
            byte bt = 0;
            ushort twobytes = 0;
            int elems = 0;
            try
            {
                twobytes = binr.ReadUInt16();
                if (twobytes == 0x8130)	//data read as little endian order (actual data order for Sequence is 30 81)
                    binr.ReadByte();	//advance 1 byte
                else if (twobytes == 0x8230)
                    binr.ReadInt16();	//advance 2 bytes
                else
                    return null;

                twobytes = binr.ReadUInt16();
                if (twobytes != 0x0102)	//version number
                    return null;
                bt = binr.ReadByte();
                if (bt != 0x00)
                    return null;

                //------  all private key components are Integer sequences ----
                elems = GetIntegerSize(binr);
                MODULUS = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                E = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                D = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                P = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                Q = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                DP = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                DQ = binr.ReadBytes(elems);

                elems = GetIntegerSize(binr);
                IQ = binr.ReadBytes(elems);

                // ------- create RSACryptoServiceProvider instance and initialize with public key -----
                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
                RSAParameters RSAparams = new RSAParameters();
                RSAparams.Modulus = MODULUS;
                RSAparams.Exponent = E;
                RSAparams.D = D;
                RSAparams.P = P;
                RSAparams.Q = Q;
                RSAparams.DP = DP;
                RSAparams.DQ = DQ;
                RSAparams.InverseQ = IQ;
                RSA.ImportParameters(RSAparams);
                return RSA;
            }
            catch (Exception)
            {
                return null;
            }
            finally { binr.Close(); }
    }
开发者ID:cangjie,项目名称:lq_yeepay,代码行数:72,代码来源:RSA.cs

示例12: StreamTest

	private Boolean StreamTest(Stream stream, Boolean fSuppress){
		if(!fSuppress)
			Console.WriteLine("Testing " + stream.GetType() + " for read/write tests");
		String strValue;
		Int32 iValue;
		Int32 iLength = 1 << 10;
		stream.Seek(0, SeekOrigin.Begin);
		for(int i=0; i<iLength; i++)
			stream.WriteByte((Byte)i);
		Byte[] btArr = new Byte[iLength];
		for(int i=0; i<iLength; i++)
			btArr[i] = (Byte)i;
		stream.Write(btArr, 0, iLength);
		BinaryWriter bw1 = new BinaryWriter(stream);
		bw1.Write(false);
		bw1.Write(true);
		for(int i=0; i<10; i++){
			bw1.Write((Byte)i);
			bw1.Write((SByte)i);
			bw1.Write((Int16)i);
			bw1.Write((Char)i);
			bw1.Write((UInt16)i);
			bw1.Write(i);
			bw1.Write((UInt32)i);
			bw1.Write((Int64)i);
			bw1.Write((UInt64)i);
			bw1.Write((Single)i);
			bw1.Write((Double)i);
		}
		Char[] chArr = new Char[iLength];
		for(int i=0; i<iLength;i++)
			chArr[i] = (Char)i;
		bw1.Write(chArr);
		bw1.Write(chArr, 512, 512);
		bw1.Write(new String(chArr));
		bw1.Write(new String(chArr));
		stream.Seek(0, SeekOrigin.Begin);
		for(int i=0; i<iLength; i++){
			if(stream.ReadByte() != i%256){
                return false;
            }
		}
		btArr = new Byte[iLength];
		stream.Read(btArr, 0, iLength);
		for(int i=0; i<iLength; i++){
			if(btArr[i] != (Byte)i){
				Console.WriteLine(i + " "  + btArr[i] + " " + (Byte)i);
				return false;
			}
		}
		BinaryReader br1 = new BinaryReader(stream);
		if(br1.ReadBoolean())
			return false;
		if(!br1.ReadBoolean())
			return false;
		for(int i=0; i<10; i++){
			if(br1.ReadByte() != (Byte)i)
			return false;
			if(br1.ReadSByte() != (SByte)i)
			return false;
			if(br1.ReadInt16() != (Int16)i)
			return false;
			if(br1.ReadChar() != (Char)i)
			return false;
			if(br1.ReadUInt16() != (UInt16)i)
			return false;
			if(br1.ReadInt32() != i)
			return false;
			if(br1.ReadUInt32() != (UInt32)i)
			return false;
			if(br1.ReadInt64() != (Int64)i)
			return false;
			if(br1.ReadUInt64() != (UInt64)i)
			return false;
			if(br1.ReadSingle() != (Single)i)
			return false;
			if(br1.ReadDouble() != (Double)i)
			return false;
		}
		chArr = br1.ReadChars(iLength);
		for(int i=0; i<iLength;i++){
			if(chArr[i] != (Char)i)
			return false;
		}
		chArr = new Char[512];
		chArr = br1.ReadChars(iLength/2);
		for(int i=0; i<iLength/2;i++){
			if(chArr[i] != (Char)(iLength/2+i))
			return false;
		}
		chArr = new Char[iLength];
		for(int i=0; i<iLength;i++)
			chArr[i] = (Char)i;
		strValue = br1.ReadString();
		if(!strValue.Equals(new String(chArr)))
			return false;
		strValue = br1.ReadString();
		if(!strValue.Equals(new String(chArr))){
            return false;
        }
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co3965streammethods.cs

示例13: ItemInfo

    public ItemInfo(BinaryReader reader, int version = int.MaxValue, int Customversion = int.MaxValue)
    {
        Index = reader.ReadInt32();
        Name = reader.ReadString();
        Type = (ItemType) reader.ReadByte();
        if (version >= 40) Grade = (ItemGrade)reader.ReadByte();
        RequiredType = (RequiredType) reader.ReadByte();
        RequiredClass = (RequiredClass) reader.ReadByte();
        RequiredGender = (RequiredGender) reader.ReadByte();
        if(version >= 17) Set = (ItemSet)reader.ReadByte();

        Shape = version >= 30 ? reader.ReadInt16() : reader.ReadSByte();
        Weight = reader.ReadByte();
        Light = reader.ReadByte();
        RequiredAmount = reader.ReadByte();

        Image = reader.ReadUInt16();
        Durability = reader.ReadUInt16();

        StackSize = reader.ReadUInt32();
        Price = reader.ReadUInt32();

        MinAC = reader.ReadByte();
        MaxAC = reader.ReadByte();
        MinMAC = reader.ReadByte();
        MaxMAC = reader.ReadByte();
        MinDC = reader.ReadByte();
        MaxDC = reader.ReadByte();
        MinMC = reader.ReadByte();
        MaxMC = reader.ReadByte();
        MinSC = reader.ReadByte();
        MaxSC = reader.ReadByte();
        if (version < 25)
        {
            HP = reader.ReadByte();
            MP = reader.ReadByte();
        }
        else
        {
            HP = reader.ReadUInt16();
            MP = reader.ReadUInt16();
        }
        Accuracy = reader.ReadByte();
        Agility = reader.ReadByte();

        Luck = reader.ReadSByte();
        AttackSpeed = reader.ReadSByte();

        StartItem = reader.ReadBoolean();

        BagWeight = reader.ReadByte();
        HandWeight = reader.ReadByte();
        WearWeight = reader.ReadByte();

        if (version >= 9) Effect = reader.ReadByte();
        if (version >= 20)
        {
            Strong = reader.ReadByte();
            MagicResist = reader.ReadByte();
            PoisonResist = reader.ReadByte();
            HealthRecovery = reader.ReadByte();
            SpellRecovery = reader.ReadByte();
            PoisonRecovery = reader.ReadByte();
            HPrate = reader.ReadByte();
            MPrate = reader.ReadByte();
            CriticalRate = reader.ReadByte();
            CriticalDamage = reader.ReadByte();
            byte bools = reader.ReadByte();
            NeedIdentify = (bools & 0x01) == 0x01;
            ShowGroupPickup = (bools & 0x02) == 0x02;
            ClassBased = (bools & 0x04) == 0x04;
            LevelBased = (bools & 0x08) == 0x08;
            CanMine = (bools & 0x10) == 0x10;
            MaxAcRate = reader.ReadByte();
            MaxMacRate = reader.ReadByte();
            Holy = reader.ReadByte();
            Freezing = reader.ReadByte();
            PoisonAttack = reader.ReadByte();
            if (version < 55)
            {
                Bind = (BindMode)reader.ReadByte();
            }
            else
            {
                Bind = (BindMode)reader.ReadInt16();
            }
            
        }
        if (version >= 21)
        {
            Reflect = reader.ReadByte();
            HpDrainRate = reader.ReadByte();
            Unique = (SpecialItemMode)reader.ReadInt16();
        }
        if (version >= 24)
        {
            RandomStatsId = reader.ReadByte();
        }
        else
        {
//.........这里部分代码省略.........
开发者ID:thedeaths,项目名称:official-mir2c-,代码行数:101,代码来源:Common.cs

示例14: LoadLevel

    IEnumerator LoadLevel(string name)
    {
        GameObject[] gameobjects = GameObject.FindGameObjectsWithTag("CUBE");
        BLOCK.electrics = new List<GameObject>();
        int maxX = 0;
        int minX = 0;
        int maxY = 0;
        int minY = 0;
        int maxZ = 0;
        int minZ = 0;
        Debug.Log("Starting to load level");
        float start = Time.realtimeSinceStartup;
        WWW blockswww = new WWW(address + levelname + ".blocks");
        yield return blockswww;
        byte[] block = blockswww.bytes;
        WWW metawww = new WWW(address + levelname + ".meta");
        yield return metawww;
        byte[] meta = metawww.bytes;
        using (MemoryStream stream = new MemoryStream(block))
        {
            using (BinaryReader reader = new BinaryReader(stream))
            {
                using (MemoryStream metastream = new MemoryStream(meta))
                {
                    using (BinaryReader metareader = new BinaryReader(metastream))
                    {
                        maxX = reader.ReadInt16();
                        maxY = reader.ReadInt16();
                        maxZ = reader.ReadInt16();
                        minX = reader.ReadInt16();
                        minY = reader.ReadInt16();
                        minZ = reader.ReadInt16();

                        //int xlenght = maxX - minX;
                        //int ylenght = maxY - minY;
                        //int zlenght = maxZ - minZ;
                        int x = minX;
                        int y = minY;
                        int z = minZ;
                        int cnt = 0;
                        int total = 0;
                        foreach (GameObject obj in gameobjects)
                        {
                            Destroy(obj);
                        }
                        blocks = new List<BLOCK>();
                        while (stream.Position < stream.Length)
                        {
                            sbyte id = reader.ReadSByte();
                            int metadata = 0;
                            if (id >= 0)
                            {
                                cnt++;
                                total++;
                                if (GlobalSettings.UsesMetaData[id])
                                {
                                    try
                                    {
                                        metadata = metareader.ReadInt32();
                                    }
                                    catch { }
                                }
                                AddBlock(new Vector3(x, y, z), id, metadata);
                                z += 1;
                                if (z > maxZ)
                                {
                                    z = minZ;
                                    y += 1;
                                    if (y > maxY)
                                    {
                                        y = minY;
                                        x += 1;
                                        if (x > maxX)
                                            break;
                                    }
                                }
                            }
                            else
                            {
                                cnt += 1;
                                int amount = -id;
                                for (int i = 0; i < amount; i++)
                                {
                                    z += 1;
                                    if (z > maxZ)
                                    {
                                        int diff = maxZ - minZ;
                                        z = minZ;
                                        y += 1;
                                        if (y > maxY)
                                        {
                                            y = minY;
                                            x += 1;
                                            if (x > maxX)
                                                break;
                                        }
                                    }
                                }
                            }

//.........这里部分代码省略.........
开发者ID:raoz,项目名称:Ludum-Dare-24,代码行数:101,代码来源:Level.cs

示例15: ReadData

 public static void ReadData(Stream s) 
 {
     int				offset		= 5;
     byte[]			bytes		= new byte[256+offset];
     int				numBytes	= s.Read(bytes,offset,256);
     int				ret;
     int				read;
     BinaryReader	br;
     if(numBytes!=256)
         throw new Exception("When reading at an offset, expected 256 bytes back!  Got: "
             +numBytes+"  s.Position: "+s.Position+"  s.Length: "+s.Length);
     for(int i=0;i<256;i++)
         if (bytes[i+offset] != i)
             throw new Exception("Error at pos: "+(i+offset)+"  expected: "
                 +i+"  got: "+bytes[i+offset]);
     //	Test ReadByte methods
     read=s.ReadByte( );
     if(read!=0)
         throw new Exception("After calling ReadByte once, expected 0, but got: "+read);
     read=s.ReadByte( );
     if(read!=65)
         throw new Exception("After calling ReadByte twice, expected 65, but got: "+read);
     read=s.ReadByte( );
     if(read!=255)
         throw new Exception("After calling ReadByte thrice, expected 255, but got: "+read);
     br = new BinaryReader(s);
     for(int i=0;i<1000;i++) 
     {
         ret=br.ReadInt32( );
         if(ret!=i)
             Error("ReadInt32 failed, i="+i+"  read: "+ret);
     }
     if(br.ReadBoolean( ))
         throw new Exception("First call ReadBoolean( ) should have returned false!");
     if(!br.ReadBoolean( ))
         throw new Exception("Second call ReadBoolean( ) should have returned true!");
     for(char ch='A';ch<='Z';ch++)
         if(br.ReadChar( )!=ch)
             Error("ReadChar failed, ch="+ch);
     for(short i=-32000;i<=32000;i+=1000)
         if(br.ReadInt16( )!=i)
             Error("ReadInt16 failed, i="+i);
     for(int i=-2000000000;i<=2000000000;i+=100000000)
         if(br.ReadInt32( )!=i)
             Error("ReadInt32 failed, i="+i);
     if(br.ReadInt64( )!=0x0123456789ABCDE7L)
         Error("ReadInt64 forwards failed");
     if(br.ReadInt64( )!=0x7EDCBA9876543210L)
         Error("ReadInt64 backwards failed");
     if(!br.ReadString( ).Equals("Hello world"))
         Error("Read string failed");
     if(br.ReadDouble( )!=Math.PI)
         Error("ReadDouble for PI failed");
     if(br.ReadSingle( )!=(float)(-2.0*Math.PI))
         Error("ReadSingle for -2PI failed");
     s=br.BaseStream;
 }
开发者ID:ArildF,项目名称:masters,代码行数:57,代码来源:cs_iotest.cs


注:本文中的BinaryReader.ReadInt16方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。