private void Banzai3_Load(object sender, EventArgs e) { Localization.SetLocalName(this); foreach (var btn in toolStrip.Controls.OfType <ToolStripButton>()) { Localization.SetLocalName(btn); } var dir = Settings.Default.LastDir; var file = Settings.Default.LastFile; if (!string.IsNullOrWhiteSpace(dir) && !string.IsNullOrWhiteSpace(file)) { try { cross = CrossIO.Import(dir, file); } catch (Exception ex) { MessageBox.Show($"Error loading last save{Environment.NewLine}{ex}"); } } scaleSize = Settings.Default.LastScale; if (scaleSize > ScaleMax || scaleSize < ScaleMin) { scaleSize = ScaleStd; } UpdateSize(); UpdateBtnState(); cross.CheckLines(); panelScroll.MouseWheel += PanelCross_MouseWheel; }
private void btnUndo_Click(object sender, EventArgs e) { if (!editorMode || cross.IsHistoryUndo) { cross.HistoryUndo(); if (!editorMode) { cross.CheckLines(); } else { cross.CalcLines(); UpdateSize(); } UpdateBtnState(); panelCross.Invalidate(); } else if (editorMode && editorHistoryUndo.Any()) { cross = editorHistoryUndo.Pop(); cross.CalcLines(); UpdateSize(); UpdateBtnState(); panelCross.Invalidate(); } }
private void AddLines(int addLeft, int addRight, int addTop, int addDown) { editorHistoryUndo.Push(cross); cross = cross.CloneAdd(addLeft, addRight, addTop, addDown); cross.CalcLines(); UpdateSize(); UpdateBtnState(); panelCross.Invalidate(); }
public static void Export(string dir, string file, Cross cross) { var store = GetPathSolve(dir); if (!Directory.Exists(store)) Directory.CreateDirectory(store); var name = GetFileNameSolve(dir, file); using (var t = File.CreateText(name)) { cross.Export(t, true); } }
private void Banzai3_Load(object sender, EventArgs e) { var stdFileName = Application.LocalUserAppDataPath + DefaultSave; if (File.Exists(stdFileName)) { try { cross = new Cross(stdFileName); } catch(Exception ex) { MessageBox.Show("Error loading last Saved Game" + Environment.NewLine + ex.ToString()); } } }
private void Banzai3_Load(object sender, EventArgs e) { var stdFileName = Application.LocalUserAppDataPath + DefaultSave; if (File.Exists(stdFileName)) { try { cross = new Cross(stdFileName); } catch (Exception ex) { MessageBox.Show("Error loading last Saved Game" + Environment.NewLine + ex.ToString()); } } }
public Cross CloneAdd(int addLeft, int addRight, int addTop, int addDown) { var newCross = new Cross(TopSize + addLeft + addRight, LeftSize + addTop + addDown); CropCloneSide(Top, addLeft, newCross.Top); CropCloneSide(Left, addTop, newCross.Left); for (int i = 0; i < Top.Length; i++) { for (int j = 0; j < Left.Length; j++) { newCross.map[i + addLeft, j + addTop] = map[i, j]; } } return(newCross); }
public static void Export(string dir, string file, Cross cross) { var store = GetPathSolve(dir); if (!Directory.Exists(store)) { Directory.CreateDirectory(store); } var name = GetFileNameSolve(dir, file); using (var t = File.CreateText(name)) { cross.Export(t, true); } }
public static void ExportEditor(string file, Cross cross) { var store = GetPathEditor(); if (!Directory.Exists(store)) Directory.CreateDirectory(store); using (var t = File.CreateText(GetFileNameEditor(file, true))) { cross.Export(t, true); } using (var t = File.CreateText(GetFileNameEditor(file, false))) { cross.Export(t, false); } var solve = GetFileNameSolve(UserDirName, file); if (File.Exists(solve)) File.Delete(solve); }
private static Image CrossMakeIcon(Cross cross) { var topSize = cross.TopSize; var leftSize = cross.LeftSize; //TODO remove magic values : 179, 135 const int minScale = 2; const int maxScale = 8; var scale = Math.Min(179 / topSize, 135 / leftSize); scale = Math.Min(maxScale, Math.Max(minScale, scale)); var bmp = new Bitmap(topSize * scale + 1, leftSize * scale + 1); using (var g = Graphics.FromImage(bmp)) { for (int i = 0; i < topSize; i++) { for (int j = 0; j < leftSize; j++) { Brush brush; switch (cross.GetCell(i, j)) { case Cross.CellState.Fill: brush = Brushes.Black; break; case Cross.CellState.Unknown: brush = Brushes.LightGray; break; case Cross.CellState.Dot: brush = Brushes.White; break; default: throw new ArgumentOutOfRangeException(); } g.FillRectangle(brush, i * scale + 1, j * scale + 1, scale - 1, scale - 1); } } } return(bmp); }
private void btnCrop_Click(object sender, EventArgs e) { if (!editorMode) { return; } var newCross = cross.CloneCrop(); if (cross.LeftSize == newCross.LeftSize && cross.TopSize == newCross.TopSize) { return; } editorHistoryUndo.Push(cross); cross = newCross; cross.CalcLines(); UpdateSize(); UpdateBtnState(); panelCross.Invalidate(); }
public Cross CloneCrop() { if (Top.All(l => l.Empty)) { return(this); } var newTop = CropGetNewSize(Top); var newLeft = CropGetNewSize(Left); var newCross = new Cross(newTop.Len, newLeft.Len); CropCloneSide(Top, newTop, newCross.Top); CropCloneSide(Left, newLeft, newCross.Left); for (int i = 0; i < newTop.Len; i++) { for (int j = 0; j < newLeft.Len; j++) { newCross.map[i, j] = map[newTop.Min + i, newLeft.Min + j]; } } return(newCross); }
private static Image CrossMakeIcon(Cross cross) { var topSize = cross.TopSize; var leftSize = cross.LeftSize; //TODO remove magic values : 179, 135 const int minScale = 2; const int maxScale = 8; var scale = Math.Min(179/topSize, 135/leftSize); scale = Math.Min(maxScale, Math.Max(minScale, scale)); var bmp = new Bitmap(topSize*scale + 1, leftSize*scale + 1); using (var g = Graphics.FromImage(bmp)) { for (int i = 0; i < topSize; i++) for (int j = 0; j < leftSize; j++) { Brush brush; switch (cross.GetCell(i, j)) { case Cross.CellState.Fill: brush = Brushes.Black; break; case Cross.CellState.Unknown: brush = Brushes.LightGray; break; case Cross.CellState.Dot: brush = Brushes.White; break; default: throw new ArgumentOutOfRangeException(); } g.FillRectangle(brush, i*scale + 1, j*scale + 1, scale - 1, scale - 1); } } return bmp; }
public static void ExportEditor(string file, Cross cross) { var store = GetPathEditor(); if (!Directory.Exists(store)) { Directory.CreateDirectory(store); } using (var t = File.CreateText(GetFileNameEditor(file, true))) { cross.Export(t, true); } using (var t = File.CreateText(GetFileNameEditor(file, false))) { cross.Export(t, false); } var solve = GetFileNameSolve(UserDirName, file); if (File.Exists(solve)) { File.Delete(solve); } }
private void btnCrop_Click(object sender, EventArgs e) { if (!editorMode) return; var newCross = cross.CloneCrop(); if (cross.LeftSize == newCross.LeftSize && cross.TopSize == newCross.TopSize) return; editorHistoryUndo.Push(cross); cross = newCross; cross.CalcLines(); UpdateSize(); UpdateBtnState(); panelCross.Invalidate(); }
public Banzai3() { InitializeComponent(); cross = new Cross(10, 10); }
private void btnSelect_Click(object sender, EventArgs e) { if(!editorMode) SaveCurrent(); //TODO need cortage var newCross = CrossChoiceForm.SelectCross(Settings.Default.LastDir); if (newCross == null) return; switch (newCross.Length) { case 1: { var size = SelectSizeForm.GetSize(null); if (size == null) return; var newDir = newCross[0]; cross = new Cross(size.Value.Width, size.Value.Height); Settings.Default.LastDir = newDir; Settings.Default.LastFile = ""; Settings.Default.Save(); editorMode = true; break; } case 2: { var newDir = newCross[0]; var newFile = newCross[1]; try { cross = CrossIO.Import(newDir, newFile); } catch (Exception) { MessageBox.Show(Localization.GetLocalName("ERROR_IO")); } Settings.Default.LastDir = newDir; Settings.Default.LastFile = newFile; Settings.Default.Save(); editorMode = false; break; } case 3: { var newDir = newCross[0]; var newFile = newCross[1]; try { cross = CrossIO.ImportEditor(newFile); } catch (Exception) { MessageBox.Show(Localization.GetLocalName("ERROR_IO")); } Settings.Default.LastDir = newDir; Settings.Default.LastFile = newFile; Settings.Default.Save(); editorMode = true; break; } } UpdateSize(); UpdateBtnState(); cross.CheckLines(); panelCross.Invalidate(); }
public MainWindow() { InitializeComponent(); cross = new Cross(1, 1); }
private void PaintSectionLen(Graphics g, Rectangle pos, Cross.Section section) { if (section.State == Cross.SectionState.InProgress || editorMode) { g.DrawString(section.Len.ToString(), font, Brushes.Black, pos, textFormat); } else if (section.State == Cross.SectionState.Wrong) { g.DrawString(section.Len.ToString(), font, Brushes.Red, pos, textFormat); } else if (section.State == Cross.SectionState.Right) { g.DrawString(section.Len.ToString(), font, Brushes.Black, pos, textFormat); var curPen = //penMedium; (scaleSize > ScaleStd) ? penBold : (scaleSize > ScaleLow) ? penMedium : pen; g.DrawLine(curPen, pos.X, pos.Bottom, pos.Right, pos.Y); //g.DrawString(section.Len.ToString(), font, Brushes.DarkCyan, pos, textFormat); } else { throw new ArgumentOutOfRangeException(); } }
private void TestCheckLineVal(string sample, string len, string state) { var results = new Dictionary<Cross.SectionState, char> { {Cross.SectionState.Right, '+'}, {Cross.SectionState.Wrong, '-'}, {Cross.SectionState.InProgress, '?'} }; var source = new Dictionary<char, Cross.CellState> { {'#', Cross.CellState.Fill}, {'.', Cross.CellState.Dot}, {' ', Cross.CellState.Unknown} }; var cross = new Cross(sample.Length, 1); for (int i = 0; i < sample.Length; i++) { cross.SetCell(i, 0, source[sample[i]]); } cross.Left[0] = new Cross.Line(len.Split().Select(int.Parse)); cross.CheckLines(); var res = new string( cross.Left[0] .Sections .Select(s => results[s.State]) .ToArray()); if (res != state) throw new Exception($"[{sample}] [{len}] [{state}]{Environment.NewLine}==> Wrong [{res}]"); }
public void TestHistory() { var cross = new Cross(1, 2); cross.SetCell(0, 0, Cross.CellState.Fill); cross.SetCell(0, 1, Cross.CellState.Fill); cross.HistoryNextStep(); cross.SetCell(0, 0, Cross.CellState.Dot); cross.SetCell(0, 1, Cross.CellState.Dot); cross.HistoryNextStep(); cross.SetCell(0, 0, Cross.CellState.Unknown); cross.SetCell(0, 1, Cross.CellState.Unknown); cross.HistoryNextStep(); if (cross.GetCell(0, 0) != Cross.CellState.Unknown || cross.GetCell(0, 1) != Cross.CellState.Unknown) throw new Exception(); cross.HistoryUndo(); if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot) throw new Exception(); cross.HistoryUndo(); if (cross.GetCell(0, 0) != Cross.CellState.Fill || cross.GetCell(0, 1) != Cross.CellState.Fill) throw new Exception(); cross.HistoryUndo(); if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot) throw new Exception(); cross.HistoryUndo(); if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot) throw new Exception(); cross.HistoryRedo(); if (cross.GetCell(0, 0) != Cross.CellState.Fill || cross.GetCell(0, 1) != Cross.CellState.Fill) throw new Exception(); cross.HistoryRedo(); if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot) throw new Exception(); cross.HistoryRedo(); if (cross.GetCell(0, 0) != Cross.CellState.Unknown || cross.GetCell(0, 1) != Cross.CellState.Unknown) throw new Exception(); }
public void TestLoadSave() { var tmpFolder = "Users.0000"; var tmpName = "Test1"; var exts = new[] {"banzai", "editor", "solve"}; var cross = new Cross(10, 10); cross.SetCell(0, 0, Cross.CellState.Fill); CrossIO.ExportEditor(tmpName, cross); var cross0 = CrossIO.Import(tmpFolder, tmpName); if (cross0.GetCell(0, 0) != Cross.CellState.Unknown) throw new Exception(); CrossIO.Export(tmpFolder, tmpName, cross); var cross1 = CrossIO.Import(tmpFolder, tmpName); if (cross1.GetCell(0, 0) != Cross.CellState.Fill) throw new Exception(); var dir = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\{Application.CompanyName}\{ Application.ProductName}\{tmpFolder}\"; Array.ForEach(exts, e => File.Delete(dir + tmpName + '.' + e)); if (!Directory.EnumerateFiles(dir).Any()) Directory.Delete(dir); }
private void Banzai3_Load(object sender, EventArgs e) { Localization.SetLocalName(this); foreach (var btn in toolStrip.Controls.OfType<ToolStripButton>()) { Localization.SetLocalName(btn); } var dir = Settings.Default.LastDir; var file = Settings.Default.LastFile; if (!string.IsNullOrWhiteSpace(dir) && !string.IsNullOrWhiteSpace(file)) { try { cross = CrossIO.Import(dir, file); } catch (Exception ex) { MessageBox.Show($"Error loading last save{Environment.NewLine}{ex}"); } } scaleSize = Settings.Default.LastScale; if (scaleSize > ScaleMax || scaleSize < ScaleMin) scaleSize = ScaleStd; UpdateSize(); UpdateBtnState(); cross.CheckLines(); panelScroll.MouseWheel += PanelCross_MouseWheel; }
public Cross CloneCrop() { if (Top.All(l => l.Empty)) return this; var newTop = CropGetNewSize(Top); var newLeft = CropGetNewSize(Left); var newCross = new Cross(newTop.Len, newLeft.Len); CropCloneSide(Top, newTop, newCross.Top); CropCloneSide(Left, newLeft, newCross.Left); for (int i = 0; i < newTop.Len; i++) for (int j = 0; j < newLeft.Len; j++) newCross.map[i, j] = map[newTop.Min + i, newLeft.Min + j]; return newCross; }
public Cross CloneAdd(int addLeft, int addRight, int addTop, int addDown) { var newCross = new Cross(TopSize + addLeft + addRight, LeftSize + addTop + addDown); CropCloneSide(Top, addLeft, newCross.Top); CropCloneSide(Left, addTop, newCross.Left); for (int i = 0; i < Top.Length; i++) for (int j = 0; j < Left.Length; j++) newCross.map[i + addLeft, j + addTop] = map[i, j]; return newCross; }
private void btnSelect_Click(object sender, EventArgs e) { if (!editorMode) { SaveCurrent(); } //TODO need cortage var newCross = CrossChoiceForm.SelectCross(Settings.Default.LastDir); if (newCross == null) { return; } switch (newCross.Length) { case 1: { var size = SelectSizeForm.GetSize(null); if (size == null) { return; } var newDir = newCross[0]; cross = new Cross(size.Value.Width, size.Value.Height); Settings.Default.LastDir = newDir; Settings.Default.LastFile = ""; Settings.Default.Save(); editorMode = true; break; } case 2: { var newDir = newCross[0]; var newFile = newCross[1]; try { cross = CrossIO.Import(newDir, newFile); } catch (Exception) { MessageBox.Show(Localization.GetLocalName("ERROR_IO")); } Settings.Default.LastDir = newDir; Settings.Default.LastFile = newFile; Settings.Default.Save(); editorMode = false; break; } case 3: { var newDir = newCross[0]; var newFile = newCross[1]; try { cross = CrossIO.ImportEditor(newFile); } catch (Exception) { MessageBox.Show(Localization.GetLocalName("ERROR_IO")); } Settings.Default.LastDir = newDir; Settings.Default.LastFile = newFile; Settings.Default.Save(); editorMode = true; break; } } UpdateSize(); UpdateBtnState(); cross.CheckLines(); panelCross.Invalidate(); }