Jump to content

Recommended Posts

Hello guys. I am building a 'sudoku' game and i want to load a puzzle (which is actually a text string consisting of 81 digits).

 

I have succeeded in loading just one puzzle, however i want to make it possible to load a different puzzle when the user clicks on a button. Also the old puzzle should be removed.

 

Here is my sudoku board:

 

<div class="group">
<div class="cell"><input type="text" name="8_0" onfocus="{onFocusY=8;onFocusZ=0;}"></div>
<div class="cell"><input type="text" name="8_1" onfocus="{onFocusY=8;onFocusZ=1;}"></div>
<div class="cell"><input type="text" name="8_2" onfocus="{onFocusY=8;onFocusZ=2;}"></div>
<div class="cell"><input type="text" name="8_3" onfocus="{onFocusY=8;onFocusZ=3;}"></div>
<div class="cell"><input type="text" name="8_4" onfocus="{onFocusY=8;onFocusZ=4;}"></div>
<div class="cell"><input type="text" name="8_5" onfocus="{onFocusY=8;onFocusZ=5;}"></div>
<div class="cell"><input type="text" name="8_6" onfocus="{onFocusY=8;onFocusZ=6;}"></div>
<div class="cell"><input type="text" name="8_7" onfocus="{onFocusY=8;onFocusZ=7;}"></div>
<div class="cell"><input type="text" name="8_8" onfocus="{onFocusY=8;onFocusZ=8;}"></div>
</div>

    
<textarea id="puzzle">306500090200400851100780060009368500628000349005924100040097002863001005070003408</textarea>

 

Actually there are nine of them, but there's no point in copying them all, they are pretty much the same.

 

To load the puzzle i've used the following javascript:

 

function ReloadingBoard(){
var puzzle = new String(document.getElementById('puzzle').value);
var pos;
var ch;
var cell;
var r;
var c;
            
pos = 0;
for(c=0;c<=8;c++)
{
for(r=0;r<=8;r++)
{
cell = GetCellFromRowcolumn(r,c);     
ch = puzzle.substr(pos,1);
                    
switch(ch){
case '0':
cell.value = '';
break;
default: cell.value = ch;
break;
}
pos++;
}
}
}

 

and

 

function loadingBoard(){
document.onkeyup = KeyPressed; 
ReloadingBoard();
}

 

So how do i make the board load a different puzzle when i click the button? Any ideas? Thanks:)

Link to comment
https://forums.phpfreaks.com/topic/261277-loading-sudoku-puzzle/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.