The original game worked for 15 tile sliding game. I wanted a 24 tile game. What's wrong? - var tiles = [[],[],[],[],[]];
-
var grid = [[],[],[],[],[]];
-
-
var game = document.createElement("div");
-
game.className = "game";
-
game.style.position = "absolute"; // give tiles something to "stick" to
-
game.style.width = width + "px";
-
game.style.height = height + "px";
-
-
-
var theEmptyT, emptyp, emptyq;
-
-
for (var i=0; i<5; ++i)
-
for (var j=0; j<5; ++j)
-
{
-
var t = document.createElement("div");
-
var x = i * tileWidth;
-
var y = j * tileHeight;
-
-
t.style.position = "absolute";
-
t.style.width = tileWidth + "px";
-
t.style.height = tileHeight + "px";
-
-
t.style.backgroundImage = "url(" + im.src + ")";
-
t.style.backgroundAttachment = "scroll";
-
t.style.backgroundPosition = "-" + x + "px -" + y + "px";
-
t.style.backgroundRepeat = "no-repeat";
-
-
// setting using shorthand works in ie but not in moz:
-
// t.style.background = "url(" + im.src + ") scroll -" + x + " -" + y + " no-repeat";
-
-
t.className = "tile";
-
-
if (i == 4 && j == 4)
-
{
-
t.style.display = "none"; // hide last block until game is over
-
t.isEmpty = true;
-
theEmptyT = t;
-
t.className = "empty";
-
}
-
-
// i,j is original position. used to determine when you've won.
-
t.i = i;
-
t.j = j;
-
// p,q is current position. initially set by repositionAll();
-
-
grid[i][j] = t;
-
-
t.onclick =
-
function()
-
{
-
var p = this.p;
-
var q = this.q;
-
if (p == emptyp) // horizontally in line with empty square
-
{
-
if (q < emptyq) // empty square is to my right
-
for (j=emptyq; j!=q; --j)
-
grid[emptyp][j] = grid[emptyp][j - 1];
-
else
-
for (j=emptyq; j!=q; ++j)
-
grid[emptyp][j] = grid[emptyp][j + 1];
-
grid[p][q] = theEmptyT;
-
}
-
else if (this.q == emptyq) // vertically in line with empty square
-
{
-
if (p < emptyp) // empty square is to my right
-
for (i=emptyp; i!=p; --i)
-
grid[i][emptyq] = grid[i - 1][emptyq];
-
else
-
for (i=emptyp; i!=p; ++i)
-
grid[i][emptyq] = grid[i + 1][emptyq];
-
grid[p][q] = theEmptyT;
-
}
-
repositionAll();
-
}
-
-
game.appendChild(t);
-
} // huge for loop to create tiles
-
-
-
-
function repositionAll()
-
{
-
var correct = 0, i, j;
-
-
for (i=0; i<5; ++i)
-
for (j=0; j<5; ++j)
-
{
-
t = grid[i][j];
-
if (t.p != i)
-
{
-
if (t.p != null && !t.isEmpty)
-
gradual(t.style, "left", tileWidth * t.p, tileWidth * i)
-
else
-
t.style.left = tileWidth * i + "px";
-
t.p = i;
-
}
-
if (t.q != j)
-
{
-
if (t.q != null && !t.isEmpty)
-
gradual(t.style, "top", tileHeight * t.q, tileHeight * j)
-
else
-
t.style.top = tileHeight * j + "px";
-
t.q = j;
-
}
-
if (t.isEmpty)
-
{
-
emptyp = i;
-
emptyq = j;
-
}
-
if (t.i == i && t.j == j)
-
++correct;
-
}
-
-
theEmptyT.style.display = (correct == 25) ? "block" : "none";
-
game.style.borderColor = (correct == 25) ? "lightgreen" : "black";
-
}
-
-
-
repositionAll();
-
-
if (scramble)
-
{
-
-
// CAN'T FIGURE OUT WHAT NUMBERS GOES HERE?
-
for (var s = 0; s < 128; ++s)
-
{
-
var r = Math.random();
-
var sp, sq;
-
if (r < .5)
-
{
-
sp = emptyp + (r < .25 ? 1 : -1);
-
sq = emptyq;
-
}
-
else
-
{
-
sp = emptyp;
-
sq = emptyq + (r > .75 ? 1 : -1);
-
}
-
-
// "reflect" if try to swap with something outside of board Changed 2 to 3, 4 to 5.
-
if (sp == -1) sp = 1;
-
if (sp == 5) sp = 3;
-
if (sq == -1) sq = 1;
-
if (sq == 5) sq = 3;
-
-
var swaptemp = grid[sp][sq];
-
grid[sp][sq] = grid[emptyp][emptyq];
-
grid[emptyp][emptyq] = swaptemp;
-
-
emptyp = sp;
-
emptyq = sq;
-
}
-
} // if scramble
-
-
repositionAll();
-
-
var par = im.parentNode;
-
par.insertBefore(game, im);
-
par.removeChild(im);
-
-
} // function makeGame
-
-
-
-
-
function replaceImage()
-
{
-
var url = document.f.image.value;
-
var im = document.createElement("img");
-
-
var h = document.getElementById("imageHolder");
-
while (h.firstChild)
-
h.removeChild(h.firstChild);
-
h.appendChild(im);
-
-
im.onload = function() { makeGame(this); }
-
im.src = url;
-
}
Original code: http://www.tpgames.net/gaming/2/15squares/1.html
My altered code: http://www.tpgames.net/gaming/2/15sq...24squares.html -- Edited by iam_clint: Fixed link 4 1391
Okay, what do I need to change, in order to get any response to this post? LOL
1) It is NOT a school assignment. I graduated years ago.
2) I am trying to learn JS and have tried several different changes to the code and can't figure it out.
3) I do know that the [ ] [ ] does get the 25 boxes I need. Apparently, that seems to be the only thing that is working.
Thanks!
iam_clint 1,208
Recognized Expert Top Contributor
sorry i didn't reply to your post sooner i haven't been around in a day or so.
I played the game alittle bit and i don't fully understand what the problem is....
please elaborate what is happening in your game and what you want it to be doing.
Here is the link to the 15 square puzzle the works properly. http://www.tpgames.net/gaming/2/15sq...quaresnav.html
I want the 24 piece puzzle to work exactly like the 15 square puzzle. The script doesn't divide the puzzle into 25 pieces, and blank out the 25th piece like it should. Also, the puzzle pieces don't always move how they should, in that the game sees one spot as blank, but I see lots of blanks.
(I came down with a bad cold, so couldn't get back to this one right away.)
What I mean is that one image will be in square 25, but won't move to square 24 or any other square.
A image in squares 1 - 4, 6 - 9, 11 - 14, 16 - 19 move correctly.
Images in squares 5, 10, 15, and 20 - 25 do not move properly always. (counting the squares from left to right, top to bottom).
Thanks! :>)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: frank.baris |
last post by:
I usually can figure out anything by searching the groups or the net
all day, but this problem has been bugging me for awhile now.
I have multiple databases, all of which have the same 2 tables, and all
the same fields and field types. Each database holds a particular
vendors data, lets call them VDB1, VDB2, ... VDBX. Then I have a temp...
|
by: tlotr |
last post by:
Can I get my local IP address from javascript under IE? I've some pieces of
code that work under netscape, but it doesnt under ie.
Thanks in advance,
tlotr
|
by: Cigar |
last post by:
I am developing a program for a client. She runs a shop where her
clients bring in items for sale or short term buyback. Development of
the program has been going great but she's mentioned that there is a
'feature' coming up in the next couple of weeks that she'd like me to
implement that has me a bit worried.
My client has told me a...
|
by: mattrapoport |
last post by:
I have a page with a div on it. The div displays a user comment. When
the user logs into this page, their current comment is pulled from a db
and displayed in the div. The user can edit the comment through a
pop-up that contains a textarea. When the user hits OK on the pop-up,
the text in the textarea is sent to a function on the main...
|
by: aramsey |
last post by:
I have a javascript program that works fine under Firefox and on IE
when running XP, but is having a problem with IE running under Windows
2000 Pro.
On my personal XP development machine I have the Microsoft Script
Editor and I can set a breakpoint, step through code, inspect
variables, etc... with no problem.
On a machine where I am...
| |
by: RMWChaos |
last post by:
Previously, I had used independent JSON lists in my code, where the lists were part of separate scripts. Because this method did not support reuse of a script without modification, I decided to consolidate all my JSON lists into one and modify my scripts so that they were more generic and reusable. So far so good.
The problem is that my JSON...
|
by: TriAdmin |
last post by:
The return from a curl() cal
is:https_Ordernumber=https_card_number=**************https_exp_date=1218https_amount=40.54https_customer_code=https_salestax=https_result=8https_result_message=NOT...
|
by: Lawrence Krubner |
last post by:
Does anything about this script look expensive, in terms of resources or
execution time? This script dies after processing about 20 or 25
numbers, yet it leaves no errors in the error logs. This is on a server
that handles a fairly demanding site. The defaults, in php.ini, have all
been cranked fairly high: scripts get 180 seconds to run, and...
|
by: Chris Seymour |
last post by:
Hi All,
I am working on a python script for my colleague that will walk a
directory and search in the different files for a specific string.
These pieces I am able to do. What my colleague wants is that when
she runs the script the filename is replaced by the current file that
is being processed. So instead of seeing a series of files being...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |