public void UpdateFieldData(FieldData fieldData, LevelDescriptor descriptor) { if (!m_isUpdateFieldData) { throw new Exception("Call BeginUpdateFieldData() first"); } Clear(); Canvas.View.Scale = new Vector2(1f, 1f); this.m_scaleSideSize = this.m_sideSize; m_fieldData = fieldData; Descriptor = descriptor; PrepareCells(); FillCanvas(); m_fieldStatus.SetInitialStatus(Descriptor, ConnectedDisplaysCount, m_displaysCount); float borderX = Descriptor.Width * m_sideSize / 2; float borderY = Descriptor.Height * m_sideSize / 2; m_area.SetBorder(-borderX, -borderY, borderX, borderY); m_area.Stop(); m_area.Aligin(); m_startTime = DateTime.Now; m_rotationsCount = 0; }
public static FieldData GenerateFieldData(LevelDescriptor descriptor) { CellData[,] cells = new CellData[descriptor.Width, descriptor.Height]; for (int x = 0; x < cells.GetLength(0); x++) { for (int y = 0; y < cells.GetLength(1); y++) { cells[x, y] = new CellData(x, y); } } CellData sourceCell = cells[StaticRandom.Next(descriptor.Width), StaticRandom.Next(descriptor.Height)]; GenerateWires(cells, sourceCell, descriptor.Difficult); for (int x = 0; x < cells.GetLength(0); x++) { for (int y = 0; y < cells.GetLength(1); y++) { FinalizeCell(cells[x, y], sourceCell); } } return(new FieldData() { CellsData = cells }); }
public void SaveFieldData(FieldData fieldData, LevelDescriptor descriptor) { lock (descriptor) { using (var file = File.Create(GetFiedDataFileName(descriptor))) m_fieldDataSerializer.Serialize(file, fieldData); } }
public void DeleteFieldData(LevelDescriptor descriptor) { lock (descriptor) { var fileName = GetFiedDataFileName(descriptor); if (File.Exists(fileName)) { File.Delete(fileName); } } }
LevelDescriptor GenerateNextLevel() { if (m_widthQueue.Count == m_lastHeightIndex) { m_widthQueue.Clear(); m_lastHeightIndex = 0; m_lastDifficult = 0; while (m_widthQueue.Count == 0) { m_square = ((m_square < 0) ? startSquare : (m_square + 1)); int border = (int)Math.Ceiling(Math.Sqrt(m_square)) + 1; for (int i = 3; i <= border; i++) { if ((m_square % i) == 0) { int estWidth = i; int estHeight = (m_square / i); if (estWidth < estHeight) { continue; } int min = Math.Min(estWidth, estHeight); int max = Math.Max(estWidth, estHeight); if (min * 2 < max) { continue; } m_widthQueue.Add(i); } } } } int height = m_widthQueue[m_lastHeightIndex]; var descriptor = new LevelDescriptor(m_levelIndex, m_square / height, height, m_lastDifficult); m_lastDifficult++; if (m_lastDifficult == LevelDescriptor.DifficultsCount) { m_lastDifficult = 0; m_lastHeightIndex++; } return(descriptor); }
public FieldData GetFieldData(LevelDescriptor descriptor) { lock (descriptor) { var fileName = GetFiedDataFileName(descriptor); if (File.Exists(fileName)) { try { using (var file = File.OpenRead(fileName)) return((FieldData)m_fieldDataSerializer.Deserialize(file)); } catch //(Exception exception) { File.Delete(fileName); } } return(FieldGenerator.GenerateFieldData(descriptor)); } }
string GetFiedDataFileName(LevelDescriptor descriptor) { return(Path.Combine(this.m_profileDir, "level_" + (descriptor.Index + 1).ToString() + ".bin")); }