Skip to content
This repository was archived by the owner on Oct 19, 2025. It is now read-only.

Commit 5bc385f

Browse files
committed
version 2.1
1 parent eeb1720 commit 5bc385f

25 files changed

+583
-40
lines changed

Source/Compunet.SudokuSolver/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ResourceDictionary>
77
<ResourceDictionary.MergedDictionaries>
88
<ResourceDictionary Source="/Resources/Themes/LightTheme.xaml"/>
9-
<ResourceDictionary Source="/Resources/Languages/Hebrew.xaml"/>
9+
<ResourceDictionary Source="/Resources/Localization/StringResources.he.xaml"/>
1010
<ResourceDictionary Source="/Resources/Fonts.xaml"/>
1111
<ResourceDictionary Source="/Resources/Icons.xaml"/>
1212
<ResourceDictionary Source="/Resources/ToolTip.xaml"/>

Source/Compunet.SudokuSolver/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Compunet.SudokuSolver.Application;
22
using Compunet.SudokuSolver.Container;
33
using Compunet.SudokuSolver.Mvvm;
4+
using Compunet.SudokuSolver.Print;
45
using Compunet.SudokuSolver.Services;
56
using Microsoft.Extensions.DependencyInjection;
67
using System.Windows;
@@ -32,6 +33,7 @@ private IServiceCollection ConfigureServices(IServiceCollection services)
3233
.AddSingleton<ISudokuInputService, SudokuInputService>()
3334
.AddSingleton<IApplicationResourceManager, ApplicationResourceManager>()
3435
.AddSingleton<ICreatePuzzleDialogService, CreatePuzzleDialogService>()
36+
.AddSingleton<IPrintService, PrintService>()
3537
.AddSingleton<ISettingsService, SettingsService>()
3638
.AddSingleton<IExitService, ExitService>()
3739
;

Source/Compunet.SudokuSolver/AppWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<views:SudokuControl Margin="20"
3838
Width="500"
3939
Height="550"/>
40-
40+
4141
</Viewbox>
4242

4343
</Grid>

Source/Compunet.SudokuSolver/Application/ApplicationResourceManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ private void InitLanguages()
7373
{
7474
var he = new ResourceDictionary
7575
{
76-
Source = new Uri("/Resources/Languages/Hebrew.xaml", UriKind.RelativeOrAbsolute)
76+
Source = new Uri("/Resources/Localization/StringResources.he.xaml", UriKind.RelativeOrAbsolute)
7777
};
7878

7979
var en = new ResourceDictionary
8080
{
81-
Source = new Uri("/Resources/Languages/English.xaml", UriKind.RelativeOrAbsolute)
81+
Source = new Uri("/Resources/Localization/StringResources.en.xaml", UriKind.RelativeOrAbsolute)
8282
};
8383

8484
var en_lang = new ThemeApplicationResource(DefaultEnglishLanguage, ApplicationResourceCategory.LanguageAsset, new Lazy<ResourceDictionary>(en));
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using Compunet.Platform;
2+
using Compunet.SudokuSolver.Mvvm;
23

34
namespace Compunet.SudokuSolver.Controls
45
{
56
public abstract class BaseWindow : BasePlatformWindow
67
{
7-
8+
public BaseWindow()
9+
{
10+
DataContext = new WindowViewModel(this);
11+
}
812
}
913
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Data;
6+
using System.Windows.Media;
7+
8+
namespace Compunet.SudokuSolver.Controls
9+
{
10+
public static class BorderExtensions
11+
{
12+
public static readonly DependencyProperty ClipToCornerRadiusProperty =
13+
DependencyProperty.RegisterAttached("ClipToCornerRadius",
14+
typeof(bool),
15+
typeof(BorderExtensions),
16+
new PropertyMetadata(false, OnClipToCornerRadiusChanged));
17+
18+
private class ClipGeometrySelectorConverter : IMultiValueConverter
19+
{
20+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
21+
{
22+
double width = (double)values[0];
23+
double height = (double)values[1];
24+
double radius = ((CornerRadius)values[2]).TopLeft;
25+
26+
Size size = new(width, height);
27+
Rect rect = new(size);
28+
RectangleGeometry clip = new(rect, radius, radius);
29+
30+
return clip;
31+
}
32+
33+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
34+
{
35+
return Array.Empty<object>();
36+
}
37+
}
38+
39+
private static void OnClipToCornerRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
40+
{
41+
Border border = (Border)d;
42+
bool value = (bool)e.NewValue;
43+
44+
if (value == false)
45+
{
46+
border.SetValue(UIElement.ClipProperty, null);
47+
return;
48+
}
49+
50+
var binding = new MultiBinding();
51+
52+
binding.Bindings.Add(new Binding
53+
{
54+
Source = border,
55+
Path = new PropertyPath("ActualWidth")
56+
});
57+
58+
binding.Bindings.Add(new Binding
59+
{
60+
Source = border,
61+
Path = new PropertyPath("ActualHeight")
62+
});
63+
64+
binding.Bindings.Add(new Binding
65+
{
66+
Source = border,
67+
Path = new PropertyPath("CornerRadius")
68+
});
69+
70+
binding.Converter = new ClipGeometrySelectorConverter();
71+
border.SetBinding(UIElement.ClipProperty, binding);
72+
}
73+
74+
public static bool GetClipToCornerRadius(Border border)
75+
{
76+
return (bool)border.GetValue(ClipToCornerRadiusProperty);
77+
}
78+
79+
public static void SetClipToCornerRadius(Border border, bool value)
80+
{
81+
border.SetValue(ClipToCornerRadiusProperty, value);
82+
}
83+
}
84+
}

Source/Compunet.SudokuSolver/Controls/SudokuListBoxItem.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SudokuListBoxItem(Cell cell)
5656
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
5757
{
5858
Value value = (Value)e.NewValue;
59-
d.SetValue(ValueTextProperty, value.IsZero ? string.Empty : value.ToString());
59+
d.SetValue(ValueTextProperty, value.ToDisplayString());
6060
}
6161
}
6262
}

