|
| 1 | +using System; |
| 2 | +using System.Drawing; |
| 3 | +using System.Collections; |
| 4 | +using System.ComponentModel; |
| 5 | +using System.Windows.Forms; |
| 6 | + |
| 7 | +namespace Sudoku |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Summary description for About. |
| 11 | + /// </summary> |
| 12 | + public class About : System.Windows.Forms.Form |
| 13 | + { |
| 14 | + #region private stuff |
| 15 | + |
| 16 | + private System.Windows.Forms.Button btnOK; |
| 17 | + /// <summary> |
| 18 | + /// Required designer variable. |
| 19 | + /// </summary> |
| 20 | + private System.ComponentModel.Container components = null; |
| 21 | + #endregion |
| 22 | + #region public About() |
| 23 | + public About() |
| 24 | + { |
| 25 | + // |
| 26 | + // Required for Windows Form Designer support |
| 27 | + // |
| 28 | + InitializeComponent(); |
| 29 | + |
| 30 | + // |
| 31 | + // TODO: Add any constructor code after InitializeComponent call |
| 32 | + // |
| 33 | + } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Clean up any resources being used. |
| 37 | + /// </summary> |
| 38 | + protected override void Dispose( bool disposing ) |
| 39 | + { |
| 40 | + if( disposing ) |
| 41 | + { |
| 42 | + if(components != null) |
| 43 | + { |
| 44 | + components.Dispose(); |
| 45 | + } |
| 46 | + } |
| 47 | + base.Dispose( disposing ); |
| 48 | + } |
| 49 | + #endregion |
| 50 | + #region Windows Form Designer generated code |
| 51 | + /// <summary> |
| 52 | + /// Required method for Designer support - do not modify |
| 53 | + /// the contents of this method with the code editor. |
| 54 | + /// </summary> |
| 55 | + private void InitializeComponent() |
| 56 | + { |
| 57 | + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(About)); |
| 58 | + this.btnOK = new System.Windows.Forms.Button(); |
| 59 | + this.SuspendLayout(); |
| 60 | + // |
| 61 | + // btnOK |
| 62 | + // |
| 63 | + this.btnOK.BackColor = System.Drawing.Color.Black; |
| 64 | + this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; |
| 65 | + this.btnOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); |
| 66 | + this.btnOK.ForeColor = System.Drawing.Color.LightGreen; |
| 67 | + this.btnOK.Location = new System.Drawing.Point(43, 133); |
| 68 | + this.btnOK.Name = "btnOK"; |
| 69 | + this.btnOK.Size = new System.Drawing.Size(75, 23); |
| 70 | + this.btnOK.TabIndex = 3; |
| 71 | + this.btnOK.Text = "OK"; |
| 72 | + this.btnOK.UseVisualStyleBackColor = false; |
| 73 | + // |
| 74 | + // About |
| 75 | + // |
| 76 | + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); |
| 77 | + this.BackColor = System.Drawing.Color.Gold; |
| 78 | + this.ClientSize = new System.Drawing.Size(162, 162); |
| 79 | + this.Controls.Add(this.btnOK); |
| 80 | + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; |
| 81 | + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); |
| 82 | + this.Name = "About"; |
| 83 | + this.ShowInTaskbar = false; |
| 84 | + this.Text = "Sudoku v4.1"; |
| 85 | + this.Paint += new System.Windows.Forms.PaintEventHandler(this.About_Paint); |
| 86 | + this.ResumeLayout(false); |
| 87 | + |
| 88 | + } |
| 89 | + #endregion |
| 90 | + #region Global Variables |
| 91 | + int count = 0; |
| 92 | + int _left = 28; |
| 93 | + int _top = 35; |
| 94 | + int[,] _grid = new int[9,9]; |
| 95 | + SudokuGrid grid = new SudokuGrid(); |
| 96 | + int [,,] gridHints = new int[9,9,9]; |
| 97 | + Pen _penThick = new Pen(Color.Black, 3); |
| 98 | + Rectangle[,] _boardArray = new Rectangle[9,9]; |
| 99 | + Font _sudukoFont = new Font("Arial", 10, FontStyle.Regular); |
| 100 | + Font _hintsFont = new Font("Small Fonts", 4); |
| 101 | + Rectangle _board = new Rectangle(0,0, 0, 0); |
| 102 | + #endregion |
| 103 | + #region void DrawSudokuGrid(Graphics g) |
| 104 | + void DrawSudokuGrid(Graphics g) |
| 105 | + { |
| 106 | + if (count == 0) |
| 107 | + { |
| 108 | + _grid = grid.GenerateGrid(); |
| 109 | + int r = 0; |
| 110 | + for (int row = 0; row < 5; row += 2) |
| 111 | + { |
| 112 | + for (int col = 0; col < 4; col += 2) |
| 113 | + { |
| 114 | + if (r == 0) |
| 115 | + r = new Random().Next(); |
| 116 | + if (r % 2 == 1) |
| 117 | + _grid[row, col] = 0; |
| 118 | + r /= 2; |
| 119 | + } |
| 120 | + } |
| 121 | + for (int row = 1; row < 5; row += 2) |
| 122 | + { |
| 123 | + for (int col = 1; col < 4; col += 2) |
| 124 | + { |
| 125 | + if (r == 0) |
| 126 | + r = new Random().Next(); |
| 127 | + if (r % 2 == 1) |
| 128 | + _grid[row, col] = 0; |
| 129 | + r /= 2; |
| 130 | + } |
| 131 | + } |
| 132 | + for (int row = 0; row < 5; row += 2) |
| 133 | + { |
| 134 | + for (int col = 1; col < 4; col += 2) |
| 135 | + { |
| 136 | + if (r == 0) |
| 137 | + r = new Random().Next(); |
| 138 | + if (r % 2 == 1) |
| 139 | + _grid[row, col] = 0; |
| 140 | + r /= 2; |
| 141 | + } |
| 142 | + } |
| 143 | + for (int row = 1; row < 5; row += 2) |
| 144 | + { |
| 145 | + for (int col = 0; col < 4; col += 2) |
| 146 | + { |
| 147 | + if (r == 0) |
| 148 | + r = new Random().Next(); |
| 149 | + if (r % 2 == 1) |
| 150 | + _grid[row, col] = 0; |
| 151 | + r /= 2; |
| 152 | + } |
| 153 | + } |
| 154 | + if (r % 2 == 0) |
| 155 | + _grid[4, 4] = 0; |
| 156 | + for (int row = 0; row < 5; row++) |
| 157 | + { |
| 158 | + for (int col = 0; col < 4; col++) |
| 159 | + { |
| 160 | + if (_grid[row, col] == 0) |
| 161 | + { |
| 162 | + _grid[8 - row, 8 - col] = 0; |
| 163 | + _grid[8 - col, row] = 0; |
| 164 | + _grid[col, 8 - row] = 0; |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + gridHints = grid.CalculateHints(_grid); |
| 169 | + _board = ClientRectangle; |
| 170 | + } |
| 171 | + // draw square |
| 172 | + g.DrawRectangle(_penThick, _board); |
| 173 | + |
| 174 | + int spacingX = _board.Width/9; |
| 175 | + int spacingY = _board.Height/9; |
| 176 | + |
| 177 | + for (int col = 0; col < 9; col++) |
| 178 | + { |
| 179 | + for (int row = 0; row < 9; row++) |
| 180 | + { |
| 181 | + _boardArray[row, col] = new Rectangle(_board.Left + col*spacingX, _board.Top + row*spacingY, spacingX, spacingY); |
| 182 | + } |
| 183 | + } |
| 184 | + g.FillRectangle(Brushes.Yellow, _boardArray[0, 3]); |
| 185 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[0, 4]); |
| 186 | + g.FillRectangle(Brushes.Yellow, _boardArray[0, 5]); |
| 187 | + g.FillRectangle(Brushes.DeepPink, _boardArray[0, 6]); |
| 188 | + g.FillRectangle(Brushes.DeepPink, _boardArray[0, 7]); |
| 189 | + g.FillRectangle(Brushes.DeepPink, _boardArray[1, 1]); |
| 190 | + g.FillRectangle(Brushes.DeepPink, _boardArray[1, 2]); |
| 191 | + g.FillRectangle(Brushes.Yellow, _boardArray[1, 3]); |
| 192 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[1, 4]); |
| 193 | + g.FillRectangle(Brushes.Yellow, _boardArray[1, 5]); |
| 194 | + g.FillRectangle(Brushes.DeepPink, _boardArray[1, 6]); |
| 195 | + g.FillRectangle(Brushes.DeepPink, _boardArray[1, 7]); |
| 196 | + g.FillRectangle(Brushes.Yellow, _boardArray[2, 3]); |
| 197 | + g.FillRectangle(Brushes.Yellow, _boardArray[2, 4]); |
| 198 | + g.FillRectangle(Brushes.Yellow, _boardArray[2, 5]); |
| 199 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[3, 0]); |
| 200 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[3, 1]); |
| 201 | + g.FillRectangle(Brushes.DeepPink, _boardArray[3, 3]); |
| 202 | + g.FillRectangle(Brushes.DeepPink, _boardArray[3, 4]); |
| 203 | + g.FillRectangle(Brushes.DeepPink, _boardArray[3, 5]); |
| 204 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[3, 7]); |
| 205 | + g.FillRectangle(Brushes.DeepPink, _boardArray[4, 4]); |
| 206 | + g.FillRectangle(Brushes.DeepPink, _boardArray[4, 5]); |
| 207 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[5, 0]); |
| 208 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[5, 1]); |
| 209 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[5, 2]); |
| 210 | + g.FillRectangle(Brushes.DeepPink, _boardArray[5, 4]); |
| 211 | + g.FillRectangle(Brushes.DeepPink, _boardArray[5, 5]); |
| 212 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[5, 6]); |
| 213 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[5, 7]); |
| 214 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[5, 8]); |
| 215 | + g.FillRectangle(Brushes.Yellow, _boardArray[6, 0]); |
| 216 | + g.FillRectangle(Brushes.Yellow, _boardArray[6, 1]); |
| 217 | + g.FillRectangle(Brushes.Yellow, _boardArray[6, 2]); |
| 218 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[6, 4]); |
| 219 | + g.FillRectangle(Brushes.Yellow, _boardArray[6, 6]); |
| 220 | + g.FillRectangle(Brushes.DeepPink, _boardArray[6, 7]); |
| 221 | + g.FillRectangle(Brushes.Yellow, _boardArray[6, 8]); |
| 222 | + g.FillRectangle(Brushes.Yellow, _boardArray[7, 0]); |
| 223 | + g.FillRectangle(Brushes.DeepPink, _boardArray[7, 1]); |
| 224 | + g.FillRectangle(Brushes.Yellow, _boardArray[7, 2]); |
| 225 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[7, 5]); |
| 226 | + g.FillRectangle(Brushes.Yellow, _boardArray[7, 6]); |
| 227 | + g.FillRectangle(Brushes.DeepPink, _boardArray[7, 7]); |
| 228 | + g.FillRectangle(Brushes.Yellow, _boardArray[7, 8]); |
| 229 | + g.FillRectangle(Brushes.Yellow, _boardArray[8, 0]); |
| 230 | + g.FillRectangle(Brushes.Yellow, _boardArray[8, 1]); |
| 231 | + g.FillRectangle(Brushes.Yellow, _boardArray[8, 2]); |
| 232 | + g.FillRectangle(Brushes.DarkViolet, _boardArray[8, 4]); |
| 233 | + g.FillRectangle(Brushes.Yellow, _boardArray[8, 6]); |
| 234 | + g.FillRectangle(Brushes.Yellow, _boardArray[8, 7]); |
| 235 | + g.FillRectangle(Brushes.Yellow, _boardArray[8, 8]); |
| 236 | + |
| 237 | + for (int i = 0; i < 10; i++) |
| 238 | + { |
| 239 | + if (i % 3 == 0) |
| 240 | + { |
| 241 | + g.DrawLine(_penThick, _board.Left, _board.Top + spacingY * i, _board.Right, _board.Top + spacingY*i); |
| 242 | + g.DrawLine(_penThick, _board.Left + spacingX * i, _board.Top, _board.Left + spacingX * i, _board.Bottom); |
| 243 | + } |
| 244 | + else |
| 245 | + { |
| 246 | + g.DrawLine(Pens.Black, _board.Left, _board.Top + spacingY * i, _board.Right, _board.Top + spacingY*i); |
| 247 | + g.DrawLine(Pens.Black, _board.Left + spacingX * i, _board.Top, _board.Left + spacingX * i, _board.Bottom); |
| 248 | + } |
| 249 | + } |
| 250 | + |
| 251 | + for (int col = 0; col < 9; col++) |
| 252 | + { |
| 253 | + for (int row = 0; row < 9; row++) |
| 254 | + { |
| 255 | + int val = _grid[row, col]; |
| 256 | + |
| 257 | + if (val != 0) |
| 258 | + { |
| 259 | + g.DrawString(val.ToString(), _sudukoFont, Brushes.Black, _board.Left + col*spacingX + 4, _board.Top + row*spacingY + 1, new StringFormat()); |
| 260 | + } |
| 261 | + else |
| 262 | + { |
| 263 | + DrawGridHints(g, row, col); |
| 264 | + } |
| 265 | + } |
| 266 | + } |
| 267 | + } |
| 268 | + #endregion |
| 269 | + #region void DrawGridHints(Graphics g, int row, int col) |
| 270 | + void DrawGridHints(Graphics g, int row, int col) |
| 271 | + { |
| 272 | + int spacingX = _board.Width/9; |
| 273 | + int spacingY = _board.Height/9; |
| 274 | + int length; |
| 275 | + string hints = ""; |
| 276 | + string hintss = ""; |
| 277 | + string hintsss = ""; |
| 278 | + for (int i = 0; i < 9; i++) |
| 279 | + { |
| 280 | + if (gridHints[row, col, i] != 0) |
| 281 | + hints = hints + gridHints[row, col, i].ToString() + ","; |
| 282 | + } |
| 283 | + |
| 284 | + if (hints.Length > 0) |
| 285 | + { |
| 286 | + hints = hints.Remove(hints.Length - 1, 1); |
| 287 | + } |
| 288 | + System.Drawing.Brush brush = Brushes.Maroon; |
| 289 | + if (hints.Length == 1) |
| 290 | + { |
| 291 | + brush = Brushes.Blue; |
| 292 | + } |
| 293 | + if (hints.Length > 8) |
| 294 | + { |
| 295 | + length = hints.Length - 8; |
| 296 | + hintss = hints.Remove(0, 8); |
| 297 | + hints = hints.Remove(8, length); |
| 298 | + if (hintss.Length > 8) |
| 299 | + { |
| 300 | + hintsss = hintss.Remove(0, 8); |
| 301 | + hintss = hintss.Remove(8, 1); |
| 302 | + g.DrawString(hintsss.ToString(), _hintsFont, brush, _board.Left + col*spacingX + 1, _board.Top + row*spacingY + 14, new StringFormat()); |
| 303 | + } |
| 304 | + g.DrawString(hintss.ToString(), _hintsFont, brush, _board.Left + col*spacingX + 1, _board.Top + row*spacingY + 8, new StringFormat()); |
| 305 | + } |
| 306 | + g.DrawString(hints.ToString(), _hintsFont, brush, _board.Left + col*spacingX + 1, _board.Top + row*spacingY + 2, new StringFormat()); |
| 307 | + } |
| 308 | + #endregion |
| 309 | + #region private void About_Paint(object sender, System.Windows.Forms.PaintEventArgs e) |
| 310 | + private void About_Paint(object sender, System.Windows.Forms.PaintEventArgs e) |
| 311 | + { |
| 312 | + String S1 = "by Tony Brix"; |
| 313 | + |
| 314 | + String S3 = "Special Thanks to"; |
| 315 | + String S4 = "Michael Gold"; |
| 316 | + DrawSudokuGrid(e.Graphics); |
| 317 | + //e.Graphics.DrawString("Sudoku", new Font("Verdana", 20), Brushes.Black, 28, 10); |
| 318 | + //e.Graphics.DrawString("Sudoku", new Font("Verdana", 20), Brushes.Black, 27, 9); |
| 319 | + //e.Graphics.DrawString("Sudoku", new Font("Verdana", 20), Brushes.Yellow, 26, 8); |
| 320 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left + 1, _top + 1); |
| 321 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left + 1, _top - 1); |
| 322 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left - 1, _top - 1); |
| 323 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left - 1, _top + 1); |
| 324 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left, _top - 1); |
| 325 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left, _top + 1); |
| 326 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left - 1, _top); |
| 327 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Black, _left + 1, _top); |
| 328 | + e.Graphics.DrawString(S1, new Font("Verdana", 12), Brushes.Aqua, _left, _top); |
| 329 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 29, _top + 20); |
| 330 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 29, _top + 18); |
| 331 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 31, _top + 18); |
| 332 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 31, _top + 20); |
| 333 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 30, _top + 18); |
| 334 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 30, _top + 20); |
| 335 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 31, _top + 19); |
| 336 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Black, _left - 29, _top + 19); |
| 337 | + e.Graphics.DrawString(S2, new Font("Verdana", 12), Brushes.Aqua, _left - 30, _top + 19); |
| 338 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 21, _top + 38); |
| 339 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 21, _top + 36); |
| 340 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 23, _top + 36); |
| 341 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 23, _top + 38); |
| 342 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 22, _top + 36); |
| 343 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 22, _top + 38); |
| 344 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 23, _top + 37); |
| 345 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Black, _left - 21, _top + 37); |
| 346 | + e.Graphics.DrawString(S3, new Font("Verdana", 12), Brushes.Aqua, _left - 22, _top + 37); |
| 347 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left, _top + 55); |
| 348 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left, _top + 53); |
| 349 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left - 2, _top + 53); |
| 350 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left - 2, _top + 55); |
| 351 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left - 1, _top + 53); |
| 352 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left - 1, _top + 55); |
| 353 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left - 2, _top + 54); |
| 354 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Black, _left, _top + 54); |
| 355 | + e.Graphics.DrawString(S4, new Font("Verdana", 12), Brushes.Aqua, _left - 1, _top + 54); |
| 356 | + count = 1; |
| 357 | + } |
| 358 | + #endregion |
| 359 | + } |
| 360 | +} |
0 commit comments