By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,168 Members | 630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,168 IT Pros & Developers. It's quick & easy.

What does whichkey>=48...<= 57 mean in a 3x3 sudoku game?

P: 785
In a 3x3 sudoku JavaScript with images, what is 48? and 57?
I'm trying to convert a 3x3 sudoku to a 2x2. I don't understand why 48 can't be say, 46 or 45; why 57 can't be 54, etc. Its the numbers I don't understand.

Expand|Select|Wrap|Line Numbers
  1. function KeyDown(whichkey)
  2. { if (IsOver) return;
  3.   if (I_Sel==-1) return;
  4.   if ((whichkey>=48)&&(whichkey<=57))
  5.   { Fld[I_Sel][J_Sel][K_Sel][L_Sel]=48-whichkey;
  6.     window.document.images[4*I_Sel+4*J_Sel+K_Sel+2*L_Sel].src = NPic[whichkey-48].src;
  7.     I_Sel=-1;
  8.   }
  9.    if (IsSolved())
  10.   { IsOver=true;
  11.     Now = new Date();
  12.     EndTime = Now.getTime() / 1000;
  13.     i=Math.floor(EndTime - StartTime);
  14.     if (window.opener)
  15.     { if (window.opener.SetHighscores)
  16.         window.opener.SetHighscores("Sudoku","",i,-1);
  17.     }
  18.     alert("Super, you solved this game in "+i+ " seconds !");
  19.   }
  20. }  
Mar 5 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 4,258
I would strongly advise you to follow some JavaScript tutorial on DOM and events before you continue with adapting that game. Because otherwise it is going to take you a very long time to get it right!

Statement if ((whichkey>=48)&&(whichkey<=57)) is simply testing the value of the key that is pressed.

Here it tests for a key greater or equal to 0 (zero, of which the decimal equivalent is 48) and a key lower or equal to 9 (nine, of which the same is 57).

So you see, you cannot just change these values to whatever you like it to be!

Ronald :cool:
Mar 5 '07 #2

Expert 100+
P: 1,208
soduko is a challenging game and to write code to play the game is also challenging this is not novice coding

For those that don't know heres how soduko works

say you have 18 squares (some already have numbers in them locked)

for each 6 squares you have to put numbers 1 - 6... 2 of the same number cant be in that column or row and not in the 6 block area... the challenge is to complete all the blocks.
Mar 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.