Frame 1
cardSpacing = 18;
backsideCardSpacing = 5;
nrOfDecks = 4;
nrOfSuits = 2;
noHints._alpha = 0;
noUndo._alpha = 0;
qbrisButton.onRelease = function () {
getURL ("http://qbris.com?ref=spidersolitaire");
};
pressCard = function () {
if (this.backside._name == "backside") {
if (cols[this.coll][cols[this.coll].length - 1].toString() == this._name.toString()) {
removeMovieClip(this.backside);
} else {
trace(cols[this.coll]);
}
} else if (cols[this.coll][cols[this.coll].length - 1].toString() == this._name.toString()) {
this.swapDepths(_root.getNextHighestDepth());
this.startDrag();
} else {
sameSuit = true;
numbers = new Array();
i = 1;
while (cols[this.coll][cols[this.coll].length - i].toString() != this._name.toString()) {
if (cols[this.coll][cols[this.coll].length - i].toString().substr(1, 1) != this.suit.toString()) {
sameSuit = false;
}
numbers.push(cols[this.coll][cols[this.coll].length - i].toString().substr(2, 2));
i++;
}
cardTemp = this.number;
straight = true;
numbers.reverse();
i = 0;
while (numbers[i]) {
if (cardTemp != (Number(numbers[i]) + 1)) {
straight = false;
}
cardTemp--;
i++;
}
if (sameSuit and straight) {
cardsToMove = new Array();
cardToFollow = this._name;
i = 1;
while (cols[this.coll][cols[this.coll].length - i].toString() != this._name.toString()) {
cardOver = cols[this.coll][cols[this.coll].length - i];
cardsToMove.push(cardOver);
i++;
}
this.swapDepths(_root.getNextHighestDepth());
cardsToMove.reverse();
i = 0;
while (cardsToMove[i]) {
_root[cardsToMove[i]].swapDepths(_root.getNextHighestDepth());
i++;
}
this.startDrag();
}
}
};
releaseCard = function () {
fromColl = this.coll;
dropedAt = Math.floor((this._x + 35) / 70);
if (dropedAt != this.coll) {
allCards = new Array(this._name);
if (cardsToMove) {
i = 0;
while (cardsToMove[i]) {
allCards.push(cardsToMove[i]);
i++;
}
}
tempCard = cols[dropedAt][cols[dropedAt].length - 1];
tempCardNumber = Number(tempCard.toString().substr(2, 2));
if (tempCardNumber == (this.number + 1)) {
this.loch = _root[tempCard]._x;
this.locv = _root[tempCard]._y + cardSpacing;
cols[dropedAt].push(this._name);
i = 0;
while (cardsToMove[i]) {
cols[dropedAt].push(cardsToMove[i]);
cols[this.coll].pop();
_root[cardsToMove[i]].loch = _root[tempCard]._x;
_root[cardsToMove[i]].locv = _root[tempCard]._y + ((i + 2) * 25);
_root[cardsToMove[i]].coll = dropedAt;
i++;
}
cols[this.coll].pop();
this.coll = dropedAt;
} else if (cols[dropedAt].length == 0) {
this.loch = (dropedAt * 70) + 1;
this.locv = 1;
cols[dropedAt].push(this._name);
i = 0;
while (cardsToMove[i]) {
cols[dropedAt].push(cardsToMove[i]);
cols[this.coll].pop();
_root[cardsToMove[i]].loch = _root[tempCard]._x;
_root[cardsToMove[i]].locv = _root[tempCard]._y + ((i + 2) * cardSpacing);
_root[cardsToMove[i]].coll = dropedAt;
i++;
}
cols[this.coll].pop();
this.coll = dropedAt;
}
if (_root[cols[fromColl][cols[fromColl].length - 1]].backside) {
removeMovieClip(_root[cols[fromColl][cols[fromColl].length - 1]].backside);
history.push(new Array(fromColl, dropedAt, allCards, "backside"));
} else {
history.push(new Array(fromColl, dropedAt, allCards));
}
if (cols[dropedAt][cols[dropedAt].length - 1].toString().substr(2, 2) == 1) {
aesColor = cols[dropedAt][cols[dropedAt].length - 1].toString().substr(1, 1);
sameSuit = true;
numbers = new Array();
i = 1;
while (i < 14) {
if (cols[this.coll][cols[this.coll].length - i].toString().substr(1, 1) != aesColor) {
sameSuit = false;
}
numbers.push(cols[this.coll][cols[this.coll].length - i].toString().substr(2, 2));
i++;
}
cardTemp = 1;
straight = true;
i = 1;
while (i < 13) {
if ((cardTemp + 1) != Number(numbers[i])) {
straight = false;
}
cardTemp++;
i++;
}
if (straight and sameSuit) {
i = 0;
while (i < 13) {
_root[cols[dropedAt][(cols[dropedAt].length - 1) - i]].alphaNumber = (i + 1) * 100;
_root[cols[dropedAt][(cols[dropedAt].length - 1) - i]].onEnterFrame = function () {
this.alphaNumber = this.alphaNumber - 8;
if (this.alphaNumber < 100) {
this._alpha = this.alphaNumber;
if (this.alphaNumber <= 3) {
if (this.number == 13) {
if (_root[cols[this.coll][cols[this.coll].length - 1]].backside) {
removeMovieClip(_root[cols[this.coll][cols[this.coll].length - 1]].backside);
}
cardsLeft = 0;
i = 0;
while (i < 10) {
cardsLeft = cardsLeft + cols[i].length;
i++;
}
if (cardsLeft == 0) {
congratualations._alpha = 100;
}
}
removeMovieClip(this);
}
}
};
i++;
}
i = 0;
while (i < 13) {
cols[dropedAt].pop();
i++;
}
}
}
}
this._x = this.loch;
this._y = this.locv;
this.stopDrag();
stopFollow();
};
stopFollow = function (fromColl, toColl) {
if (cardToFollow) {
i = 0;
while (cardsToMove[i]) {
_root[cardsToMove[i]]._y = _root[cardToFollow]._y + ((i + 1) * cardSpacing);
_root[cardsToMove[i]]._x = _root[cardToFollow]._x;
_root[cardsToMove[i]].loch = _root[cardsToMove[i]]._x;
_root[cardsToMove[i]].locv = _root[cardsToMove[i]]._y;
i++;
}
cardToFollow = false;
cardsToMove = [0];
}
};
startGame = function () {
congratualations._alpha = 0;
history = new Array();
suit = ["h", "s", "k", "r"];
antal = ["a", "b", "c", "d", "e", "f", "g", "h"];
dnr = 0;
deck = new Array(52);
n = 0;
while (n < nrOfDecks) {
s = 0;
while (s < nrOfSuits) {
i = 1;
while (i < 14) {
deck[dnr] = (antal[n] + suit[s]) + i;
dnr++;
i++;
}
s++;
}
n++;
}
cols = new Array(10);
i = 0;
while (i < 10) {
cols[i] = new Array();
i++;
}
Array.prototype.shuffle = function () {
var _local2 = this.length;
l = 0;
while (l < _local2) {
this.splice(random(this.length), 0, this.splice(random(this.length), 1));
l++;
}
};
deck.shuffle();
deck.shuffle();
nr = 0;
i = 0;
while (i < 44) {
_root.createEmptyMovieClip(deck[nr], nr);
_root[deck[nr]].attachBitmap(flash.display.BitmapData.loadBitmap(deck[nr].toString().substr(1, 3) + ".gif"), 0);
_root[deck[nr]]._x = ((nr % 10) * 70) + 1;
_root[deck[nr]]._y = -120 + (Math.floor(nr / 10) * backsideCardSpacing);
_root[deck[nr]].loch = ((nr % 10) * 70) + 1;
_root[deck[nr]].locv = Math.floor(nr / 10) * backsideCardSpacing;
_root[deck[nr]].number = Number(deck[nr].toString().substr(2, 2));
_root[deck[nr]].suit = deck[nr].toString().substr(1, 1);
if ((_root[deck[nr]].suit == "h") or (_root[deck[nr]].suit == "r")) {
_root[deck[nr]].colour = "red";
} else {
_root[deck[nr]].colour = "black";
}
_root[deck[nr]].coll = nr % 10;
cols[nr % 10][Math.floor(nr / 10)] = deck[nr];
if (nr < 34) {
_root[deck[nr]].attachMovie("backside", "backside", 1);
}
_root[deck[nr]].onEnterFrame = function () {
this._y = this._y + 5;
if (this._y >= this.locv) {
delete this.onEnterFrame;
}
};
_root[deck[nr]].onPress = pressCard;
_root[deck[nr]].onRelease = releaseCard;
nr++;
i++;
}
newCards.onRelease = function () {
history = new Array();
i = 0;
while (i < 10) {
_root.createEmptyMovieClip(deck[nr], _root.getNextHighestDepth());
_root[deck[nr]].attachBitmap(flash.display.BitmapData.loadBitmap(deck[nr].toString().substr(1, 3) + ".gif"), 0);
_root[deck[nr]]._x = (i * 70) + 1;
_root[deck[nr]]._y = _root[cols[i][cols[i].length - 1]]._y + cardSpacing;
_root[deck[nr]].loch = _root[deck[nr]]._x;
_root[deck[nr]].locv = _root[deck[nr]]._y;
_root[deck[nr]].number = Number(deck[nr].toString().substr(2, 2));
_root[deck[nr]].suit = deck[nr].toString().substr(1, 1);
if ((_root[deck[nr]].suit == "h") or (_root[deck[nr]].suit == "r")) {
_root[deck[nr]].colour = "red";
} else {
_root[deck[nr]].colour = "black";
}
_root[deck[nr]].coll = i;
cols[i].push(deck[nr]);
_root[deck[nr]].onPress = pressCard;
_root[deck[nr]].onRelease = releaseCard;
_root[deck[nr]]._alpha = 0;
_root[deck[nr]].onEnterFrame = function () {
this._alpha = this._alpha + 5;
if (this._alpha > 94) {
delete this.onEnterFrame;
}
};
nr++;
i++;
}
if (nr == 104) {
newCards._alpha = 10;
delete newCards.onRelease;
}
};
hintButton.onRelease = function () {
to = false;
from = false;
c = 0;
while (c < 10) {
firstSuit = cols[c][cols[c].length - 1].toString().substr(1, 1);
tempValue = Number(cols[c][cols[c].length - 1].toString().substr(2, 2)) - 1;
i = 0;
while ((cols[c][(cols[c].length - 1) - i].toString().substr(1, 1) == firstSuit) and (_root[cols[c][(cols[c].length - 1) - i]].backside._name != "backside")) {
if (Number(cols[c][(cols[c].length - 1) - i].toString().substr(2, 2)) != (tempValue + 1)) {
break;
}
tempValue++;
i++;
}
from = cols[c][cols[c].length - i];
nrToFind = Number(cols[c][cols[c].length - i].toString().substr(2, 2)) + 1;
j = 0;
while (j < 10) {
if ((Number(cols[j][cols[j].length - 1].toString().substr(2, 2)) == nrToFind) and (cols[j][cols[j].length - 1].toString().substr(1, 1) == firstSuit)) {
to = cols[j][cols[j].length - 1];
break;
}
j++;
}
if (to) {
break;
}
c++;
}
if (!to) {
c = 0;
while (c < 10) {
firstSuit = cols[c][cols[c].length - 1].toString().substr(1, 1);
tempValue = Number(cols[c][cols[c].length - 1].toString().substr(2, 2)) - 1;
i = 0;
while ((cols[c][(cols[c].length - 1) - i].toString().substr(1, 1) == firstSuit) and (_root[cols[c][(cols[c].length - 1) - i]].backside._name != "backside")) {
if (Number(cols[c][(cols[c].length - 1) - i].toString().substr(2, 2)) != (tempValue + 1)) {
break;
}
tempValue++;
i++;
}
from = cols[c][cols[c].length - i];
nrToFind = Number(cols[c][cols[c].length - i].toString().substr(2, 2)) + 1;
j = 0;
while (j < 10) {
if (Number(cols[j][cols[j].length - 1].toString().substr(2, 2)) == nrToFind) {
to = cols[j][cols[j].length - 1];
break;
}
j++;
}
if (to) {
break;
}
c++;
}
}
if (to and (_root.mark._name != "mark")) {
_root.attachMovie("mark", "mark", _root.getNextHighestDepth(), {_x:_root[from]._x, _y:_root[from]._y});
mark._alpha = 10;
mark.plusMinus = 1;
mark.onEnterFrame = function () {
this._alpha = this._alpha + (5 * mark.plusMinus);
if (this._alpha > 80) {
mark.plusMinus = -1;
}
if (this._alpha < 8) {
removeMovieClip(this);
_root.attachMovie("mark", "mark", _root.getNextHighestDepth(), {_x:_root[to]._x, _y:_root[to]._y});
mark._alpha = 10;
mark.plusMinus = 1;
mark.onEnterFrame = function () {
this._alpha = this._alpha + (5 * mark.plusMinus);
if (this._alpha > 80) {
mark.plusMinus = -1;
}
if (this._alpha < 8) {
removeMovieClip(this);
}
};
}
};
} else if (_root.mark._name != "mark") {
noHints._alpha = 100;
}
};
};
undoButton.onRelease = function () {
if (history.length) {
toDo = history.pop();
if (toDo[3] == "backside") {
if (cols[toDo[0]][cols[toDo[0]].length - 2]) {
_root[cols[toDo[0]][cols[toDo[0]].length - 1]]._y = _root[cols[toDo[0]][cols[toDo[0]].length - 2]]._y + backsideCardSpacing;
} else {
_root[cols[toDo[0]][cols[toDo[0]].length - 1]]._y = 1;
}
_root[cols[toDo[0]][cols[toDo[0]].length - 1]].attachMovie("backside", "backside", 1);
}
i = 0;
while (toDo[2][i]) {
_root[toDo[2][i]].swapDepths(_root.getNextHighestDepth());
_root[toDo[2][i]]._x = (toDo[0] * 70) + 1;
if (_root[cols[toDo[0]][cols[toDo[0]].length - 1]].backside._name == "backside") {
_root[toDo[2][i]]._y = _root[cols[toDo[0]][cols[toDo[0]].length - 1]]._y + backsideCardSpacing;
} else if (!cols[toDo[0]][cols[toDo[0]].length - 2]) {
_root[toDo[2][i]]._y = 1;
} else {
_root[toDo[2][i]]._y = _root[cols[toDo[0]][cols[toDo[0]].length - 1]]._y + cardSpacing;
}
_root[toDo[2][i]].loch = _root[toDo[2][i]]._x;
_root[toDo[2][i]].locv = _root[toDo[2][i]]._y;
_root[toDo[2][i]].coll = toDo[0];
cols[toDo[0]].push(toDo[2][i]);
cols[toDo[1]].pop();
i++;
}
} else {
noUndo._alpha = 100;
}
};
restartButton1.onRelease = function () {
nrOfDecks = 8;
nrOfSuits = 1;
restart();
startGame();
};
restartButton2.onRelease = function () {
nrOfDecks = 4;
nrOfSuits = 2;
restart();
startGame();
};
restartButton4.onRelease = function () {
nrOfDecks = 2;
nrOfSuits = 4;
restart();
startGame();
};
restart = function () {
suit = ["h", "s", "k", "r"];
antal = ["a", "b", "c", "d", "e", "f", "g", "h"];
dnr = 0;
deck = new Array(52);
n = 0;
while (n < 8) {
i = 1;
while (i < 14) {
s = 0;
while (s < 4) {
removeMovieClip(_root[(antal[n] + suit[s]) + i]);
dnr++;
s++;
}
i++;
}
n++;
}
newCards._alpha = 100;
};
startGame();
stop();
this.onEnterFrame = function () {
if (cardToFollow) {
i = 0;
while (cardsToMove[i]) {
_root[cardsToMove[i]]._y = _root[cardToFollow]._y + ((i + 1) * cardSpacing);
_root[cardsToMove[i]]._x = _root[cardToFollow]._x;
i++;
}
}
if (noHints._alpha > -1) {
noHints._alpha = noHints._alpha - 1;
}
if (noUndo._alpha > -1) {
noUndo._alpha = noUndo._alpha - 1;
}
};
this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth());
var mouseListener = new Object();
mouseListener.onMouseUp = function () {
i = 0;
while (_root[deck[i]]._name) {
if (_root[deck[i]]._y != _root[deck[i]].locv) {
trace((((_root[deck[i]]._name + " - ") + _root[deck[i]]._y) + " loch:") + _root[deck[i]].locv);
}
i++;
}
};
Mouse.addListener(mouseListener);