Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    puzzle javascript urgent

    This is a code I wrote about a javascript game which you should click on each picture so that the puzzle will be done. I have nine pictures with each picture named 1.jpg 2.jpg --- 9.jpg
    I have three difficulties beginner intermediate hard . The code has logical errors I can't understand . can anybody help me

    <html>
    <head>
    <title> CAIS326 Assignment 3 </title>
    <script type="text/javascript">
    <!--
    var seconds = 0;
    var timerId;
    var time;
    var Click1 = 0,Click2 = 0,Click3 = 0,Click4 = 0,Click5 = 0,Click6 = 0,Click7 = 0,Click8 = 0,Click9 = 0;
    var Pictures = [1,2,3,4,5,6,7,8,9];
    function SwapImages()
    {
    for(var q=0 ; q<9; q++)
    document.getElementById("image+q+").src = Pictures[Click+q+ -1]+".jpg";

    }
    function RegisterClicks(Index)
    {
    if (Click1 == 0)
    Click1 = Index;

    else if (Click2 == 0)
    Click2 = Index;

    else if (Click3 == 0)
    Click3 = Index;

    else if (Click4 == 0)
    Click4 = Index;

    else if (Click5 == 0)
    Click5 = Index;
    else if (Click6 == 0)
    Click6 = Index;
    else if (Click7 == 0)
    Click7 = Index;
    else if (Click8 == 0)
    Click8 = Index;
    else if (Click9 == 0)
    Click9 = Index;
    for(var m=0; m<9; m++)
    {

    if (Click+m+ > 0 && Click+m + 1+ > 0){
    SwapImages();
    Click+m+ = 0;
    Click+m + 1+ = 0;
    }
    }


    }

    function startTimer() {
    if (document.form1.gamelevel[0].checked)
    time=60;
    else if (document.form1.gamelevel[1].checked)
    time=45;
    else
    time=30;

    // 1000 milliseconds = 1 second
    timerId = window.setInterval( "updateTime()", 1000 );
    }

    function updateTime() {
    seconds++;
    soFar.innerText = seconds;

    if ( time == seconds)
    {
    seconds = 0;
    window.alert ("Game over Loser...");
    clearTimeout(timerId);
    }
    }


    var array = new Array(9);

    for (var i=0; i<9; i++)
    {
    array[i] = i+1;
    }
    shuffle();
    document.writeln("<table border=1>");
    var b = 0;
    while (b < 9 )
    {
    var num = array[b];
    document.writeln("<tr><td><img src=\""+num+".jpg\" id =\"image"+num+" \" onClick=\"RegisterClicks("+num+")\" /></td>");
    ++b;
    num = array[b];
    document.writeln("<td><img src=\""+num+".jpg\" id =\"image"+num+" \" onClick=\"RegisterClicks("+num+")\" /></td>");
    ++b;
    num = array[b];
    document.writeln("<td><img src=\""+num+".jpg\" id =\"image"+num+" \" onClick=\"RegisterClicks("+num+")\" /></td></tr>");
    ++b;
    }
    document.writeln("</table>");
    function shuffle()
    {
    var k = 9;
    var RandNum;
    var Temp;
    for (var n=0; n<9; n++)
    {
    RandNum = Math.floor(Math.random()*k);

    Temp = array[k-1];
    array[k-1] = array[RandNum];
    array[RandNum] = Temp;
    k=k-1;
    }
    }

    //-->
    </script>
    </head>
    <body>
    <form name = "form1" action = "">
    <input type="Radio" name = "gamelevel" Value = "Beginner" Checked = "true" />
    <font color=#37448E>Beginner</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="Radio" name = "gamelevel" Value = "Intermediate" />
    <font color=#37448E>Intermediate</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="Radio" name = "gamelevel" Value = "Advanced" />
    <font color=#37448E>Advanced</font></div><br/><br/>
    <input type = "button" value = " start " onClick="startTimer()"/><br/>

    <p>Seconds you have spent viewing this page so far:
    <strong id = "soFar">0</strong></p>

    </form>

    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    It would help if you said what the errors are, what is the expected behviour and what actually happens.

    BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.



    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 12-16-2010 at 08:10 AM.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs down coding forums ignorant staff

    Quote Originally Posted by Philip M View Post
    It would help if you said what the errors are, what is the expected behviour and what actually happens.

    BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.



    It is your responsibility to die() if necessary….. - PHP Manual
    I don't know what is the point of such website if you are unable to reply on any good question, and you are always putting restrictions - that reflects inability to provide answers.

    I suggest to close this site or to change the illeterate staff like you philip !!!

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    You seem to be under the mistaken impression that this site has "staff" and is some sort of free public service. Not so. Everyone here is contributing his unpaid voluntary time and expertise. That means that there is no obligation to respond to any query, especially those where the OP is rude or those which ignore the forum rules and guidelines.

    Did you not notice that no-one apart from myself has even bothered to respond to your query?

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    You seem to be under the mistaken impression that this site has "staff" and is some sort of free public service. Not so. Everyone here is contributing his unpaid voluntary time and expertise. That means that there is no obligation to respond to any query, especially those where the OP is rude or those which ignore the forum rules and guidelines.

    Did you not notice that no-one apart from myself has even bothered to respond to your query?
    No body answered because you closed the road in front of them . U said that I should change my query because it was invalid so nobody bothered after seeing this. Second of all if you don't know how to answer , don't but don't you ever put restrictions on other contributors because you don't know how to answer.!

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by achanos View Post
    No body answered because you closed the road in front of them . U said that I should change my query because it was invalid so nobody bothered after seeing this. Second of all if you don't know how to answer , don't but don't you ever put restrictions on other contributors because you don't know how to answer.!
    The "restrictions" (that is the forum rules and guidelines) are laid down by the forum administrator, not by me. The request to use [ code ] tags is, as I explained, to help us to help you. As for the rest, you really ought to see your doctor.

    You ought to understand that newcomers to any group or organisation (especially adolescents) who start throwing their weight around are usually unpopular.

  • #7
    Regular Coder
    Join Date
    Dec 2007
    Posts
    137
    Thanks
    1
    Thanked 21 Times in 21 Posts
    Philip M was just offering advice to you in order how to ask for advice, like wrapping your code in the CODE tags so it's more readable. It is real taxing to try to read unformatted code. And also by not giving more details about your problem, the errors you are getting and expected behavior, we don't have enough information to give you an answer.

    It's like going to a car mechanic and saying, "something is wrong with my car, but I'm not going to tell you what is wrong, find out yourself." And presenting us the code that is not formatted is making us do extra work, and is like saying to the mechanic, "by the way, my car isn't here, go pick it up at my house yourself".

    The rules and posting guildelines are stickied on top of the forum, and also there is an alert message on the posting form itself saying to read them before posting. I don't know Philip M but looking at his stats, he's been thanked over a thousand times on this board, so he is honestly trying to help you and many others.

  • Users who have thanked pigpen for this post:

    Philip M (12-19-2010)

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    I didn't even bother to TRY to answer the original post because (a) He never stated what the purpose of the game is, (b) he never stated in what way the code doesn't do what it's supposed to, and (c) it is *HOMEWORK*!!! [Note the <title>: CAIS326 Assignment 3] and rule 1.5 of this forum says we do not do homework.

    *IF* he had stated "when you click on X then Y is supposed to happen but instead Z happens," then maybe he would have gotten an answer. But to expect us to do his homework for him--and to not even bother to tell us what the assignment is--well, I think he got more help than he deserved.

    And by the way, I *still* don't understand what the purpose of the game is.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    We do not do homework but as I understand it there is nothing wrong with offering guidance, hints and a reasonable amount of corrections.

    I did try to suggest how he might encourage a more helpful response, and got a mouthful of abuse for my pains.

    Quote Originally Posted by pigpen View Post
    .. so he is honestly trying to help you ..
    Well, no, not any more he ain't .........

  • #10
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by achanos View Post
    This is a code I wrote about a javascript game which you should click on each picture so that the puzzle will be done. I have nine pictures with each picture named 1.jpg 2.jpg --- 9.jpg
    I have three difficulties beginner intermediate hard . The code has logical errors I can't understand.
    Presumably this is the sliding image puzzle assignment that's currently doing the rounds. I don't know how you can tell that there are logical errors, since there are indicated syntax errors that prevent it even starting. Weren't you taught to use the error console?

    I thought I'd have a stab at this one myself. It only needs one image and the 'difficulty' level doesn't use a timer :
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>That Image Slider Puzzle</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    <style type='text/css'>
    body{background-color:#ccc}
    </style>
    </head>
    <body>
    <h1>It's That Image Slider Puzzle</h1>
    <h2 id='jsw' style='text-decoration:blink;color:#f00'>Enable Javascript</h2>
    <form action=''>
    <p>
     <input type='text' name='thePic' > &lt;- Enter the URL of any image anywhere, or select from the list below.
    <p> 
     <select name='examples' onchange='if(this.value)thePic.value=this.value;'>
      <option value=''>Example Images</option>
      <option value='http://www.inetours.com/England/London/images/BgBn/Big_Ben_face_8381.jpg'>A</option>
      <option value='http://img.dailymail.co.uk/i/pix/2008/02_02/kaplinsDM1202_468x727.jpg'>B</option>
      <option value='http://img638.imageshack.us/img638/3985/formula1carsengineering.jpg'>C</option>
     </select>
    <p> 
     <select name = 'rigour' id = 'rigour' onchange='btn.onclick()'>
      <option value='3'>Easy</option>
      <option value='5'>Not so easy</option>  
     </select> <label for='rigour'>Set Difficulty Level</label>
    <p>
     <input type='button' name='btn' onclick='new puzzle( "theGame", thePic.value, rigour.value );' value='Download Image & Start Puzzle'>
    </form>
    <div id='theGame' style='border:none;background-color:#cc0'></div>
    
    <script type='text/javascript'>
    
    document.getElementById('jsw').style.display = 'none';
    
    function puzzle( containerId, img, gridSize )
    {
     this.$ = function( id )
     {
      return document.getElementById( id );
     }
       
     this.rows = Math.max( 3, gridSize );
     this.cols = this.rows;
     this.container;
     
     this.image = new Image();
     this.cellCount = this.rows * this.cols;
     this.blankXOffset;
     this.blankYOffset;
     
     this.container = this.$( containerId );
     
     this.divGroup = this.container.childNodes;
     
     this.container.style.position = 'relative';
    
     this.build = function( /*2843294C6F67696320416C69*/ )
     {  
      var w = this.image.width,
          cellWidth = Math.floor( w / this.cols ),      
          h = this.image.height,
          cellHeight = Math.floor( h / this.rows ),
          src = this.image.src,
          newDiv,
          that = this;
      
      this.container.style.width = this.image.width + 'px';   
      this.container.style.height = this.image.height + 'px';   
      
      while( this.container.firstChild )
       this.container.removeChild( this.container.firstChild );
    
      for( var i = 0; i < this.cellCount ; i++ )
      {
       newDiv = document.createElement( 'div' );
    
       with( newDiv.style )
       {
        position = 'absolute';
        width = cellWidth + 'px';
        height = cellHeight + 'px';
        backgroundImage = 'url("' + src + '")';
        backgroundRepeat = 'no-repeat';
        this.left = ( ( i % this.cols ) *  cellWidth );
        left = this.left +'px';
        this.top = ( Math.floor( i / this.rows ) *  cellHeight );       
        top =  this.top + 'px';
        
        backgroundPosition = ( i != this.cellCount - 1 ) 
                              ? ( -this.left + "px " + (-this.top) + "px" )
                              : cellWidth + "px " + cellHeight + "px ";
       }
    
       if( i == this.cellCount - 1  )
       {
        this.blankXOffset = -this.left;  
        this.blankYOffset = -this.top;  
        newDiv.isBlank = true;
       }
       
       newDiv.truePos = i;   
       
       newDiv.onclick = function(){ if( !this.isBlank ){ that.scan( this ); } } 
       
       this.container.appendChild( newDiv );
    
       newDiv.style.backgroundImage = 'url("' + src + '")'; /* Required by Webkit; will not respond prior to attachment */   
      }
      
      this.shuffle();
     }
     
     this.scan = function( elem )
     {
      var blankOffset, elemOffset, cn = this.divGroup;
        
      for( var i = 0, len = this.cellCount; i <  len;  i++ )
      {
       if( cn[ i ] === elem )
        elemOffset = i+1;
        
       if( cn[ i ].isBlank ) 
        blankOffset = i+1
      }  
        
      if( Math.floor((blankOffset-1) / this.rows) == Math.floor((elemOffset-1) / this.rows) && Math.abs( blankOffset - elemOffset ) == 1  
          ||
          blankOffset % this.cols == elemOffset % this.cols && Math.abs( blankOffset - elemOffset ) == this.cols )
      {  
       this.swap( cn[ blankOffset-1 ], cn[ elemOffset-1 ] ); 
      }
      else
       { /**/ }
      
      
      for( var i = 0, len = cn.length ; i < len && cn[ i ].truePos == i; i++ )
      ;
      
      if( i == len )
      {
       cn[ i-1 ].style.backgroundPosition = this.blankXOffset + 'px ' + this.blankYOffset + 'px';  
       alert('You did it!');   
      }   
         
     }
     
     this.swap = function(a, b)
     {
      var tmp = {};
      
      tmp.truePos = b.truePos;
      tmp.offset = b.style.backgroundPosition;    
      tmp.isBlank = !!b.isBlank;
      
      b.truePos = a.truePos;
      b.style.backgroundPosition = a.style.backgroundPosition;
      b.isBlank = !!a.isBlank;
      
      a.truePos = tmp.truePos;
      a.style.backgroundPosition = tmp.offset;
      a.isBlank = tmp.isBlank;
     }
     
     this.shuffle = function()
     {
      var tmp;
        
      for( var max = this.divGroup.length - 2, i = max, n; i > -1; i-- )
      {
       while( ( n = Math.floor( Math.random() * max ) ) == i )
       ;    
       this.swap( this.divGroup[ i ], this.divGroup[ n ] );   
      }     
     }
     
     var that = this;
     
     this.image.onload = function(){ that.build(); }
     
     this.image.onerror = function(){ alert('Unable to load specified image.'); }
     
     this.image.src = img;
    }
    
    </script>
    </body>
    </html>
    Last edited by Logic Ali; 12-20-2010 at 04:42 PM. Reason: Added crutchware for webkit browsers

  • Users who have thanked Logic Ali for this post:

    achanos (12-20-2010)

  • #11
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I am also new to this forum too and I must say all the above persons are very right in all their stated facts. But guys lets forgive and forget the ignorance of the new and try to give him a second chance. He will learn from this mistake and I am sure he will never do it again. Help Him Please!!!

  • #12
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Logic Ali - the forum rules say that we should not do homework - that is supply an oven-ready solution. But no teacher would ever believe that your code is the OP's own work.

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Quote Originally Posted by Philip M View Post
    Logic Ali - ... But no teacher would ever believe that your code is the OP's own work.
    Heck, I don't even believe that's LogicAli's work. He clearly stole the from a textbook on writing complex code. <grin style="monstrous"/>



    (Sorry, LogicAli. It's beautiful. But also scary.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #14
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    First of all , thanks to Logic ali for his help. he is the only sane person.
    Philip M if you consider me a beginner , then what are you? a child or a nagging closed-minded nerd. I stated the purpose of my game in the first sentence and I abided by the forum laws.
    I am out of this forum , but I am happy that happened because you gave me the right image about you , and how intelligent you are !
    I don't even believe that the "old Pedant" accused logic ali of stealing while he-himself is a big illiterate and doesn't know anything about computers .

    One user said that I will learn from my mistake , I tell him/her I have never been wrong , Philip M and old pedant should learn from their mistakes by stop making excuses.
    Last edited by achanos; 12-20-2010 at 08:03 PM.

  • #15
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    I really really really hope you *ARE* foolish enough to turn in LogicAli's answer!!!

    You will flunk flunk flunk for not doing your own work.

    My comment about LogicAli stealing the code was a *JOKE*. That code is so advanced that half the people reading this forum couldn't (or at least wouldn't) write it. It's beautiful code, but no newbie in the world could/would write it.

    So you have now been wrong on several points. And you will be even more wrong when you turn in that answer.

    I feel sorry for you. Clearly you are a spoiled child who will now take his toys back to his room and sulk. You surely have no future in computing, since (as was said) you don't learn from your mistakes.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •