473,473 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What is wrong with this script? Images doesn't show.

tpgames
785 Contributor
2x2 Sudoku doesn't work at all. The images don't show up on the grid. I don't understand JavaScript very well. Just learning it. Thanks!

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.  
  5. <title>Sudoku 9</title>
  6.  
  7. <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
  8. <link type="text/css" rel="stylesheet" href="http://www.tpgames.net/gaming/2/game.css"> 
  9. <link rel="shortcut icon" href="http://www.tpgames.net/tpgamesicon.gif">
  10.  
  11. <script language="JavaScript1.2">
  12. var IsNetscape;
  13. if(navigator.appName == "Netscape")
  14. { IsNetscape = true;
  15.   document.captureEvents(Event.KEYDOWN)
  16. }  
  17. else IsNetscape = false;  
  18. function NetscapeKeyDown(key)
  19. { if(IsNetscape)
  20.     KeyDown(key.which);
  21. }  
  22. document.onkeydown = NetscapeKeyDown;
  23. </script>
  24. <script for=document event="onkeydown()" language="JScript">
  25. if (window.event) KeyDown(window.event.keyCode);
  26. </script>
  27. <script language="JavaScript">
  28. var i, j, k, I_Sel, J_Sel, K_Sel, L_Sel, StartTime, EndTime, IsOver;
  29.  
  30. PreFld0=new Array(
  31. new Array(
  32. new Array(new Array(1,2),new Array(3,4)),
  33. new Array(new Array(3,4),new Array(1,2)),
  34. new Array(
  35. new Array(new Array(2,3),new Array(4,1)),
  36. new Array(new Array(4,1),new Array(2,3)),
  37. new Array(
  38. new Array(new Array(3,4),new Array(1,2)),
  39. new Array(new Array(1,2),new Array(3,4))));
  40.  
  41. PreFld=new Array(
  42. new Array(
  43. new Array(new Array(1,2),new Array(3,4)),
  44. new Array(new Array(3,4),new Array(1,2)),
  45. new Array(
  46. new Array(new Array(2,3),new Array(4,1)),
  47. new Array(new Array(4,1),new Array(2,3)),
  48. new Array(
  49. new Array(new Array(3,4),new Array(1,2)),
  50. new Array(new Array(1,2),new Array(3,4))));
  51.  
  52. Fld=new Array(
  53. new Array(
  54. new Array(new Array(1,2),new Array(3,4)),
  55. new Array(new Array(3,4),new Array(1,2)),
  56. new Array(
  57. new Array(new Array(2,1),new Array(4,3)),
  58. new Array(new Array(4,3),new Array(2,1)),
  59. new Array(
  60. new Array(new Array(1,4),new Array(3,2)),
  61. new Array(new Array(3,2),new Array(1,4))));
  62.  
  63. NPic = new Array(5);
  64. NPic[0] = new Image();
  65. NPic[0].src = "rebu_n.gif";
  66. for (i=1; i < 5; i++)
  67. { NPic[i] = new Image();
  68.   NPic[i].src = "rebu"+eval(i)+"n.gif";
  69. QPic = new Image(); 
  70. QPic.src = "rebu0q.gif"; 
  71.  
  72. function Clicked(ii, jj, kk, ll)
  73. { var ff=false;
  74.   if (IsOver) return;
  75.   if (I_Sel>=0) window.document.images[4*I_Sel+4*J_Sel+K_Sel+2*L_Sel].src = NPic[0].src;
  76.   if (Fld[ii][jj][kk][ll]>0) return;
  77.   I_Sel=ii;
  78.   J_Sel=jj;
  79.   K_Sel=kk;
  80.   L_Sel=ll;
  81.   window.document.images[4*I_Sel+4*J_Sel+K_Sel+2*L_Sel].src = QPic.src;
  82.  
  83.  
  84.  
  85. function KeyDown(whichkey)
  86. { if (IsOver) return;
  87.   if (I_Sel==-1) return;
  88.   if ((whichkey>=48)&&(whichkey<=57))
  89.   { Fld[I_Sel][J_Sel][K_Sel][L_Sel]=48-whichkey;
  90.     window.document.images[4*I_Sel+4*J_Sel+K_Sel+2*L_Sel].src = NPic[whichkey-48].src;
  91.     I_Sel=-1;
  92.   }
  93.   if (IsSolved())
  94.   { IsOver=true;
  95.     Now = new Date();
  96.     EndTime = Now.getTime() / 1000;
  97.     i=Math.floor(EndTime - StartTime);
  98.     if (window.opener)
  99.     { if (window.opener.SetHighscores)
  100.         window.opener.SetHighscores("Sudoku","",i,-1);
  101.     }
  102.     alert("Super, you solved this game in "+i+ " seconds !");
  103.   }
  104. }  
  105.  
  106. function IsSolved()
  107. { var ii,jj,kk,ll,nn;
  108.   bb=new Array(10);
  109.   for (ii=0; ii<2; ii++)
  110.   { for (jj=0; jj<2; jj++)
  111.     { for (nn=0; nn<10; nn++) bb[nn]=0;
  112.       for (kk=0; kk<2; kk++)
  113.       { for (ll=0; ll<2; ll++)
  114.           bb[Math.abs(Fld[ii][jj][kk][ll])]++;
  115.       }
  116.       if (bb[0]>0) return(false);
  117.       for (nn=1; nn<10; nn++) 
  118.       { if (bb[nn]!=1) return(false);
  119.       }
  120.     }
  121.   }
  122.   for (ii=0; ii<2; ii++)
  123.   { for (kk=0; kk<2; kk++)
  124.     { for (nn=1; nn<10; nn++) bb[nn]=0;
  125.       for (jj=0; jj<2; jj++)
  126.       { for (ll=0; ll<2; ll++)
  127.           bb[Math.abs(Fld[ii][jj][kk][ll])]++;
  128.       }
  129.       for (nn=1; nn<10; nn++) 
  130.       { if (bb[nn]!=1) return(false);
  131.       }
  132.     }
  133.   }
  134.   for (jj=0; jj<2; jj++)
  135.   { for (ll=0; ll<2; ll++)
  136.     { for (nn=1; nn<10; nn++) bb[nn]=0;
  137.       for (ii=0; ii<2; ii++)
  138.       { for (kk=0; kk<2; kk++)
  139.           bb[Math.abs(Fld[ii][jj][kk][ll])]++;
  140.       }
  141.       for (nn=1; nn<10; nn++) 
  142.       { if (bb[nn]!=1) return(false);
  143.       }
  144.     }
  145.   }
  146.   return(true);
  147. }
  148.  
  149. function Show()
  150. { if (IsOver)
  151.   { alert("Everything's okay.");
  152.     return;
  153.   }
  154.   for (i=0; i<2; i++)
  155.   { for (j=0; j<2; j++)
  156.     { for (k=0; k<2; k++)
  157.       { for (l=0; l<2; l++)
  158.           Fld[i][j][k][l]=PreFld[i][j][k][l];
  159.       }
  160.     }
  161.   }
  162.   IsOver=true;
  163.   I_Sel=-1;
  164.   RefreshScreen();
  165.   alert(" TIM solved it for you!");
  166. }
  167.  
  168. function SwitchI(ii0,ii1)
  169. { var jj,kk,ll,tt;
  170.   for (jj=0; jj<2; jj++)
  171.   { for (kk=0; kk<2; kk++)
  172.     { for (ll=0; ll<2; ll++)
  173.       { tt=PreFld[ii0][jj][kk][ll];
  174.         PreFld[ii0][jj][kk][ll]=PreFld[ii1][jj][kk][ll];
  175.         PreFld[ii1][jj][kk][ll]=tt;
  176.       }
  177.     }
  178.   }
  179. }
  180.  
  181. function SwitchJ(jj0,jj1)
  182. { var ii,kk,ll,tt;
  183.   for (ii=0; ii<2; ii++)
  184.   { for (kk=0; kk<2; kk++)
  185.     { for (ll=0; ll<2; ll++)
  186.       { tt=PreFld[ii][jj0][kk][ll];
  187.         PreFld[ii][jj0][kk][ll]=PreFld[ii][jj1][kk][ll];
  188.         PreFld[ii][jj1][kk][ll]=tt;
  189.       }
  190.     }
  191.   }
  192. }
  193.  
  194. function SwitchK(ii,kk0,kk1)
  195. { var jj,ll,tt;
  196.   for (jj=0; jj<2; jj++)
  197.   { for (ll=0; ll<2; ll++)
  198.     { tt=PreFld[ii][jj][kk0][ll];
  199.       PreFld[ii][jj][kk0][ll]=PreFld[ii][jj][kk1][ll];
  200.       PreFld[ii][jj][kk1][ll]=tt;
  201.     }
  202.   }
  203. }
  204.  
  205. function SwitchL(jj,ll0,ll1)
  206. { var ii,kk,tt;
  207.   for (ii=0; ii<2; ii++)
  208.   { for (kk=0; kk<2; kk++)
  209.     { tt=PreFld[ii][jj][kk][ll0];
  210.       PreFld[ii][jj][kk][ll0]=PreFld[ii][jj][kk][ll1];
  211.       PreFld[ii][jj][kk][ll1]=tt;
  212.     }
  213.   }
  214. }
  215.  
  216. function MixNumbers()
  217. { var nn,tt,ii,jj,kk,ll,rr=new Array(0,1,2,3,4);
  218.   for (nn=0; nn<48; nn++)
  219.   { ii=1+Math.floor(Math.random()*4);
  220.     jj=1+Math.floor(Math.random()*4);
  221.     tt=rr[ii];
  222.     rr[ii]=rr[jj];
  223.     rr[jj]=tt;
  224.   }
  225.   for (ii=0; ii<2; ii++)
  226.   { for (jj=0; jj<2; jj++)
  227.     { for (kk=0; kk<2; kk++)
  228.       { for (ll=0; ll<2; ll++)
  229.         { tt=PreFld[ii][jj][kk][ll];
  230.           PreFld[ii][jj][kk][ll]=rr[tt];
  231.         }
  232.       }
  233.     }
  234.   }    
  235. }
  236.  
  237. function random(nn)
  238. { return(Math.floor(Math.random()*nn));
  239. }
  240.  
  241. function Scramble()
  242. { var ff=0, ss, tt, vv0, vv1, vv2;
  243.   for (i=0; i<2; i++)
  244.   { for (j=0; j<2; j++)
  245.     { for (k=0; k<2; k++)
  246.       { for (l=0; l<2; l++)
  247.           PreFld[i][j][k][l]=PreFld0[i][j][k][l];
  248.       }
  249.     }
  250.   }
  251.   for (j=0; j<2; j++)
  252.   { tt=PreFld[0][j][0][0];
  253.     for (k=0; k<1; k++)
  254.       PreFld[0][j][k][0]=PreFld[0][j][k+1][0];
  255.     PreFld[0][j][2][0]=tt;
  256.   }
  257.   for (j=0; j<2; j++)
  258.   { tt=PreFld[0][j][2][2];
  259.     for (k=1; k>0; k--)
  260.       PreFld[0][j][k][2]=PreFld[0][j][k-1][2];
  261.     PreFld[0][j][0][2]=tt;
  262.   }
  263.   for (ff=0; ff<54; ff++)
  264.   { j=random(2);
  265.     k=random(2);
  266.     vv0=PreFld[0][j][k][1];
  267.     vv1=PreFld[0][j][k][2];
  268.     if (PreFld[1][j][(k+2)%3][1]==vv1)
  269.     { vv2=PreFld[1][j][(k+2)%3][2];
  270.       for (tt=0; tt<2; tt++)
  271.       { if ((PreFld[2][j][tt][1]==vv2)&&(PreFld[2][j][tt][2]==vv0))
  272.         { PreFld[0][j][k][1]=vv1;
  273.           PreFld[0][j][k][2]=vv0;
  274.           PreFld[1][j][(k+2)%3][1]=vv2;
  275.           PreFld[1][j][(k+2)%3][2]=vv1;
  276.           PreFld[2][j][tt][1]=vv0;
  277.           PreFld[2][j][tt][2]=vv2;
  278.         }
  279.       }
  280.     }
  281.     j=random(2);
  282.     k=random(2);
  283.     vv0=PreFld[0][j][k][0];
  284.     vv1=PreFld[0][j][k][1];
  285.     if (PreFld[1][j][k][0]==vv1)
  286.     { vv2=PreFld[1][j][k][1];
  287.       for (tt=0; tt<2; tt++)
  288.       { if ((PreFld[2][j][tt][0]==vv2)&&(PreFld[2][j][tt][1]==vv0))
  289.         { PreFld[0][j][k][0]=vv1;
  290.           PreFld[0][j][k][1]=vv0;
  291.           PreFld[1][j][k][0]=vv2;
  292.           PreFld[1][j][k][1]=vv1;
  293.           PreFld[2][j][tt][0]=vv0;
  294.           PreFld[2][j][tt][1]=vv2;
  295.         }
  296.       }
  297.     }
  298.   }  
  299.   for (ff=0; ff<3; ff++)
  300.   { i=random(2);
  301.     j=random(2);
  302.     if (i!=j) SwitchI(i,j);
  303.     i=random(2);
  304.     j=random(2);
  305.     if (i!=j) SwitchJ(i,j);
  306.     i=random(2);
  307.     k=random(2);
  308.     l=random(2);
  309.     if (k!=l) SwitchK(i,k,l);
  310.     j=random(2);
  311.     k=random(2);
  312.     l=random(2);
  313.     if (k!=l) SwitchL(j,k,l);    
  314.   }
  315.   MixNumbers();
  316.   for (i=0; i<2; i++)
  317.   { for (j=0; j<2; j++)
  318.     { for (k=0; k<2; k++)
  319.       { for (l=0; l<2; l++)
  320.           Fld[i][j][k][l]=PreFld[i][j][k][l];
  321.       }
  322.     }
  323.   }
  324.   ff=0;
  325.   while (ff<40)
  326.   { i=Math.floor(Math.random()*2);
  327.     j=Math.floor(Math.random()*2);
  328.     k=Math.floor(Math.random()*2);
  329.     l=Math.floor(Math.random()*2);
  330.     if (Fld[i][j][k][l]>0) { Fld[i][j][k][l]=0; ff++; }
  331.     if (Fld[2-i][2-j][2-k][2-l]>0) { Fld[2-i][2-j][2-k][2-l]=0; ff++; }
  332.     if (Fld[j][i][l][k]>0) { Fld[j][i][l][k]=0; ff++; }
  333.     if (Fld[2-j][2-i][2-l][2-k]>0) { Fld[2-j][2-i][2-l][2-k]=0; ff++; }
  334.   }
  335.   I_Sel=-1;
  336.   IsOver=false;
  337.   RefreshScreen();
  338.   Now = new Date();
  339.   StartTime = Now.getTime() / 1000;
  340. }
  341.  
  342. function RefreshScreen()
  343. { for (i=0; i<2; i++)
  344.   { for (j=0; j<2; j++)
  345.     { for (k=0; k<2; k++)
  346.       { for (l=0; l<2; l++)
  347.         { window.document.images[4*i+24*j+k+2*l].src = NPic[Fld[i][j][k][l]].src;
  348.         }
  349.       }
  350.     }
  351.   }
  352. }
  353. function Help()
  354. { alert("Put the missing Czech letters into the grid"+
  355.       "\nso that every letter occurs once in every row"+
  356.       "\nand column and in every 2x2 block."+
  357.       "\nThe `A means Put answer here.");
  358. }
  359. </script>
  360.  
Mar 5 '07 #1
3 1547
tpgames
785 Contributor
The rest of the code, as I have no clue where my error might be.
Expand|Select|Wrap|Line Numbers
  1.  </head>
  2. <BODY bgcolor="#eeddcc">
  3.  
  4. <form>
  5. <DIV ALIGN=center>
  6. <table border=0 cellpadding=4 cellspacing=0 align=center><tr><th colspan=3>
  7. <script language="JavaScript">
  8. document.open("text/plain");
  9. document.writeln("<table border=0 cellpadding=0 cellspacing=1 bgcolor='#000000'><tr><th><table border=0 cellpadding=0 cellspacing=2>");
  10. for (j=0; j < 2; j++)
  11. { document.writeln("<tr>");
  12.   for (i=0; i < 2; i++)
  13.   { document.writeln("<th><table border=0 cellpadding=0 cellspacing=0>");
  14.     for (l=0; l<2; l++)
  15.     { document.writeln("<tr>");
  16.       for (k=0; k<2; k++)
  17.         document.writeln("<th><IMG src=\"rebu_n.gif\" border=0 onMouseDown=\"Clicked("+i+","+j+","+k+","+l+")\"></th>");
  18.       document.writeln("</tr>");
  19.     }
  20.     document.writeln("</table></th>");
  21.   }
  22.   document.writeln("</tr>");
  23. }
  24. document.writeln("</table></th></tr></table></th></tr>");
  25. document.writeln("<tr><th colspan=3><table border=0 cellpadding=0 cellspacing=1>");
  26. document.writeln("<tr align=center>");
  27. for (i=1; i < 5; i++)
  28. document.writeln("<td><IMG src=\"rebu"+eval(i)+"n.gif\" border=0 onMouseDown=\"KeyDown("+eval(48+i)+")\"></td>");
  29. document.writeln("</tr>");
  30. document.writeln("</table></th></tr>");
  31.  
  32. if (navigator.appName == "Konqueror")
  33. { document.write("<tr><td colspan=3><input width=0 height=0 style=\"width:0; height:0\" name=\"KeyCatch\" onBlur=\"KeyCatchFocus()\" onKeyUp=\"KeyCatchChange()\"></td></tr>");
  34.   KeyCatchFocus();
  35. }
  36. function KeyCatchFocus()
  37. { setTimeout("document.forms[0].KeyCatch.focus()",100);
  38. }
  39. function KeyCatchChange()
  40. { var vv=""+document.forms[0].KeyCatch.value;
  41.   if (vv=="") return;
  42.   KeyDown(vv.charCodeAt(0));
  43.   document.forms[0].KeyCatch.value="";
  44. }
  45.  
  46. document.close();
  47. </script>
  48. <tr>
  49. <th><input type=button value="NEW" width=70 style="width:70" onClick="javascript:Scramble()"></th>
  50. <th><input type=button value="SOLVE IT" width=90 style="width:90" onClick="javascript:Show()"></th>
  51. <th><input type=button value="RULES" width=70 style="width:70" onClick="javascript:Help()"></th>
  52. </tr>
  53.  
  54. <tr>
  55. <td class="tpmarble"><a href="http://www.tpgames.net/gaming/2/labnav.html"> Games </a></td>
  56. <td class="tpmarble"><a href="http://www.tpgames.net/gaming/2/puzzlers/sudoku/sudoku.html"> Sudoku </a></td>
  57. <td class="tpmarble"><a href="http://www.tpgames.net/gaming/2/puzzlersnav.html"> Puzzlers </a></td>
  58. </tr>
  59.  
  60.  
  61. </table>
  62. </DIV>
  63. </form>
  64. <script language="JavaScript">
  65.   Scramble();
  66. </script>
  67. </BODY>
  68. </HTML>
Mar 5 '07 #2
ronverdonk
4,258 Recognized Expert Specialist
With this size of code (no of lines) shown, I am bound to ask you:

what have you done so far to pinpoint the area in which the problem is occurring? Like traces, traps, debug texts, etc.

Ronald :cool:
Mar 5 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
You're converting a 3x3 script to a 2x2, so make sure you understand what's going on in the 3x3 one first before attempting to make any changes.

There's some keyboard checking code which is not the best. You should never use browser sniffing except as a last resort. You can check for the key pressed using a cross-browser method using object detection using something similar to the code in this link.
Mar 6 '07 #4

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

Similar topics

44
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with...
2
by: Wallace Pipp | last post by:
Hello all, I created a bitmap with my control, but the bitmap(MyControl.bmp) doesn't show up on the toolbar. Here's what I tried: public class MyControl : System.Windows.Forms.Control {...
2
by: Jim | last post by:
My browser doesn't show text boxes, labels etc. It seems that it doesn't read the script at all (C#). I use the following program (from a wrox book): <----------------------------------------...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
2
by: Tammam | last post by:
Hello, I converted a web solution from VS2003 to VS2005. The conversion process proceeded successfully with no errors and the new VS2005 solution builds with no error. When trying to run it, the...
1
by: maldita | last post by:
I am a newbie and I have created this page in asp.net and have several problems with it. http://i71.photobucket.com/albums/i153/werdina/p.jpg 1) How do I make the email show up so that when...
0
by: =?Utf-8?B?c2hhZG93?= | last post by:
After migrating my project from VS2003 to VS2005, the images in my aspx pages don't show (only a red X is shown). But the images show up inside the Visual Studio View Designer. This is the aspx...
0
by: Sin Jeong-hun | last post by:
http://misako.co.kr/externaldata/Test.aspx I've created a very simple user control which just has a label on it. I followed the instruction but it doesn't show up. I don't know what's wrong...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.