Some time ago, I fell in love with Sudoku, so I made one myself. It looked quite simple like MetroUI. As follows:
Supports custom backgrounds and shortcuts!
Because the self-knowledge algorithm is not very good, I used some small technologies when doing this!
Let's talk about the specific structure!
There are four small projects, from top to bottom:
Sudoku. CodeMonk (a Sudoku implemented by myself)
Sudoku. Common (Sudoku interface and other public classes)
Sudoku. Test (Test project)
Sudoku. WinForm (Sudoku for WinForm)
Of course, the most important thing is the ISudoku interface, which defines a series of data-independence operations, such as generating data-independence, opening and saving data-independence, and revoking repeated operations! The details are as follows:
View Code
Using System;
Using System. Collections. Generic;
Namespace Sudoku. Common
{
Public delegate void FinishHandler ();
/// <Summary>
/// Sudoku Interface
/// </Summary>
Public interface ISudoku: IDisposable
{
Event FinishHandler OnInitializeFinish;
Event FinishHandler OnLoadFinish;
/// <Summary>
/// Set the vertex
/// </Summary>
/// <Param name = "x"> x coordinate </param>
/// <Param name = "y"> y coordinate </param>
/// <Returns> point </returns>
Byte this [byte x, byte y] {get; set ;}
/// <Summary>
/// Load a Sudoku
/// </Summary>
/// <Param name = "path"> path </param>
Void Load (string path );
/// <Summary>
/// Save the sudoku
/// </Summary>
/// <Param name = "path"> path </param>
Void Save (string path );
/// <Summary>
/// Cancel
/// </Summary>
Void Undo ();
/// <Summary>
/// Repeated
/// </Summary>
Void Redo ();
/// <Summary>
/// Reset
/// </Summary>
Void Reset ();
/// <Summary>
/// Initialize the sudoku
/// </Summary>
Void Initialize ();
/// <Summary>
/// Obtain the data of a Sudoku
/// </Summary>
/// <Returns> </returns>
Byte [,] Current {get ;}
/// <Summary>
/// Original array
/// </Summary>
Byte [,] Original {get ;}
/// <Summary>
/// Level
/// </Summary>
Byte Level {get; set ;}
/// <Summary>
/// Whether the task is completed
/// </Summary>
Bool IsFinish {get ;}
/// <Summary>
/// Set or obtain the sudoku Solution
/// </Summary>
ISudokuSolution Solution {get; set ;}
/// <Summary>
/// Use the built-in solution to solve the current Sudoku
/// </Summary>
Void Solve ();
/// <Summary>
/// Check whether the point at this position can be placed
/// </Summary>
/// <Param name = "row"> line coordinate </param>
/// <Param name = "col"> column coordinate </param>
/// <Param name = "value"> value </param>
/// <Returns> true if it can be placed </returns>
Bool CanSet (byte row, byte col, byte value );
/// <Summary>
/// Obtain the set of values placed at this position
/// </Summary>
/// <Param name = "row"> line coordinate </param>
/// <Param name = "col"> column coordinate </param>
/// <Returns> set of placed values </returns>
List <byte> CanSetValues (byte row, byte col );
}
}
The ISudokuSolution in defines some methods for solving data independence:
View Code
Using System. Collections. Generic;
Namespace Sudoku. Common
{
/// <Summary>
/// Sudoku solution example
/// </Summary>
Public interface ISudokuSolution
{
/// <Summary>
/// Set or obtain the sudoku to be resolved
/// </Summary>
ISudoku Sudoku {get; set ;}
/// <Summary>
/// Solve the problem of sudoku
/// </Summary>
/// <Returns> solves the completed Sudoku </returns>
ISudoku Solve ();
/// <Summary>
/// Check whether the point at this position can be placed
/// </Summary>
/// <Param name = "row"> line coordinate </param>
/// <Param name = "col"> column coordinate </param>
/// <Param name = "value"> value </param>
/// <Returns> true if it can be placed </returns>
Bool CanSet (byte row, byte col, byte value );
/// <Summary>
/// Obtain the set of values placed at this position
/// </Summary>
/// <Param name = "row"> line coordinate </param>
/// <Param name = "col"> column coordinate </param>
/// <Returns> set of placed values </returns>
List <byte> CanSetValues (byte row, byte col );
}
}
For the sake of simplicity, there are also some common functions or instances that use the configuration file to generate a sudoku or Sudoku solution!
The implementation logic of Sudoku. CodeMonk code is clear, and the method of digging holes is used to generate Sudoku! No specific solution is provided. There is no Command mode for Undo and reuse of Stack, Which is troublesome. Xml serialization and deserialization are used to save and read data. Other methods are useless!
A complicated part can only be regarded as the GDI + operations and custom controls in the WinForm project.
To make the form look more Metro, I found some official Microsoft WP development icons. We also customized a PicButton, which is a bit of a small animation effect (small animation ).
The complexity is the custom SudokuLabel. For more information, see the code!
Release package download: sudoku-release.zip
Source code download: http://files.cnblogs.com/wushilonng/Sudoku.zip
Codeplex address: http://longsudoku.codeplex.com/
Others:
(1), delete the background.jpg under the directory to go back to the background, and put a background.jpg under the directory to be the background!
(2) Ctrl + Z undo, Ctrl + Y repeat, Ctrl + O open, Ctrl + S save, Ctrl + N New, Ctrl + H help answer, Ctrl + R reset!
(3) the number on the right is used to indicate the number that can be filled in the current grid.
(4) the so-called small animation is a slight rotation of the icon!
(5) The default difficulty is Level 1 (relatively mentally retarded), and no difficulty adjustment is made yet. You need to modify the code (encoding ).