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.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sliding puzzle game

    Please can anyone help?

    hello I am novice when it comes to writing code and as i'm writing some code for a sliding puzzle game, i have managed to display the images.

    but now i need to write the functions to see if the image when clicked on is next to the blank one and then to move them if this is true.


    <Html>
    <Head>
    <Title> Sliding Puzzle Game</Title>

    <Script Language = "JavaScript">

    var images = new Array();
    //var initialise
    var id = 0;
    alert("starting");
    window.onerror = handleError;

    function handleError(strMessage, strURL, intLine)
    //the above function catches any errors and display what and where.
    {
    document.write("<br/>The following Error occurred:");
    document.write("<br/>Message: " + strMessage);
    document.write("<br/>Code: " + strURL);
    document.write("<br/>On line: " + intLine);
    }



    function Write2screen(){

    var k=0;

    for (i=0; i< 4; i++) {
    for (j=0; j<4; j++) {

    id++; //give picture unique id after each iteration

    images[k] = "Images/" + k + ".jpg";
    document.write(" <img src= '"+images[k]+"' id='"+id+"'/>");
    k++;
    }
    document.write("<br/>");
    }
    }



    function CanMoveTile() {
    // checks to see whether the cell at postion cellNum
    // is next to the black tile and returns true if and
    // only if this is the case

    }

    function moveTile(id) {
    // this function moves the tile that was clicked on (if the tile can actually be moved)

    }


    Write2screen();

    </Script>
    </Head>
    <body onClick=moveTile(id)>

    </body>
    </Html>


    many thanks in advance
    Last edited by Caligula; 12-12-2010 at 12:16 AM. Reason: changing title to be more pronounced

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    728
    Thanks
    35
    Thanked 132 Times in 123 Posts
    When document.write is called, the document is closed and a new one is written.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,159
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    To expand on mrhoo's comment:-

    document.write statements must be run before the page finishes loading. Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. So document.write is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.


    If you are a novice you have bitten off a very large mouthful. The code is not trivial.
    http://www.codingforums.com/showthread.php?t=136979


    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.



    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 12-12-2010 at 10:01 AM.


  •  

    LinkBacks (?)


    Posting Permissions

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