Source/Compunet.SudokuSolver/Core/.Board/BoardValidationExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static bool ColumnContains(this IBoard board, int columnindex, Value valu
3636
return false;
3737
}
3838

39-
public static bool SquareContains(this IBoard board, int sequreindex, Value value, Cell? ignore = null)
39+
public static bool BoxContains(this IBoard board, int sequreindex, Value value, Cell? ignore = null)
4040
{
4141
int r = sequreindex / 3 * 3;
4242
int c = sequreindex % 3 * 3;
@@ -62,7 +62,7 @@ public static bool CheckValue(this IBoard board, Cell position, Value value)
6262
{
6363
return !(board.RowContains(position.Row, value)
6464
|| board.ColumnContains(position.Column, value)
65-
|| board.SquareContains(position.Square, value));
65+
|| board.BoxContains(position.Box, value));
6666
}
6767

6868
public static IEnumerable<Cell> GetWarns(this IBoard state)
@@ -80,7 +80,7 @@ public static IEnumerable<Cell> GetWarns(this IBoard state)
8080
if (state.ColumnContains(cell.Column, value, cell))
8181
yield return cell;
8282

83-
if (state.SquareContains(cell.Square, value, cell))
83+
if (state.BoxContains(cell.Box, value, cell))
8484
yield return cell;
8585

8686
}

Source/Compunet.SudokuSolver/Core/.Board/SudokuBoardGenerator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ public static async Task<IBoard> GeneratePuzzleState(SudokuPuzzleLevel level)
3737

3838
var board = SudokuBoardCreator.CreateEditable(resolte);
3939

40-
int TakeRandomForRemove()
40+
int CreateRandomForRemove()
4141
{
4242
return level switch
4343
{
44-
SudokuPuzzleLevel.Easy => random.Next(3, 8),
45-
SudokuPuzzleLevel.Medium => random.Next(5, 9),
46-
SudokuPuzzleLevel.Hard => random.Next(6, 9),
44+
SudokuPuzzleLevel.Easy => random.Next(4, 6),
45+
SudokuPuzzleLevel.Medium => random.Next(5, 7),
46+
SudokuPuzzleLevel.Hard => random.Next(6, 8),
4747
_ => 0
4848
};
4949
}
5050

5151
var cells = Cell.AllRange.Shuffle();
5252

53-
foreach (var square in cells.GroupBy(c => c.Square))
53+
foreach (var square in cells.GroupBy(c => c.Box))
5454
{
55-
foreach (var cell in square.Take(TakeRandomForRemove()))
55+
foreach (var cell in square.Take(CreateRandomForRemove()))
5656
{
5757
board.SetValue(cell, Value.Zero);
5858
}

Source/Compunet.SudokuSolver/Core/.Structs/Cell.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ public struct Cell : IEquatable<Cell>
2020

2121
#endregion
2222

23-
//public static readonly Cell First = new(0);
24-
//public static readonly Cell Last = new(80);
25-
2623
public int Row => Index / 9;
2724
public int Column => Index % 9;
28-
public int Square => Column / 3 + (Row / 3 * 3);
25+
public int Box => Column / 3 + (Row / 3 * 3);
2926
public int Index { get; }
3027

3128
public bool IsFirst => Index == 0;
@@ -102,7 +99,7 @@ public override int GetHashCode()
10299

103100
public override string ToString()
104101
{
105-
return $"Row: {Row}, Column: {Column}, Square: {Square}";
102+
return $"Row: {Row}, Column: {Column}, Square: {Box}";
106103
}
107104

108105
#endregion

0 commit comments

Comments
 (0)