private static HexData LoadFromFile(string path) { HexData data = new HexData(); if (File.Exists(path) && Path.GetExtension(path) == ".hex") { byte[] bytes = File.ReadAllBytes(path); data.FromBytes(bytes, 0); } return(data); }
public static void LoadData(string directory) { if (Directory.Exists(directory)) { string[] files = Directory.GetFiles(directory); StandardData = new HexData[files.Length]; for (int i = 0; i < files.Length; i++) { string file = files[i]; HexData hexData = LoadFromFile(file); StandardData[i] = hexData; } StandardData = StandardData.OrderBy(x => x.ID).ToArray(); } }
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); }