...

View Full Version : puzzle javascript urgent



achanos
12-16-2010, 07:21 AM
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>

Philip M
12-16-2010, 08:07 AM
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

achanos
12-18-2010, 10:38 AM
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 !!!

Philip M
12-18-2010, 11:57 AM
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?

achanos
12-18-2010, 02:02 PM
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.!

Philip M
12-18-2010, 05:28 PM
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.

pigpen
12-19-2010, 05:08 PM
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.

Old Pedant
12-19-2010, 08:20 PM
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.

Philip M
12-19-2010, 08:59 PM
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.


.. so he is honestly trying to help you ..
Well, no, not any more he ain't .........

Logic Ali
12-20-2010, 02:32 AM
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 :
<!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>

JSJobs.us
12-20-2010, 03:57 AM
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!!!

Philip M
12-20-2010, 07:37 AM
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. :D

Old Pedant
12-20-2010, 07:08 PM
Logic Ali - ... But no teacher would ever believe that your code is the OP's own work. :D

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.)

achanos
12-20-2010, 08:01 PM
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.

Old Pedant
12-20-2010, 08:23 PM
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.

achanos
12-20-2010, 08:35 PM
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.

DUDE IF YOU THINK THIS CODE IS ADVANCED THEN YOU ARE TRULY ILLITERATE IN COMPUTERS. This code is normal to me and I appreciate his help. If your IQ is low please leave the sciences field.

Please don't post more replies because I am done with you guys . and if I am not popular I would not have 16 reply !!!!!!!!

Bye and Peace to you all !

achanos
12-20-2010, 08:43 PM
got it??

Old Pedant
12-20-2010, 08:46 PM
Is there a place to list the most humorous posts of 2010? If so, I nominate post #16 in this thread. Granted, it has to be taken in combination with the first post, but it's still a winner.

Philip M
12-21-2010, 08:12 AM
Is there a place to list the most humorous posts of 2010? If so, I nominate post #16 in this thread. Granted, it has to be taken in combination with the first post, but it's still a winner.

Shame on you Old Pedant! It is no longer acceptable to mock or poke fun at unfortunate people with personality disorders, or those whose minds have lost touch with reality.

Old Pedant
12-21-2010, 07:10 PM
I wasn't going to reply further, but I just had to say: ROTFLMAO!!! I really and truly laughed out loud at that one, Philip!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum