Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
UziTech committed Oct 26, 2018
1 parent 995cf85 commit 9268c19
Showing 4 changed files with 523 additions and 826 deletions.
206 changes: 84 additions & 122 deletions About.cs
Original file line number Diff line number Diff line change
@@ -4,13 +4,11 @@
using System.ComponentModel;
using System.Windows.Forms;

namespace Sudoku
{
namespace Sudoku {
/// <summary>
/// Summary description for About.
/// </summary>
public class About : System.Windows.Forms.Form
{
public class About : System.Windows.Forms.Form {
#region private stuff

private System.Windows.Forms.Button btnOK;
@@ -20,8 +18,7 @@ public class About : System.Windows.Forms.Form
private System.ComponentModel.Container components = null;
#endregion
#region public About()
public About()
{
public About() {
//
// Required for Windows Form Designer support
//
@@ -35,115 +32,101 @@ public About()
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
protected override void Dispose(bool disposing) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
base.Dispose(disposing);
}
#endregion
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(About));
this.btnOK = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.BackColor = System.Drawing.Color.Black;
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnOK.ForeColor = System.Drawing.Color.LightGreen;
this.btnOK.Location = new System.Drawing.Point(43, 133);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 3;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = false;
//
// About
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Gold;
this.ClientSize = new System.Drawing.Size(162, 162);
this.Controls.Add(this.btnOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "About";
this.ShowInTaskbar = false;
this.Text = "Sudoku v4.1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.About_Paint);
this.ResumeLayout(false);
private void InitializeComponent() {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(About));
this.btnOK = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.BackColor = System.Drawing.Color.Black;
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnOK.ForeColor = System.Drawing.Color.LightGreen;
this.btnOK.Location = new System.Drawing.Point(43, 133);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 3;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = false;
//
// About
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Gold;
this.ClientSize = new System.Drawing.Size(162, 162);
this.Controls.Add(this.btnOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "About";
this.ShowInTaskbar = false;
this.Text = "Sudoku v4.1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.About_Paint);
this.ResumeLayout(false);

}
#endregion
#region Global Variables
int count = 0;
int _left = 28;
int _top = 35;
int[,] _grid = new int[9,9];
int[,] _grid = new int[9, 9];
SudokuGrid grid = new SudokuGrid();
int [,,] gridHints = new int[9,9,9];
int[,,] gridHints = new int[9, 9, 9];
Pen _penThick = new Pen(Color.Black, 3);
Rectangle[,] _boardArray = new Rectangle[9,9];
Rectangle[,] _boardArray = new Rectangle[9, 9];
Font _sudukoFont = new Font("Arial", 10, FontStyle.Regular);
Font _hintsFont = new Font("Small Fonts", 4);
Rectangle _board = new Rectangle(0,0, 0, 0);
Rectangle _board = new Rectangle(0, 0, 0, 0);
#endregion
#region void DrawSudokuGrid(Graphics g)
void DrawSudokuGrid(Graphics g)
{
if (count == 0)
{
void DrawSudokuGrid(Graphics g) {
if (count == 0) {
_grid = grid.GenerateGrid();
int r = 0;
for (int row = 0; row < 5; row += 2)
{
for (int col = 0; col < 4; col += 2)
{
for (int row = 0; row < 5; row += 2) {
for (int col = 0; col < 4; col += 2) {
if (r == 0)
r = new Random().Next();
if (r % 2 == 1)
_grid[row, col] = 0;
r /= 2;
}
}
for (int row = 1; row < 5; row += 2)
{
for (int col = 1; col < 4; col += 2)
{
for (int row = 1; row < 5; row += 2) {
for (int col = 1; col < 4; col += 2) {
if (r == 0)
r = new Random().Next();
if (r % 2 == 1)
_grid[row, col] = 0;
r /= 2;
}
}
for (int row = 0; row < 5; row += 2)
{
for (int col = 1; col < 4; col += 2)
{
for (int row = 0; row < 5; row += 2) {
for (int col = 1; col < 4; col += 2) {
if (r == 0)
r = new Random().Next();
if (r % 2 == 1)
_grid[row, col] = 0;
r /= 2;
}
}
for (int row = 1; row < 5; row += 2)
{
for (int col = 0; col < 4; col += 2)
{
for (int row = 1; row < 5; row += 2) {
for (int col = 0; col < 4; col += 2) {
if (r == 0)
r = new Random().Next();
if (r % 2 == 1)
@@ -153,12 +136,9 @@ void DrawSudokuGrid(Graphics g)
}
if (r % 2 == 0)
_grid[4, 4] = 0;
for (int row = 0; row < 5; row++)
{
for (int col = 0; col < 4; col++)
{
if (_grid[row, col] == 0)
{
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 4; col++) {
if (_grid[row, col] == 0) {
_grid[8 - row, 8 - col] = 0;
_grid[8 - col, row] = 0;
_grid[col, 8 - row] = 0;
@@ -171,14 +151,12 @@ void DrawSudokuGrid(Graphics g)
// draw square
g.DrawRectangle(_penThick, _board);

int spacingX = _board.Width/9;
int spacingY = _board.Height/9;
int spacingX = _board.Width / 9;
int spacingY = _board.Height / 9;

for (int col = 0; col < 9; col++)
{
for (int row = 0; row < 9; row++)
{
_boardArray[row, col] = new Rectangle(_board.Left + col*spacingX, _board.Top + row*spacingY, spacingX, spacingY);
for (int col = 0; col < 9; col++) {
for (int row = 0; row < 9; row++) {
_boardArray[row, col] = new Rectangle(_board.Left + col * spacingX, _board.Top + row * spacingY, spacingX, spacingY);
}
}
g.FillRectangle(Brushes.Yellow, _boardArray[0, 3]);
@@ -234,81 +212,65 @@ void DrawSudokuGrid(Graphics g)
g.FillRectangle(Brushes.Yellow, _boardArray[8, 7]);
g.FillRectangle(Brushes.Yellow, _boardArray[8, 8]);

for (int i = 0; i < 10; i++)
{
if (i % 3 == 0)
{
g.DrawLine(_penThick, _board.Left, _board.Top + spacingY * i, _board.Right, _board.Top + spacingY*i);
for (int i = 0; i < 10; i++) {
if (i % 3 == 0) {
g.DrawLine(_penThick, _board.Left, _board.Top + spacingY * i, _board.Right, _board.Top + spacingY * i);
g.DrawLine(_penThick, _board.Left + spacingX * i, _board.Top, _board.Left + spacingX * i, _board.Bottom);
}
else
{
g.DrawLine(Pens.Black, _board.Left, _board.Top + spacingY * i, _board.Right, _board.Top + spacingY*i);
} else {
g.DrawLine(Pens.Black, _board.Left, _board.Top + spacingY * i, _board.Right, _board.Top + spacingY * i);
g.DrawLine(Pens.Black, _board.Left + spacingX * i, _board.Top, _board.Left + spacingX * i, _board.Bottom);
}
}

for (int col = 0; col < 9; col++)
{
for (int row = 0; row < 9; row++)
{
for (int col = 0; col < 9; col++) {
for (int row = 0; row < 9; row++) {
int val = _grid[row, col];

if (val != 0)
{
g.DrawString(val.ToString(), _sudukoFont, Brushes.Black, _board.Left + col*spacingX + 4, _board.Top + row*spacingY + 1, new StringFormat());
}
else
{
if (val != 0) {
g.DrawString(val.ToString(), _sudukoFont, Brushes.Black, _board.Left + col * spacingX + 4, _board.Top + row * spacingY + 1, new StringFormat());
} else {
DrawGridHints(g, row, col);
}
}
}
}
}
#endregion
#region void DrawGridHints(Graphics g, int row, int col)
void DrawGridHints(Graphics g, int row, int col)
{
int spacingX = _board.Width/9;
int spacingY = _board.Height/9;
void DrawGridHints(Graphics g, int row, int col) {
int spacingX = _board.Width / 9;
int spacingY = _board.Height / 9;
int length;
string hints = "";
string hintss = "";
string hintsss = "";
for (int i = 0; i < 9; i++)
{
for (int i = 0; i < 9; i++) {
if (gridHints[row, col, i] != 0)
hints = hints + gridHints[row, col, i].ToString() + ",";
}

if (hints.Length > 0)
{
hints = hints.Remove(hints.Length - 1, 1);
if (hints.Length > 0) {
hints = hints.Remove(hints.Length - 1, 1);
}
System.Drawing.Brush brush = Brushes.Maroon;
if (hints.Length == 1)
{
if (hints.Length == 1) {
brush = Brushes.Blue;
}
if (hints.Length > 8)
{
if (hints.Length > 8) {
length = hints.Length - 8;
hintss = hints.Remove(0, 8);
hints = hints.Remove(8, length);
if (hintss.Length > 8)
{
if (hintss.Length > 8) {
hintsss = hintss.Remove(0, 8);
hintss = hintss.Remove(8, 1);
g.DrawString(hintsss.ToString(), _hintsFont, brush, _board.Left + col*spacingX + 1, _board.Top + row*spacingY + 14, new StringFormat());
g.DrawString(hintsss.ToString(), _hintsFont, brush, _board.Left + col * spacingX + 1, _board.Top + row * spacingY + 14, new StringFormat());
}
g.DrawString(hintss.ToString(), _hintsFont, brush, _board.Left + col*spacingX + 1, _board.Top + row*spacingY + 8, new StringFormat());
g.DrawString(hintss.ToString(), _hintsFont, brush, _board.Left + col * spacingX + 1, _board.Top + row * spacingY + 8, new StringFormat());
}
g.DrawString(hints.ToString(), _hintsFont, brush, _board.Left + col*spacingX + 1, _board.Top + row*spacingY + 2, new StringFormat());
g.DrawString(hints.ToString(), _hintsFont, brush, _board.Left + col * spacingX + 1, _board.Top + row * spacingY + 2, new StringFormat());
}
#endregion
#region private void About_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
private void About_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
private void About_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
String S1 = "by Tony Brix";
String S2 = "[email protected]";
String S3 = "Special Thanks to";
195 changes: 94 additions & 101 deletions HowToPlay.cs
Original file line number Diff line number Diff line change
@@ -4,13 +4,11 @@
using System.ComponentModel;
using System.Windows.Forms;

namespace Sudoku
{
namespace Sudoku {
/// <summary>
/// Summary description for HowToPlay.
/// </summary>
public class HowToPlay : System.Windows.Forms.Form
{
public class HowToPlay : System.Windows.Forms.Form {
#region private stuff
private System.Windows.Forms.Label HowTo;
private System.Windows.Forms.Label KeysHowTo;
@@ -24,8 +22,7 @@ public class HowToPlay : System.Windows.Forms.Form
private System.ComponentModel.Container components = null;
#endregion
#region public HowToPlay()
public HowToPlay()
{
public HowToPlay() {
//
// Required for Windows Form Designer support
//
@@ -40,111 +37,107 @@ public HowToPlay()
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
protected override void Dispose(bool disposing) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
base.Dispose(disposing);
}
#endregion
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(HowToPlay));
this.HowTo = new System.Windows.Forms.Label();
this.KeysHowTo = new System.Windows.Forms.Label();
this.HLColorHowTo = new System.Windows.Forms.Label();
this.HighLightColorHowTo = new System.Windows.Forms.Label();
this.OkBtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// HowTo
//
this.HowTo.ForeColor = System.Drawing.Color.Red;
this.HowTo.Location = new System.Drawing.Point(8, 8);
this.HowTo.Name = "HowTo";
this.HowTo.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.HowTo.Size = new System.Drawing.Size(168, 48);
this.HowTo.TabIndex = 0;
this.HowTo.Text = " Enter numbers 1 - 9 in each row, column and 3x3 square.";
//
// KeysHowTo
//
this.KeysHowTo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.KeysHowTo.Location = new System.Drawing.Point(8, 56);
this.KeysHowTo.Name = "KeysHowTo";
this.KeysHowTo.Size = new System.Drawing.Size(168, 80);
this.KeysHowTo.TabIndex = 1;
this.KeysHowTo.Text = " Select a cell by clicking on it with your mouse or moving to it with your arro" +
"w keys.";
//
// HLColorHowTo
//
this.HLColorHowTo.ForeColor = System.Drawing.Color.Yellow;
this.HLColorHowTo.Location = new System.Drawing.Point(8, 120);
this.HLColorHowTo.Name = "HLColorHowTo";
this.HLColorHowTo.Size = new System.Drawing.Size(168, 32);
this.HLColorHowTo.TabIndex = 2;
this.HLColorHowTo.Text = " Space Bar clears the number.";
//
// HighLightColorHowTo
//
this.HighLightColorHowTo.ForeColor = System.Drawing.Color.Lime;
this.HighLightColorHowTo.Location = new System.Drawing.Point(8, 152);
this.HighLightColorHowTo.Name = "HighLightColorHowTo";
this.HighLightColorHowTo.Size = new System.Drawing.Size(168, 48);
this.HighLightColorHowTo.TabIndex = 3;
this.HighLightColorHowTo.Text = " If the cell is highlighted with yellow that means the number is wrong.";
//
// OkBtn
//
this.OkBtn.BackColor = System.Drawing.SystemColors.HotTrack;
this.OkBtn.DialogResult = System.Windows.Forms.DialogResult.OK;
this.OkBtn.ForeColor = System.Drawing.Color.Purple;
this.OkBtn.Location = new System.Drawing.Point(64, 248);
this.OkBtn.Name = "OkBtn";
this.OkBtn.Size = new System.Drawing.Size(48, 23);
this.OkBtn.TabIndex = 0;
this.OkBtn.Text = "Ok";
this.OkBtn.UseVisualStyleBackColor = false;
//
// label1
//
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.label1.Location = new System.Drawing.Point(8, 200);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 48);
this.label1.TabIndex = 4;
this.label1.Text = "Use template mode to create your own SudoKu puzzle.";
//
// HowToPlay
//
this.AutoScaleBaseSize = new System.Drawing.Size(7, 15);
this.BackColor = System.Drawing.Color.Navy;
this.ClientSize = new System.Drawing.Size(184, 280);
this.Controls.Add(this.label1);
this.Controls.Add(this.OkBtn);
this.Controls.Add(this.HighLightColorHowTo);
this.Controls.Add(this.HLColorHowTo);
this.Controls.Add(this.KeysHowTo);
this.Controls.Add(this.HowTo);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "HowToPlay";
this.ShowInTaskbar = false;
this.Text = "How To Play";
this.ResumeLayout(false);
private void InitializeComponent() {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(HowToPlay));
this.HowTo = new System.Windows.Forms.Label();
this.KeysHowTo = new System.Windows.Forms.Label();
this.HLColorHowTo = new System.Windows.Forms.Label();
this.HighLightColorHowTo = new System.Windows.Forms.Label();
this.OkBtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// HowTo
//
this.HowTo.ForeColor = System.Drawing.Color.Red;
this.HowTo.Location = new System.Drawing.Point(8, 8);
this.HowTo.Name = "HowTo";
this.HowTo.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.HowTo.Size = new System.Drawing.Size(168, 48);
this.HowTo.TabIndex = 0;
this.HowTo.Text = " Enter numbers 1 - 9 in each row, column and 3x3 square.";
//
// KeysHowTo
//
this.KeysHowTo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.KeysHowTo.Location = new System.Drawing.Point(8, 56);
this.KeysHowTo.Name = "KeysHowTo";
this.KeysHowTo.Size = new System.Drawing.Size(168, 80);
this.KeysHowTo.TabIndex = 1;
this.KeysHowTo.Text = " Select a cell by clicking on it with your mouse or moving to it with your arro" +
"w keys.";
//
// HLColorHowTo
//
this.HLColorHowTo.ForeColor = System.Drawing.Color.Yellow;
this.HLColorHowTo.Location = new System.Drawing.Point(8, 120);
this.HLColorHowTo.Name = "HLColorHowTo";
this.HLColorHowTo.Size = new System.Drawing.Size(168, 32);
this.HLColorHowTo.TabIndex = 2;
this.HLColorHowTo.Text = " Space Bar clears the number.";
//
// HighLightColorHowTo
//
this.HighLightColorHowTo.ForeColor = System.Drawing.Color.Lime;
this.HighLightColorHowTo.Location = new System.Drawing.Point(8, 152);
this.HighLightColorHowTo.Name = "HighLightColorHowTo";
this.HighLightColorHowTo.Size = new System.Drawing.Size(168, 48);
this.HighLightColorHowTo.TabIndex = 3;
this.HighLightColorHowTo.Text = " If the cell is highlighted with yellow that means the number is wrong.";
//
// OkBtn
//
this.OkBtn.BackColor = System.Drawing.SystemColors.HotTrack;
this.OkBtn.DialogResult = System.Windows.Forms.DialogResult.OK;
this.OkBtn.ForeColor = System.Drawing.Color.Purple;
this.OkBtn.Location = new System.Drawing.Point(64, 248);
this.OkBtn.Name = "OkBtn";
this.OkBtn.Size = new System.Drawing.Size(48, 23);
this.OkBtn.TabIndex = 0;
this.OkBtn.Text = "Ok";
this.OkBtn.UseVisualStyleBackColor = false;
//
// label1
//
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.label1.Location = new System.Drawing.Point(8, 200);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 48);
this.label1.TabIndex = 4;
this.label1.Text = "Use template mode to create your own SudoKu puzzle.";
//
// HowToPlay
//
this.AutoScaleBaseSize = new System.Drawing.Size(7, 15);
this.BackColor = System.Drawing.Color.Navy;
this.ClientSize = new System.Drawing.Size(184, 280);
this.Controls.Add(this.label1);
this.Controls.Add(this.OkBtn);
this.Controls.Add(this.HighLightColorHowTo);
this.Controls.Add(this.HLColorHowTo);
this.Controls.Add(this.KeysHowTo);
this.Controls.Add(this.HowTo);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "HowToPlay";
this.ShowInTaskbar = false;
this.Text = "How To Play";
this.ResumeLayout(false);

}
#endregion
810 changes: 299 additions & 511 deletions SudokuGrid.cs

Large diffs are not rendered by default.

138 changes: 46 additions & 92 deletions SudokuReader.cs
Original file line number Diff line number Diff line change
@@ -2,43 +2,34 @@
using System.IO;
using System.Xml;

namespace Sudoku
{
namespace Sudoku {
/// <summary>
/// Summary description for SudokuReader.
/// </summary>
public class SudokuReader
{
public class SudokuReader {
#region Global Variables
static private SudokuReader _reader = new SudokuReader();
XmlDocument _xDoc = new XmlDocument();
XmlDocument _xDoc = new XmlDocument();
#endregion
#region static public SudokuReader Reader
static public SudokuReader Reader
{
get
{
static public SudokuReader Reader {
get {
return _reader;
}
}
#endregion
#region public SudokuReader()
public SudokuReader()
{
public SudokuReader() {
}
#endregion
#region public SudokuGrid Read(string filename)
public SudokuGrid Read(string filename)
{
try
{
public SudokuGrid Read(string filename) {
try {
_xDoc.Load(filename);

SudokuGrid grid = new SudokuGrid(_xDoc);
return grid;
}
catch (Exception ex)
{
} catch (Exception ex) {
System.Windows.Forms.MessageBox.Show("Couldn't Load the Grid in " + filename + "-->" + ex.ToString());
}
SudokuGrid Grid = new SudokuGrid();
@@ -49,39 +40,34 @@ public SudokuGrid Read(string filename)
}
#endregion
#region public SudokuGrid Restart()
public SudokuGrid Restart()
{
public SudokuGrid Restart() {
SudokuGrid grid = new SudokuGrid(_xDoc);
return grid;
}
#endregion
#region public void Save(string filename, SudokuGrid grid, int CM)
public void Save(string filename, SudokuGrid grid, int CM)
{
public void Save(string filename, SudokuGrid grid, int CM) {
_xDoc = new XmlDocument();
FillDocument(_xDoc, grid, CM);
SaveToDisk(filename);
}
#endregion
#region public void Save(string filename, int[,] grid, int CM)
public void Save(string filename, int[,] grid, int CM)
{
public void Save(string filename, int[,] grid, int CM) {
_xDoc = new XmlDocument();
FillDocument(_xDoc, grid, CM);
SaveToDisk(filename);
}
#endregion
#region public void SaveTemplate(string filename, SudokuGrid grid)
public void SaveTemplate(string filename, SudokuGrid grid)
{
public void SaveTemplate(string filename, SudokuGrid grid) {
_xDoc = new XmlDocument();
FillTemplate(_xDoc, grid);
SaveToDisk(filename);
}
#endregion
#region public void FillDocument(XmlDocument doc, SudokuGrid grid, int CM)
public void FillDocument(XmlDocument doc, SudokuGrid grid, int CM)
{
public void FillDocument(XmlDocument doc, SudokuGrid grid, int CM) {
XmlNode rows1 = doc.CreateNode(XmlNodeType.Element, "Rows", "");
XmlNode rows2 = doc.CreateNode(XmlNodeType.Element, "Rows", "");
XmlNode sudoku = doc.CreateNode(XmlNodeType.Element, "Sudoku", "");
@@ -93,56 +79,42 @@ public void FillDocument(XmlDocument doc, SudokuGrid grid, int CM)
guesses.AppendChild(rows1);
hints.AppendChild(rows2);

for (int row = 0; row < 10; row++)
{
for (int row = 0; row < 10; row++) {
XmlNode node = doc.CreateNode(XmlNodeType.Element, "Row", "");
XmlNode node2 = doc.CreateNode(XmlNodeType.Element, "Row", "");
rows1.AppendChild(node2);
rows2.AppendChild(node);
if (row == 9)
{
if (row == 9) {
node2.InnerText += CM.ToString();
}
else
{
for (int col = 0; col < 9; col++)
{
if (grid[row, col] == 0)
{
} else {
for (int col = 0; col < 9; col++) {
if (grid[row, col] == 0) {
node.InnerText += "-,";
node2.InnerText += "-,";
}
else
{
if (grid.IsKnownElement(row, col))
{
} else {
if (grid.IsKnownElement(row, col)) {
node.InnerText += grid[row, col] + ",";
node2.InnerText += "-,";
}
else
{
} else {
node.InnerText += "-,";
node2.InnerText += grid[row, col] + ",";
}
}
}

if (node.InnerText.Length > 0)
{
if (node.InnerText.Length > 0) {
node.InnerText = node.InnerText.Remove(node.InnerText.Length - 1, 1);
}

if (node2.InnerText.Length > 0)
{
if (node2.InnerText.Length > 0) {
node2.InnerText = node2.InnerText.Remove(node2.InnerText.Length - 1, 1);
}
}
}
}
#endregion
#region public void FillDocument(XmlDocument doc, int[,] grid, int CM)
public void FillDocument(XmlDocument doc, int[,] grid, int CM)
{
public void FillDocument(XmlDocument doc, int[,] grid, int CM) {
XmlNode rows1 = doc.CreateNode(XmlNodeType.Element, "Rows", "");
XmlNode rows2 = doc.CreateNode(XmlNodeType.Element, "Rows", "");
XmlNode sudoku = doc.CreateNode(XmlNodeType.Element, "Sudoku", "");
@@ -155,89 +127,71 @@ public void FillDocument(XmlDocument doc, int[,] grid, int CM)
hints.AppendChild(rows2);


for (int row = 0; row < 10; row++)
{
XmlNode node = doc.CreateNode(XmlNodeType.Element,"Row", "");
XmlNode node2 = doc.CreateNode(XmlNodeType.Element,"Row", "");
for (int row = 0; row < 10; row++) {
XmlNode node = doc.CreateNode(XmlNodeType.Element, "Row", "");
XmlNode node2 = doc.CreateNode(XmlNodeType.Element, "Row", "");
rows1.AppendChild(node2);
rows2.AppendChild(node);
if (row == 9)
{
if (row == 9) {
node2.InnerText += CM.ToString();
}
else
{
for (int col = 0; col<9; col++)
{
if (grid[row, col] == 0)
{
} else {
for (int col = 0; col < 9; col++) {
if (grid[row, col] == 0) {
node.InnerText += "-" + ",";
node2.InnerText += "-" + ",";
}
else
{
} else {
node.InnerText += grid[row, col] + ",";
node2.InnerText += "-" + ",";
}
}

if (node.InnerText.Length > 0)
{
node.InnerText = node.InnerText.Remove(node.InnerText.Length -1 , 1);
if (node.InnerText.Length > 0) {
node.InnerText = node.InnerText.Remove(node.InnerText.Length - 1, 1);
}

if (node2.InnerText.Length > 0)
{
node2.InnerText = node2.InnerText.Remove(node2.InnerText.Length -1 , 1);
if (node2.InnerText.Length > 0) {
node2.InnerText = node2.InnerText.Remove(node2.InnerText.Length - 1, 1);
}
}
}
}
#endregion
#region public void FillTemplate(XmlDocument doc, SudokuGrid grid)
public void FillTemplate(XmlDocument doc, SudokuGrid grid)
{
public void FillTemplate(XmlDocument doc, SudokuGrid grid) {
XmlNode sudoku = doc.CreateNode(XmlNodeType.Element, "Sudoku", "");
XmlNode hints = doc.CreateNode(XmlNodeType.Element, "Hints", "");
XmlNode rows = doc.CreateNode(XmlNodeType.Element, "Rows", "");
doc.AppendChild(sudoku);
sudoku.AppendChild(hints);
hints.AppendChild(rows);

for (int row = 0; row < 9; row++)
{
for (int row = 0; row < 9; row++) {
XmlNode node = doc.CreateNode(XmlNodeType.Element, "Row", "");

rows.AppendChild(node);

for (int col = 0; col < 9; col++)
{
if (grid[row, col] == 0)
{
for (int col = 0; col < 9; col++) {
if (grid[row, col] == 0) {
node.InnerText += "-,";
}
else
{
} else {
node.InnerText += grid[row, col] + ",";
}
}

if (node.InnerText.Length > 0)
{
node.InnerText = node.InnerText.Remove(node.InnerText.Length -1 , 1);
if (node.InnerText.Length > 0) {
node.InnerText = node.InnerText.Remove(node.InnerText.Length - 1, 1);
}
}
}
#endregion
#region private void SaveToDisk(string filename)
private void SaveToDisk(string filename)
{
private void SaveToDisk(string filename) {
XmlTextWriter xmlWriter = new XmlTextWriter(filename, System.Text.Encoding.Default);
xmlWriter.IndentChar = '\t';
xmlWriter.Indentation = 1;
xmlWriter.Formatting = Formatting.Indented;

_xDoc.Save(xmlWriter);
_xDoc.Save(xmlWriter);

xmlWriter.Close();
}

0 comments on commit 9268c19

Please sign in to comment.