pause eller hvad det hedder
Her er mit script, ja det er ikke mig der har lavet det hele, jeg har moddet lidt i det.if (!initialized) {
Initialize();
initialized = true;
}
function PieceX(col)
{
return xBase + col * xSpace;
}
function PieceY(row)
{
return yBase + row * ySpace;
}
// Subroutine Initialize
// Puzzle Initialization Code
function Initialize()
{
Congratulations.stop();
// Set dimensions of game grid
numRows = 3;
numCols = 3;
numCells = numRows*numCols;
xBase = p0._x;
yBase = p0._y;
xSpace = p0._width * 1.025;
ySpace = p0._height * 1.025;
// Create pieces
var c = 1;
var r = 0;
for (var i=1; i<numCells-1; i++) {
var name = "p" + i;
var newPiece = eval(name);
newPiece._x = PieceX(c);
newPiece._y = PieceY(r);
newPiece.PieceNumber = i+1;
if (++c >= numCols) {
c = 0;
r++;
}
}
// Set initial positions of each cell, including empty space
posArray = [];
for (i=0; i<numCells-1; i++) {
posArray[i] = i;
}
empty = numCells-1;
}
// Subroutine Winner
// Tests whether the current piece positions is a winning position (that is, every piece in sequence)
function isWinner()
{
for (var i = 0; i<numCells-1; i++) {
if (posArray[i] != i) {
return false;
}
}
return true;
}
// Subroutine Click
// Puzzle click handler.When a piece is clicked, determine if it is adjacent to the empty space. if it is, move it into the empty space.
// Check if this is a winner
function Click(clicked)
{
clicked--;
if (isWinner()) {
// Start a new game
timerstart();
shuffle();
// Get rid of the congratulations message
Congratulations.gotoAndStop(1);
} else {
// Get the position of the clicked piece
pos = posArray[clicked];
// Get row, column of empty spot
emptyRow = Math.floor(empty/numCols);
emptyCol = empty-emptyRow*numCols;
// Get row, column of clicked piece
clickedRow = Math.floor(pos/numCols);
clickedCol = pos-clickedRow*numCols;
// Test adjacency
// adjacent(i, j) = i is above j or i is below j, or i is left of j or i is right of j
rowDiff = Math.abs(clickedRow-emptyRow);
colDiff = Math.abs(clickedCol-emptyCol);
adjacent = (rowDiff+colDiff) == 1;
if (adjacent) {
// Move the movie clip for the piece
var piece = eval("/p" + clicked);
piece._x = PieceX(emptyCol);
piece._y = PieceY(emptyRow);
// Swap the clicked piece with the empty space
posArray[clicked] = empty;
empty = pos;
// If this is a winner, start the winning movie clip
if (isWinner()) {
timerstop();
jubii();
}
}
}
}
function jubii()
{
loadVariablesNum ("http://www.rc-internet.com/mini/variabel/submit.asp?variabel="+runningTid, 0);
getURL ("http://www.rc-internet.com/mini/variabel/resultat.asp", "_blank");
}
function timerstop()
{
_root.playTid = false;
}
function timerstart()
{
_root.startTid = getTimer();
_root.playTid = true;
}
function Shuffle()
{
// We want to arrange the cells in a random
// order. We do this by generating a random
// number r(i) for each cell i, and sorting
// the pairs (i, r(i)) using r(i) as the key.
// Comparison function for the sort
var cf = function (x, y) {
if (x[1] < y[1]) {
return -1;
} else if (x[1] > y[1]) {
return 1;
} else {
return 0;
}
}
var i;
var cell = [];
for (i=0; i<numCells; i++) {
cell.push([i, Math.random()]);
}
cell.sort(cf);
// We've sorted the ordered pairs...
// Now position the pieces according
// to the new order.
var r = 0, c = 0;
for (i=0; i<numCells; i++) {
var piece = cell[i][0];
if (piece == numCells-1) {
empty = i;
} else {
posArray[piece] = i;
var p = eval("/p" + piece);
p._x = PieceX(c);
p._y = PieceY(r);
}
if (++c >= numCols) {
c = 0;
r++;
}
}
}
Det jeg gerne vil have er at den i
function jubii()
{
loadVariablesNum ("http://www.rc-internet.com/mini/variabel/submit.asp?variabel="+runningTid, 0);
getURL ("http://www.rc-internet.com/mini/variabel/resultat.asp", "_blank");
}
Mellem loadVariablesNum og getURL laver en pause på 5 eller 10 sekunder.
