Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Oct 26, 2018
1 parent 995cf85 commit 9268c19
Show file tree
Hide file tree
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
Expand Up @@ -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;
Expand All @@ -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
//
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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]);
Expand Down Expand Up @@ -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";
Expand Down
Loading

0 comments on commit 9268c19

Please sign in to comment.