예제 #1
0
        /// <summary>
        /// Loads a hex from a byte array.
        /// </summary>
        /// <param name="bytes">The byte array</param>
        /// <param name="startIndex">The start of the data in the array</param>
        /// <returns>Returns the amount of bytes loaded</returns>
        public int FromBytes(byte[] bytes, int startIndex)
        {
            int count = 0;

            count += Position.FromBytes(bytes, startIndex + count);
            byte idCount = bytes[startIndex + count];

            count += 1;

            IDs = new List <byte>();
            for (byte i = 0; i < idCount; i++)
            {
                IDs.Add(bytes[startIndex + count]);
                count += 1;
            }

            return(count);
        }
예제 #2
0
        public int FromBytes(byte[] bytes, int startIndex)
        {
            int count = 0;

            try
            {
                Grid      = new HexGrid <Hex>();
                count    += Grid.FromBytes(bytes, startIndex + count);
                StartPos  = new HexPoint();
                count    += StartPos.FromBytes(bytes, startIndex + count);
                MinMoves  = BitConverter.ToInt32(bytes, startIndex + count);
                count    += 4;
                Completed = (bytes[startIndex + count] & (1 << 0)) > 0;
                Perfect   = (bytes[startIndex + count] & (1 << 1)) > 0;
                count    += 1;

                int hintLength = 0;
                count += hintLength.FromBytes(bytes, startIndex + count);
                Hint   = Encoding.UTF8.GetString(bytes, startIndex + count, hintLength);
                count += hintLength;

                // Read hex data
                int dataCount = BitConverter.ToInt32(bytes, startIndex + count);
                count += 4;

                Data = new HexData[dataCount];

                for (int i = 0; i < dataCount; i++)
                {
                    HexData hexData = new HexData();
                    count  += hexData.FromBytes(bytes, startIndex + count);
                    Data[i] = hexData;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Level]: Error while loading: {e.Message}");
            }

            return(count);
        }