Frame 1
_global.debugMode = true;
if (debugMode) {
cards = "5c_9c_3s_2d_10s_8h_13h_5d_3d_9s_11d_7s_5h_1c_8c_12h_11s_7c_1h_12d_13d_3h_2c_6c_8s_4d_1s_8d_2h_1d_13c_13s_6s_12s_4s_5s_12c_11h_6d_2s_9h_6h_7d_11c_4c_10c_10h_7h_9d_3c_10d_4h";
gameData = ((("<gamedata timelimit=\"180\" rounds=\"2\" cards=\"" + cards) + "/") + cards) + "\"><text id=\"score\">Po\u00E4ng</text><text id=\"time\">Tid</text><text id=\"endgame\">Avsluta</text><text id=\"discard\">Sl\u00E4ng</text><text id=\"exit_game_in\">Spelet avslutas om</text><text id=\"next_round\">N\u00E4sta omg\u00E5ng om</text><text id=\"seconds\">sekunder</text><text id=\"timebonus\">Tidsbonus</text><text id=\"totalscore\">Total po\u00E4ng</text><text id=\"previous_score\">F\u00F6reg\u00E5ende omg\u00E5ng</text><text id=\"all_rounds_score\">Alla ronder</text><text id=\"round\">Rond</text><text id=\"finalscore1\">Po\u00E4ng rond 1</text><text id=\"finalscore2\">Slutpo\u00E4ng</text></gamedata>";
}
var inited = false;
onEnterFrame = function () {
if ((!inited) && (gameData != undefined)) {
var board = attachMovie("Board", "board", 0);
board.init(new PracticeRules(board));
inited = true;
}
};
Symbol 56 MovieClip [Board] Frame 1
#initclip 10
Object.registerClass("Board", Board);
#endinitclip
Instance of Symbol 31 MovieClip [cardbox] "cardBox0" in Symbol 56 MovieClip [Board] Frame 1
//component parameters
onClipEvent (initialize) {
fieldnum = 1;
}
Instance of Symbol 31 MovieClip [cardbox] "cardBox1" in Symbol 56 MovieClip [Board] Frame 1
//component parameters
onClipEvent (initialize) {
fieldnum = 2;
}
Instance of Symbol 31 MovieClip [cardbox] "cardBox2" in Symbol 56 MovieClip [Board] Frame 1
//component parameters
onClipEvent (initialize) {
fieldnum = 3;
}
Instance of Symbol 31 MovieClip [cardbox] "cardBox3" in Symbol 56 MovieClip [Board] Frame 1
//component parameters
onClipEvent (initialize) {
fieldnum = 4;
}
Symbol 70 MovieClip [Card] Frame 1
#initclip 8
Object.registerClass("Card", Card);
#endinitclip
Symbol 228 MovieClip [ScoreDisplay] Frame 1
#initclip 9
Object.registerClass("ScoreDisplay", ScoreDisplay);
#endinitclip
Symbol 232 MovieClip [__Packages.Rules] Frame 0
class Rules
{
function Rules () {
}
function init() {
}
function win() {
}
function endGame() {
}
function discardClicked() {
}
function columnClicked(column) {
}
}
Symbol 233 MovieClip [__Packages.Pile] Frame 0
class Pile
{
var board, cards, depthOffset, singleCard, id, x, y;
function Pile (newBoard, offset) {
board = newBoard;
cards = new Array();
depthOffset = offset;
singleCard = false;
}
function setPosFromTemplate(mc, newId) {
id = newId;
x = mc._x;
y = mc._y;
mc._visible = false;
}
function removeAllCards() {
var i = 0;
while (i < cards.length) {
var card = cards[i];
i++;
}
cards = new Array();
}
function setSingleCardMode(singleCardMode) {
singleCard = singleCardMode;
}
function pushCard(card) {
if (singleCard && (cards.length > 1)) {
cards[cards.length - 2]._visible = false;
}
var targetDepth = (cards.length + depthOffset);
card.swapDepths(targetDepth);
cards.push(card);
card.setPile(this);
}
function popCard() {
if (singleCard && (cards.length > 2)) {
cards[cards.length - 3]._visible = true;
}
return(cards.pop());
}
function cardCount() {
return(cards.length);
}
function mayDrop(draggedCards) {
return(false);
}
function cardClicked(card) {
}
}
Symbol 234 MovieClip [__Packages.Board] Frame 0
class Board extends MovieClip
{
var rules, timeAlertColor, timeAlert, scoreAlertColor, scoreAlert, hand, handPos, flippedHand, scrapPos, endgameButton, discardButton, config, startTime, cardLists, timeTitle, scoreTitle, endgameText, discardText, attachMovie, remainingTime, result, timeValue, scoreValue;
function Board () {
super();
}
function init(rules) {
this.rules = rules;
timeAlertColor = new Color(timeAlert);
timeAlertColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:0, ab:0});
scoreAlertColor = new Color(scoreAlert);
scoreAlertColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:0, ab:0});
var pileCount = 10;
hand = new Pile(this, 52 * (pileCount++));
hand.setPosFromTemplate(handPos, "h0");
hand.singleCard = true;
flippedHand = new Pile(this, 52 * (pileCount++));
flippedHand.setPosFromTemplate(scrapPos, "h1");
flippedHand.singleCard = true;
var x = 0;
while (x < 4) {
columns[x] = new Column(this, 52 * (pileCount++));
columns[x].setPosFromTemplate(this["pilePos" + x], "p" + x);
columns[x].setComponents(this["valueCounter" + x], this["cardBox" + x]);
columns[x].number = x;
x++;
}
parseGameData();
var thisBoard = this;
endgameButton.onPress = function () {
thisBoard.rules.endGame();
};
discardButton.onPress = function () {
thisBoard.rules.discardClicked();
};
var myListener = new Object();
myListener.onKeyDown = function () {
if (Key.getCode() == 49) {
thisBoard.rules.columnClicked(thisBoard.columns[0]);
} else if (Key.getCode() == 50) {
thisBoard.rules.columnClicked(thisBoard.columns[1]);
} else if (Key.getCode() == 51) {
thisBoard.rules.columnClicked(thisBoard.columns[2]);
} else if (Key.getCode() == 52) {
thisBoard.rules.columnClicked(thisBoard.columns[3]);
} else if (Key.getCode() == 32) {
thisBoard.rules.discardClicked();
}
};
Key.addListener(myListener);
fscommand ("gameStart");
}
function parseGameData() {
var gameDataXml = new XML(_root.gameData);
config = new Object();
var cn = gameDataXml.firstchild.childNodes;
var i = 0;
while (i < cn.length) {
if (config[cn[i].nodeName] == undefined) {
config[cn[i].nodeName] = new Object();
}
config[cn[i].nodeName][cn[i].attributes.id] = new String(cn[i].firstChild.nodeValue);
i++;
}
startTime = new Number(gameDataXml.firstchild.attributes.timelimit) * 1000;
cardLists = gameDataXml.firstchild.attributes.cards.split("/");
timeTitle.text = config.text.time;
scoreTitle.text = config.text.score;
endgameText.text = config.text.endgame;
discardText.text = config.text.discard;
var i = 0;
var f = 0;
while (f < 4) {
var v = 0;
while (v < 13) {
var fStr = "";
if (f == 0) {
fStr = "h";
}
if (f == 1) {
fStr = "s";
}
if (f == 2) {
fStr = "d";
}
if (f == 3) {
fStr = "c";
}
var cardFace = ((v + 1) + fStr);
var card = attachMovie("Card", cardFace, i++);
card.setFaceValue(cardFace, v, f);
this[cardFace] = card;
v++;
}
f++;
}
initRound(0);
}
function initRound(roundNum) {
remainingTime = startTime;
setRemainingTime(remainingTime);
timeAlertColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:0, ab:0});
scoreAlertColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:0, ab:0});
setScore(0);
hand.removeAllCards();
flippedHand.removeAllCards();
var i = 0;
while (i < 4) {
columns[i].removeAllCards();
i++;
}
var cardFaces = cardLists[roundNum].split("_");
var i = 0;
while (i < 52) {
var cardFace = cardFaces[i];
var card = this[cardFace];
card.setFrontFaceUp(true);
card.forceTo(hand.x, hand.y);
card._alpha = 100;
card._visible = true;
hand.pushCard(card);
i++;
}
playTimeOffset = getTimer();
rules.init();
}
function onEnterFrame() {
if ((!hasWon) && (_root.playTime != undefined)) {
remainingTime = startTime - ((_root.playTime * 1000) - playTimeOffset);
if (remainingTime > startTime) {
playTimeOffset = playTimeOffset - (remainingTime - startTime);
remainingTime = startTime;
}
_root.playTime = undefined;
}
scoreAlertColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:scoreAlertValue, ab:0});
scoreAlertValue = scoreAlertValue * 0.8;
var now = getTimer();
if ((lastTime != -1) && ((now - lastTime) > 0)) {
remainingTime = remainingTime - (now - lastTime);
if (remainingTime < 0) {
if (!hasWon) {
setRemainingTime(0);
timeAlertColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:0, ab:0});
rules.win();
} else {
setRemainingTime(0);
if (roundNum == 1) {
if (!hasReportedGameOver) {
hasReportedGameOver = true;
fscommand ("gameOver", score);
}
} else {
result._visible = false;
hasWon = false;
roundNum++;
initRound(roundNum);
}
}
} else {
setRemainingTime(remainingTime);
}
}
lastTime = now;
}
function setRemainingTime(remainingTime) {
if (hasWon) {
if (remainingTime < 0) {
remainingTime = 0;
}
if (roundNum == 0) {
result.qin.text = (((config.text.next_round + " ") + Math.round(remainingTime / 1000)) + " ") + config.text.seconds;
} else {
result.qin.text = (((config.text.exit_game_in + " ") + Math.round(remainingTime / 1000)) + " ") + config.text.seconds;
}
} else {
var seconds = Math.round(remainingTime / 1000);
var minutes = Math.floor(seconds / 60);
if (seconds < 60) {
var pulse = ((Math.sin(remainingTime / 100) * 25) + 25);
var alphaColor = ((pulse * (60 - seconds)) / 60);
timeAlertColor.setTransform({ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:alphaColor, ab:0});
}
seconds = seconds % 60;
minutes = minutes % 100;
var res = "";
if (minutes < 10) {
res = res + "0";
}
res = res + (minutes + ":");
if (seconds < 10) {
res = res + "0";
}
res = res + (seconds + "");
timeValue.text = res;
}
}
function getTimeLeft() {
return(Math.floor(remainingTime / 1000));
}
function getTotalTime() {
return(Math.floor(startTime / 1000));
}
function endGame(score) {
roundNum = 1;
win(score, 0, score);
}
function win(baseScore, timeScore, totalScore) {
if (!hasWon) {
result = attachMovie("Result", "result", 100000);
if (roundNum == 0) {
result.roundlabel.text = config.text.finalscore1;
} else {
result.roundlabel.text = config.text.finalscore2;
}
result.timebonus_text.text = config.text.timebonus;
result.timebonus.text = timeScore.toString();
result.score_text.text = config.text.score;
result.score.text = baseScore.toString();
result.totalscore_text.text = config.text.totalscore;
result.totalscore.text = totalScore.toString();
result.qin.text = (((config.text.exit_game_in + " ") + Math.floor(remainingTime / 1000)) + " ") + config.text.seconds;
result.previousscore_text._visible = roundNum == 1;
result.previousscore._visible = roundNum == 1;
result.allrounds_text._visible = roundNum == 1;
result.allrounds._visible = roundNum == 1;
result.previousscore_text.text = config.text.previous_score;
result.previousscore.text = score;
score = score + totalScore;
result.allrounds_text.text = config.text.all_rounds_score;
result.allrounds.text = score;
result._x = 0;
result._y = 0;
hasWon = true;
remainingTime = 5000;
}
}
function showScoreAlert() {
scoreAlertValue = 100;
}
function setScore(score) {
var res = "";
if (score < 1000) {
res = res + "0";
}
if (score < 100) {
res = res + "0";
}
if (score < 10) {
res = res + "0";
}
res = res + (score + "");
scoreValue.text = res;
}
var columns = new Array();
var hasWon = false;
var cards = new Array();
var lastTime = -1;
var scoreAlertValue = 0;
var score = 0;
var roundNum = 0;
var hasReportedGameOver = false;
var playTimeOffset = 0;
}
Symbol 235 MovieClip [__Packages.Card] Frame 0
class Card extends MovieClip
{
var xSlideTarget, _x, ySlideTarget, _y, frontFaceUp, pile, id, value, suit, frontFace, attachMovie, _width, _height, backFace, _alpha, _visible, getDepth;
function Card () {
super();
xSlideTarget = _x;
ySlideTarget = _y;
frontFaceUp = false;
}
function setPile(newPile) {
pile = newPile;
}
function onPress() {
pile.cardClicked(this);
}
function setFaceValue(newFaceValue, newValue, newSuit) {
id = newFaceValue;
value = newValue;
suit = newSuit;
frontFace = attachMovie(id, "frontFace", 0);
frontFace._width = _width;
frontFace._height = _height;
frontFace._visible = false;
}
function setFrontFaceUp(newFrontFaceUp) {
frontFaceUp = newFrontFaceUp;
backFace._visible = !frontFaceUp;
frontFace._visible = frontFaceUp;
}
function fadeOut(delay) {
fadeoutTime = 10 + delay;
}
function onEnterFrame() {
if (fadeoutTime > 0) {
fadeoutTime--;
if (fadeoutTime < 10) {
_alpha = fadeoutTime * 10;
}
if (fadeoutTime == 0) {
_visible = false;
}
}
if (slideTime > 0) {
movePos((xSlideTarget - _x) / slideTime, (ySlideTarget - _y) / slideTime);
slideTime--;
if (slideTime == 0) {
slideEnd();
}
}
}
function slideTo(x, y) {
xSlideTarget = x;
ySlideTarget = y;
slideTime = 5;
movePos((xSlideTarget - _x) / slideTime, (ySlideTarget - _y) / slideTime);
slideTime--;
slideStart();
}
function forceTo(x, y) {
_x = x;
_y = y;
xSlideTarget = x;
ySlideTarget = y;
}
function movePos(xa, ya) {
setPos(_x + xa, _y + ya);
}
function setPos(x, y) {
_x = Math.round(x);
_y = Math.round(y);
}
function slideStart() {
super.swapDepths(getDepth() + 100000);
}
function slideEnd() {
super.swapDepths(getDepth() - 100000);
}
function swapDepths(targetDepth) {
if (slideTime > 0) {
slideEnd();
}
super.swapDepths(targetDepth);
if (slideTime > 0) {
slideStart();
}
}
var slideTime = 0;
var fadeoutTime = 0;
var lastClickTime = 0;
}
Symbol 236 MovieClip [__Packages.Column] Frame 0
class Column extends Pile
{
var x, cards, y, valueCounter, cardBox, id, board, depthOffset, value;
function Column (newBoard, offset) {
super(newBoard, offset);
}
function pushCard(card) {
card.slideTo(x, y + (cards.length * 16));
if (card.value == 0) {
containsAce = true;
}
super.pushCard(card);
}
function setComponents(valueCounter, cardBox) {
this.valueCounter = valueCounter;
this.cardBox = cardBox;
}
function setPosFromTemplate(mc, newId) {
id = newId;
x = mc._x;
y = mc._y;
mc._alpha = 0;
mc._visible = true;
var thisPile = this;
mc.onPress = function () {
thisPile.click();
};
}
function setCanMove(canMove) {
cardBox._visible = canMove;
}
function removeAllCards() {
super.removeAllCards();
cards = new Array();
score = (0);
containsAce = false;
}
function clear(splashName) {
var i = 0;
while (i < cards.length) {
var card = cards[i];
card.fadeOut(i * 4);
i++;
}
var boaster = board.attachMovie("ScoreDisplay", boaster + depthOffset, (50000 + depthOffset) + boasterId);
boasterId++;
if (boasterId == 10) {
boasterId = 0;
}
boaster.init(cardBox, splashName, (cards.length + 3) * 16);
cards = new Array();
score = (0);
containsAce = false;
}
function showScorePenalty(splashName) {
var boaster = board.attachMovie("ScoreDisplay", boaster + depthOffset, (50000 + depthOffset) + boasterId);
boasterId++;
if (boasterId == 10) {
boasterId = 0;
}
boaster.init(cardBox, splashName, (cards.length + 3) * 16);
}
function cardClicked(card) {
click();
}
function click() {
board.rules.columnClicked(this);
}
function get score() {
return(value);
}
function set score(newValue) {
value = newValue;
valueCounter.text = value.toString();
//return(score);
}
var containsAce = false;
var boasterId = 0;
}
Symbol 237 MovieClip [__Packages.PracticeRules] Frame 0
class PracticeRules extends Rules
{
var board, xylophone, dingding, card_layout, negative_horn, startsound;
function PracticeRules (board) {
super();
this.board = board;
xylophone = new Sound();
dingding = new Sound();
card_layout = new Sound();
negative_horn = new Sound();
startsound = new Sound();
xylophone.attachSound("xylophone");
dingding.attachSound("ding_ding");
card_layout.attachSound("card_layout");
negative_horn.attachSound("negative_horn");
startsound.attachSound("startsound");
}
function init() {
score = 0;
clearings = 0;
hasWon = false;
newCardRevealed();
var i = 0;
while (i < 4) {
var column = board.columns[i];
column.score = 0;
i++;
}
startsound.start();
}
function win() {
if (hasWon) {
return(undefined);
}
hasWon = true;
var baseScore = score;
var remainingSeconds = board.getTimeLeft();
var timeBonus = Math.floor((5000 * (remainingSeconds / board.getTotalTime())) / (1 + board.flippedHand.cards.length));
if (timeBonus < 0) {
timeBonus = 0;
}
board.win(score, timeBonus, score + timeBonus);
score = score + timeBonus;
}
function endGame() {
if (hasWon) {
return(undefined);
}
board.endGame(score);
}
function discardClicked() {
if (hasWon) {
return(undefined);
}
if (board.hand.cards.length > 0) {
card_layout.start();
var card = board.hand.popCard();
card.slideTo(board.flippedHand.x, board.flippedHand.y);
card.setFrontFaceUp(false);
board.flippedHand.pushCard(card);
newCardRevealed();
}
}
function columnClicked(column) {
if (hasWon) {
return(undefined);
}
if (board.hand.cards.length > 0) {
var topCard = board.hand.cards[board.hand.cards.length - 1];
if (canMove(topCard, column)) {
card_layout.start();
column.pushCard(board.hand.popCard());
column.score = column.score + getCardValue(topCard, column.__get__score());
var preScore = score;
if ((column.__get__score() < 21) && (column.cards.length == 5)) {
scoreFiveCardCharlie(column);
} else if (((column.__get__score() == 11) && (column.containsAce)) && (column.cards.length == 2)) {
scoreBlackJack(column);
} else if (topCard.id == "13h") {
scoreMagic(column);
} else if ((column.__get__score() == 21) || ((column.__get__score() == 11) && (column.containsAce))) {
score21(column);
}
newCardRevealed();
} else {
var preScore = score;
negative_horn.start();
score = score - 100;
if (score < 0) {
score = 0;
}
board.setScore(score);
board.showScoreAlert();
}
}
}
function scoreFiveCardCharlie(column) {
dingding.start();
score = score + (getNextClearValue() * 3);
board.setScore(score);
column.clear("charlie");
}
function scoreBlackJack(column) {
dingding.start();
score = score + (getNextClearValue() * 2);
board.setScore(score);
column.clear("bj");
}
function scoreMagic(column) {
dingding.start();
score = score + getNextClearValue();
board.setScore(score);
column.clear("magic");
}
function score21(column) {
dingding.start();
score = score + getNextClearValue();
board.setScore(score);
column.clear("21");
}
function getNextClearValue() {
clearings++;
return(clearings * 100);
}
function newCardRevealed() {
board.cardsleft.text = board.hand.cards.length.toString();
board.discards.text = board.flippedHand.cards.length.toString();
if (board.hand.cards.length > 0) {
var topCard = board.hand.cards[board.hand.cards.length - 1];
var i = 0;
while (i < board.columns.length) {
var column = board.columns[i];
column.setCanMove(canMove(topCard, column));
i++;
}
} else {
win();
var i = 0;
while (i < board.columns.length) {
var column = board.columns[i];
column.setCanMove(false);
i++;
}
}
}
function canMove(card, column) {
if (card.id == "13h") {
return(true);
}
return((column.__get__score() + getCardValue(card, column.__get__score())) <= 21);
}
function getCardValue(card, baseScore) {
var value = (card.value + 1);
if (value > 10) {
value = 10;
}
return(value);
}
var score = 0;
var clearings = 0;
var hasWon = false;
}
Symbol 238 MovieClip [__Packages.ScoreDisplay] Frame 0
class ScoreDisplay extends MovieClip
{
var scoreDisplayHolder, _x, _y, orgxscale, _xscale, orgyscale, _yscale, _alpha, removeMovieClip;
function ScoreDisplay () {
super();
}
function init(mc, splashName, yo) {
var foo = scoreDisplayHolder.attachMovie(splashName, foo, 1);
foo._x = 0;
foo._y = 0;
_x = mc._x;
_y = mc._y + yo;
orgxscale = _xscale;
orgyscale = _yscale;
time = 0;
_alpha = 0;
}
function onEnterFrame() {
var a = Math.sin((time / lifeSpan) * Math.PI);
_alpha = (a * a) * 100;
var scale = ((time / lifeSpan) * 2);
scale = Math.sqrt(scale);
_xscale = scale * orgxscale;
_yscale = scale * orgyscale;
time++;
if (time > lifeSpan) {
removeMovieClip();
}
}
var lifeSpan = 25;
var time = 0;
}