Skip to content

Commit ffa861a

Browse files
committed
Show solution opens in a second window.
1 parent 54c3e88 commit ffa861a

File tree

3 files changed

+69
-30
lines changed

3 files changed

+69
-30
lines changed

Encoding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ function decode(input) {
5353
return;
5454
}
5555

56-
submitGivens();
57-
5856
for (var i = 0; i < 81; i++) {
5957
currentCell = cells[i];
6058

@@ -92,6 +90,8 @@ function decode(input) {
9290
currentCell.candidatesElement.innerHTML = currentCell.getPencilmarkString();
9391
}
9492

93+
submitGivens();
94+
showDuplicates();
9595
}
9696

9797
function loadFromCookie() {

Sudoku.js

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -344,44 +344,82 @@ function submitGivens() {
344344

345345
currentCell.solution = parseInt(cells.solution[i]);
346346
}
347-
348-
clearPencilmarks();
349347
}
350348
}
351349

352350
function showSolution() {
351+
var currentElement;
352+
var row;
353+
var solution = "";
353354

354-
var currentCell;
355-
356-
if (cells.solution === undefined) return;
355+
if (cells.solution === undefined || !window.confirm("Are you sure you want to show the solution?")) {
356+
return;
357+
}
357358

358-
if (document.getElementById("show_solution").checked) {
359-
if (!window.confirm("Are you sure you want to show the solution?")) {
360-
document.getElementById("show_solution").checked = false;
361-
return;
359+
360+
for (var i = 0; i < 9; i++) {
361+
row = i * 9;
362+
solution += cells.solution.charAt(row) + " " + cells.solution.charAt(row + 1) + " " + cells.solution.charAt(row + 2) + " | ";
363+
solution += cells.solution.charAt(row + 3) + " " + cells.solution.charAt(row + 4) + " " + cells.solution.charAt(row + 5) + " | ";
364+
solution += cells.solution.charAt(row + 6) + " " + cells.solution.charAt(row + 7) + " " + cells.solution.charAt(row + 8) + "<br />";
365+
366+
if (i == 2 || i == 5) {
367+
solution += "------+-------+------<br />";
362368
}
369+
}
370+
371+
if (window.solutionWindow) {
372+
window.solutionWindow.close();
373+
}
374+
375+
window.solutionWindow = window.open("", "", "height=230,width=208,status=0,menubar=0");
376+
377+
currentElement = window.solutionWindow.document.head.appendChild(document.createElement("title"));
378+
currentElement.textContent = "Solution";
379+
380+
381+
382+
currentElement = window.solutionWindow.document.body.appendChild(document.createElement("div"));
383+
384+
// alert(solution);
385+
386+
currentElement.innerHTML = solution;
387+
currentElement.style.fontFamily = "Consolas";
388+
currentElement.style.fontColor = "#666";
389+
390+
window.onunload = function() {
391+
window.solutionWindow.close();
392+
};
393+
394+
395+
396+
// if (document.getElementById("show_solution").checked) {
397+
// if (!window.confirm("Are you sure you want to show the solution?")) {
398+
// document.getElementById("show_solution").checked = false;
399+
// return;
400+
// }
363401

364-
for (var i = 0; i < 81; i++) {
365-
currentCell = cells[i];
402+
// for (var i = 0; i < 81; i++) {
403+
// currentCell = cells[i];
366404

367-
if (currentCell.element.children.length > 0) {
368-
currentCell.element.firstChild.value = currentCell.solution;
369-
currentCell.element.firstChild.disabled = true;
370-
}
405+
// if (currentCell.element.children.length > 0) {
406+
// currentCell.element.firstChild.value = currentCell.solution;
407+
// currentCell.element.firstChild.disabled = true;
408+
// }
371409

372410

373-
}
374-
} else {
375-
for (var i = 0; i < 81; i++) {
376-
currentCell = cells[i];
411+
// }
412+
// } else {
413+
// for (var i = 0; i < 81; i++) {
414+
// currentCell = cells[i];
377415

378-
if (currentCell.element.children.length > 0) {
379-
currentCell.element.firstChild.disabled = false;
416+
// if (currentCell.element.children.length > 0) {
417+
// currentCell.element.firstChild.disabled = false;
380418

381-
currentCell.element.firstChild.value = currentCell.value === 0 ? "" : currentCell.value;
382-
}
383-
}
384-
}
419+
// currentCell.element.firstChild.value = currentCell.value === 0 ? "" : currentCell.value;
420+
// }
421+
// }
422+
// }
385423
}
386424

387425
function getHint() {

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@
127127
<div class="small_header">Solution/Hints:</div>
128128
<ul>
129129
<li>
130-
<input type="checkbox" name="show_solution" id="show_solution" title="Show the solution to the sudoku puzzle." onclick="showSolution();" />
131-
<label for="show_solution" title="Show the solution to the sudoku puzzle.">Show solution.<label>
130+
<!-- <input type="checkbox" name="show_solution" id="show_solution" title="Show the solution to the sudoku puzzle." onclick="showSolution();" />
131+
<label for="show_solution" title="Show the solution to the sudoku puzzle.">Show solution.<label> -->
132+
<input type="button" name="show_solution" id="show_solution" value="Show Solution" title="Show the solution to the sudoku puzzle in a new window." onclick="showSolution();" />
132133
</li><li>
133134
<input type="button" name="get_hint" id="get_hint" value="Hint (3)" title="Give a hint for the selected cell. There are three hints remaining." onclick="getHint();" />
134135
</li>
@@ -138,7 +139,7 @@
138139
</div>
139140

140141
<div id="begin_solving">
141-
<input type="button" value="Begin Solving" id="begin_solving_button" class="large_button" title="Submit the entered numbers as clues and begin solving the sudoku puzzle." onclick="submitGivens();" onmouseover="this.classList.add('large_button_hover'); this.classList.remove('large_button');" onmousedown="this.classList.add('large_button_hover'); this.classList.remove('large_button');" onmouseout="this.classList.add('large_button'); this.classList.remove('large_button_hover');" />
142+
<input type="button" value="Begin Solving" id="begin_solving_button" class="large_button" title="Submit the entered numbers as clues and begin solving the sudoku puzzle." onclick="submitGivens(); clearPencilmarks();" onmouseover="this.classList.add('large_button_hover'); this.classList.remove('large_button');" onmousedown="this.classList.add('large_button_hover'); this.classList.remove('large_button');" onmouseout="this.classList.add('large_button'); this.classList.remove('large_button_hover');" />
142143
</div>
143144

144145
<div id="side_bar">

0 commit comments

Comments
 (0)