Section 1
//ArialAbyMiecPewnosc (ArialAbyMiecPewnosc)
package {
import flash.text.*;
public dynamic class ArialAbyMiecPewnosc extends Font {
}
}//package
Section 2
//BasicButton (BasicButton)
package {
import flash.display.*;
public dynamic class BasicButton extends SimpleButton {
}
}//package
Section 3
//ClickPieceSound (ClickPieceSound)
package {
import flash.media.*;
public dynamic class ClickPieceSound extends Sound {
}
}//package
Section 4
//Dang (Dang)
package {
import flash.media.*;
public dynamic class Dang extends Sound {
}
}//package
Section 5
//DropSound (DropSound)
package {
import flash.media.*;
public dynamic class DropSound extends Sound {
}
}//package
Section 6
//EndOfGameSound (EndOfGameSound)
package {
import flash.media.*;
public dynamic class EndOfGameSound extends Sound {
}
}//package
Section 7
//MatchFindSound (MatchFindSound)
package {
import flash.media.*;
public dynamic class MatchFindSound extends Sound {
}
}//package
Section 8
//MatchThree (MatchThree)
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.media.*;
import flash.utils.*;
import flash.external.*;
public class MatchThree extends MovieClip {
private var firstPiece:Piece;
private var isDropping;
public var startButton:BasicButton;
private var holdPossible:Array;
private var gameSprite:Sprite;
public var threshholdSubmitScore:int;
var useSwapSound:SwapSound;
var useWrongSwapSound:WrongSwapSound;
public var quit_btn:SimpleButton;
private var grid:Array;
var useDropSound:DropSound;
public var hint_btn:SimpleButton;
public var submit_btn:SimpleButton;
var useEndOfGameSound:EndOfGameSound;
var hintDisplayTimer:Timer;
private var isSwapping:Boolean;
public var scoreDisplay:TextField;
public var playAgainButton:BasicButton;
var useClickPieceSound:ClickPieceSound;
private var gameScore:int;
var useMatchFindSound:MatchFindSound;
static const hintCost:uint = 100;
static const spacing:Number = 45;
static const offsetX:Number = 192;
static const numPieces:uint = 8;
static const offsetY:Number = 43;
static const basePoints:uint = 5;
static const totalNumCols:uint = 8;
static const hintFlashDelay:uint = 200;
static const totalNumRows:uint = 8;
static const hintFlashRepeats:uint = 6;
public function MatchThree(){
holdPossible = new Array();
useMatchFindSound = new MatchFindSound();
useWrongSwapSound = new WrongSwapSound();
useSwapSound = new SwapSound();
useEndOfGameSound = new EndOfGameSound();
useClickPieceSound = new ClickPieceSound();
useDropSound = new DropSound();
super();
addFrameScript(0, frame1, 1, frame2, 2, frame3);
}
public function matchPattern(_arg1, _arg2:uint, _arg3, _arg4:Array){
var _local5:int;
var _local6:int;
var _local7:uint;
var _local8:uint;
_local5 = grid[_arg1][_arg2].type;
_local6 = 0;
while (_local6 < _arg3.length) {
if (!matchType((_arg1 + _arg3[_local6][0]), (_arg2 + _arg3[_local6][1]), _local5)){
return (false);
};
_local6++;
};
_local6 = 0;
while (_local6 < _arg4.length) {
if (matchType((_arg1 + _arg4[_local6][0]), (_arg2 + _arg4[_local6][1]), _local5)){
_local7 = (_arg1 + _arg4[_local6][0]);
_local8 = (_arg2 + _arg4[_local6][1]);
holdPossible["col"] = _local7;
holdPossible["row"] = _local8;
return (true);
};
_local6++;
};
return (false);
}
function frame2(){
quit_btn.addEventListener(MouseEvent.CLICK, endGame);
hint_btn.addEventListener(MouseEvent.CLICK, flashHint);
startMatchThree();
}
public function getMatchHoriz(_arg1, _arg2):Array{
var _local3:Array;
var _local4:int;
_local3 = new Array(grid[_arg1][_arg2]);
_local4 = 1;
while ((_arg1 + _local4) < totalNumCols) {
if (grid[_arg1][_arg2].type == grid[(_arg1 + _local4)][_arg2].type){
_local3.push(grid[(_arg1 + _local4)][_arg2]);
} else {
return (_local3);
};
_local4++;
};
return (_local3);
}
private function hintDisplayTimerComplete(_arg1:TimerEvent):void{
grid[holdPossible["col"]][holdPossible["row"]].hint.visible = false;
hintDisplayTimer.stop();
hintDisplayTimer.removeEventListener(TimerEvent.TIMER, hintDisplayTimerListener);
hintDisplayTimer.removeEventListener(Event.COMPLETE, hintDisplayTimerComplete);
}
public function lookForMatches():Array{
var _local1:Array;
var _local2:int;
var _local3:int;
var _local4:Array;
_local1 = new Array();
_local2 = 0;
while (_local2 < totalNumRows) {
_local3 = 0;
while (_local3 < 6) {
_local4 = getMatchHoriz(_local3, _local2);
if (_local4.length > 2){
_local1.push(_local4);
_local3 = (_local3 + (_local4.length - 1));
};
_local3++;
};
_local2++;
};
_local3 = 0;
while (_local3 < totalNumCols) {
_local2 = 0;
while (_local2 < 6) {
_local4 = getMatchVert(_local3, _local2);
if (_local4.length > 2){
_local1.push(_local4);
_local2 = (_local2 + (_local4.length - 1));
};
_local2++;
};
_local3++;
};
return (_local1);
}
function frame3(){
scoreDisplay.text = String(gameScore);
cleanUp();
playAgainButton.addEventListener(MouseEvent.CLICK, playAgain);
submit_btn.addEventListener(MouseEvent.CLICK, submitScore);
}
public function submitScore(_arg1:MouseEvent):void{
if (gameScore > threshholdSubmitScore){
ExternalInterface.call("submitGameResults", "jewelgrab", gameScore);
ExternalInterface.call("addPoints", "game_complete");
};
gotoAndStop("intro");
}
public function endGame(_arg1:MouseEvent=null){
playSound(useEndOfGameSound);
MovieClip(root).gameScore = gameScore;
setChildIndex(gameSprite, 0);
gotoAndStop("gameover");
}
public function addScore(_arg1:int){
if (_arg1 > 0){
playSound(useMatchFindSound);
};
gameScore = (gameScore + _arg1);
MovieClip(root).scoreDisplay.text = String(gameScore);
}
public function addNewPieces(){
var _local1:int;
var _local2:int;
var _local3:int;
var _local4:Piece;
_local1 = 0;
while (_local1 < totalNumCols) {
_local2 = 0;
_local3 = (totalNumRows - 1);
while (_local3 >= 0) {
if (grid[_local1][_local3] == null){
_local4 = addPiece(_local1, _local3);
var _temp1 = _local2;
_local2 = (_local2 + 1);
_local4.y = ((offsetY - spacing) - (spacing * _temp1));
isDropping = true;
};
_local3--;
};
_local1++;
};
}
public function setUpGrid():void{
var _local1:int;
var _local2:int;
while (true) {
gameSprite = new Sprite();
_local1 = 0;
while (_local1 < totalNumCols) {
_local2 = 0;
while (_local2 < totalNumRows) {
addPiece(_local1, _local2);
_local2++;
};
_local1++;
};
if (lookForMatches().length != 0){
} else {
if (lookForPossibles() == false){
} else {
break;
};
};
};
addChild(gameSprite);
}
public function findAndRemoveMatches(){
var _local1:Array;
var _local2:int;
var _local3:Number;
var _local4:int;
var _local5:*;
_local1 = lookForMatches();
_local2 = 0;
while (_local2 < _local1.length) {
_local3 = ((_local1[_local2].length - 1) * basePoints);
_local4 = 0;
while (_local4 < _local1[_local2].length) {
if (gameSprite.contains(_local1[_local2][_local4])){
_local5 = new PointBurst(this, _local3, _local1[_local2][_local4].x, _local1[_local2][_local4].y);
addScore(_local3);
gameSprite.removeChild(_local1[_local2][_local4]);
grid[_local1[_local2][_local4].col][_local1[_local2][_local4].row] = null;
affectAbove(_local1[_local2][_local4]);
};
_local4++;
};
_local2++;
};
addNewPieces();
if (_local1.length == 0){
if (!lookForPossibles()){
endGame();
};
};
}
function frame1(){
stop();
threshholdSubmitScore = 150;
startButton.addEventListener(MouseEvent.CLICK, clickStart);
}
public function affectAbove(_arg1:Piece){
var _local2:int;
_local2 = (_arg1.row - 1);
while (_local2 >= 0) {
if (grid[_arg1.col][_local2] != null){
grid[_arg1.col][_local2].row++;
grid[_arg1.col][(_local2 + 1)] = grid[_arg1.col][_local2];
grid[_arg1.col][_local2] = null;
};
_local2--;
};
}
public function movePieces(_arg1:Event){
var _local2:Boolean;
var _local3:int;
var _local4:int;
_local2 = false;
_local3 = 0;
while (_local3 < totalNumRows) {
_local4 = 0;
while (_local4 < totalNumCols) {
if (grid[_local4][_local3] != null){
if (grid[_local4][_local3].y < ((grid[_local4][_local3].row * spacing) + offsetY)){
grid[_local4][_local3].y = (grid[_local4][_local3].y + 5);
_local2 = true;
} else {
if (grid[_local4][_local3].y > ((grid[_local4][_local3].row * spacing) + offsetY)){
grid[_local4][_local3].y = (grid[_local4][_local3].y - 5);
_local2 = true;
} else {
if (grid[_local4][_local3].x < ((grid[_local4][_local3].col * spacing) + offsetX)){
grid[_local4][_local3].x = (grid[_local4][_local3].x + 5);
_local2 = true;
} else {
if (grid[_local4][_local3].x > ((grid[_local4][_local3].col * spacing) + offsetX)){
grid[_local4][_local3].x = (grid[_local4][_local3].x - 5);
_local2 = true;
};
};
};
};
};
_local4++;
};
_local3++;
};
if (((isDropping) && (!(_local2)))){
isDropping = false;
findAndRemoveMatches();
} else {
if (((isSwapping) && (!(_local2)))){
isSwapping = false;
findAndRemoveMatches();
};
};
}
public function clickPiece(_arg1:MouseEvent){
var _local2:Piece;
_local2 = Piece(_arg1.currentTarget);
if (firstPiece == null){
_local2.select.visible = true;
firstPiece = _local2;
playSound(useClickPieceSound);
} else {
if (firstPiece == _local2){
_local2.select.visible = false;
firstPiece = null;
} else {
firstPiece.select.visible = false;
if (firstPiece.row == _local2.row){
if (Math.abs((firstPiece.col - _local2.col)) == 1){
makeSwap(firstPiece, _local2);
firstPiece = null;
};
} else {
if (firstPiece.col == _local2.col){
if (Math.abs((firstPiece.row - _local2.row)) == 1){
makeSwap(firstPiece, _local2);
firstPiece = null;
};
} else {
playSound(useWrongSwapSound);
firstPiece = _local2;
firstPiece.select.visible = true;
};
};
};
};
}
public function lookForPossibles(){
var _local1:int;
var _local2:int;
_local1 = 0;
while (_local1 < totalNumCols) {
_local2 = 0;
while (_local2 < totalNumRows) {
if (matchPattern(_local1, _local2, [[1, 0]], [[-2, 0], [-1, -1], [-1, 1], [2, -1], [2, 1], [3, 0]])){
return (true);
};
if (matchPattern(_local1, _local2, [[2, 0]], [[1, -1], [1, 1]])){
return (true);
};
if (matchPattern(_local1, _local2, [[0, 1]], [[0, -2], [-1, -1], [1, -1], [-1, 2], [1, 2], [0, 3]])){
return (true);
};
if (matchPattern(_local1, _local2, [[0, 2]], [[-1, 1], [1, 1]])){
return (true);
};
_local2++;
};
_local1++;
};
return (false);
}
public function makeSwap(_arg1, _arg2:Piece){
swapPieces(_arg1, _arg2);
if (lookForMatches().length == 0){
swapPieces(_arg1, _arg2);
} else {
isSwapping = true;
};
}
public function matchType(_arg1, _arg2, _arg3:int){
if ((((((((_arg1 < 0)) || ((_arg1 > (totalNumCols - 1))))) || ((_arg2 < 0)))) || ((_arg2 > (totalNumRows - 1))))){
return (false);
};
return ((grid[_arg1][_arg2].type == _arg3));
}
public function playAgain(_arg1:MouseEvent){
gotoAndStop("play");
}
public function clickStart(_arg1:MouseEvent){
gotoAndStop("play");
}
public function addPiece(_arg1, _arg2:int):Piece{
var _local3:Piece;
_local3 = new Piece();
_local3.x = ((_arg1 * spacing) + offsetX);
_local3.y = ((_arg2 * spacing) + offsetY);
_local3.col = _arg1;
_local3.row = _arg2;
_local3.type = Math.ceil((Math.random() * numPieces));
_local3.gotoAndStop(_local3.type);
_local3.select.visible = false;
_local3.hint.visible = false;
gameSprite.addChild(_local3);
grid[_arg1][_arg2] = _local3;
_local3.addEventListener(MouseEvent.CLICK, clickPiece);
return (_local3);
}
public function playSound(_arg1:Object){
var _local2:SoundChannel;
_local2 = _arg1.play();
}
private function hintDisplayTimerListener(_arg1:TimerEvent):void{
if (firstPiece != null){
firstPiece.select.visible = false;
firstPiece = null;
};
grid[holdPossible["col"]][holdPossible["row"]].hint.visible = !(grid[holdPossible["col"]][holdPossible["row"]].hint.visible);
}
public function swapPieces(_arg1, _arg2:Piece){
var _local3:uint;
var _local4:uint;
_local3 = _arg1.col;
_local4 = _arg1.row;
_arg1.col = _arg2.col;
_arg1.row = _arg2.row;
_arg2.col = _local3;
_arg2.row = _local4;
grid[_arg1.col][_arg1.row] = _arg1;
grid[_arg2.col][_arg2.row] = _arg2;
}
public function startMatchThree():void{
var _local1:int;
grid = new Array();
_local1 = 0;
while (_local1 < totalNumRows) {
grid.push(new Array());
_local1++;
};
setUpGrid();
isDropping = false;
isSwapping = false;
gameScore = 0;
addEventListener(Event.ENTER_FRAME, movePieces);
}
public function flashHint(_arg1:MouseEvent){
addScore((-1 * hintCost));
hintDisplayTimer = new Timer(hintFlashDelay, hintFlashRepeats);
hintDisplayTimer.addEventListener(TimerEvent.TIMER, hintDisplayTimerListener);
hintDisplayTimer.addEventListener(Event.COMPLETE, hintDisplayTimerComplete);
hintDisplayTimer.start();
}
public function getMatchVert(_arg1, _arg2):Array{
var _local3:Array;
var _local4:int;
_local3 = new Array(grid[_arg1][_arg2]);
_local4 = 1;
while ((_arg2 + _local4) < totalNumRows) {
if (grid[_arg1][_arg2].type == grid[_arg1][(_arg2 + _local4)].type){
_local3.push(grid[_arg1][(_arg2 + _local4)]);
} else {
return (_local3);
};
_local4++;
};
return (_local3);
}
public function cleanUp(){
grid = null;
removeChild(gameSprite);
gameSprite = null;
removeEventListener(Event.ENTER_FRAME, movePieces);
}
}
}//package
Section 9
//Piece (Piece)
package {
import flash.display.*;
public dynamic class Piece extends MovieClip {
public var select:Select;
public var hint:MovieClip;
}
}//package
Section 10
//PointBurst (PointBurst)
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
public class PointBurst extends Sprite {
private var burstSprite:Sprite;
private var animTimer:Timer;
private var parentMC:MovieClip;
private var tField:TextField;
static const animStepTime:int = 50;
static const fontSize:int = 20;
static const fontFace:String = "Arial";
static const fontBold:Boolean = true;
static const animSteps:int = 15;
static const startScale:Number = 0;
static const fontColor:Number = 0xFFFFFF;
static const endScale:Number = 2;
public function PointBurst(_arg1:MovieClip, _arg2:Object, _arg3, _arg4:Number){
var _local5:TextFormat;
super();
_local5 = new TextFormat();
_local5.font = fontFace;
_local5.size = fontSize;
_local5.bold = fontBold;
_local5.color = fontColor;
_local5.align = "center";
tField = new TextField();
tField.embedFonts = true;
tField.selectable = false;
tField.defaultTextFormat = _local5;
tField.autoSize = TextFieldAutoSize.CENTER;
tField.text = String(_arg2);
tField.x = -((tField.width / 2));
tField.y = -((tField.height / 2));
burstSprite = new Sprite();
burstSprite.x = _arg3;
burstSprite.y = _arg4;
burstSprite.scaleX = startScale;
burstSprite.scaleY = startScale;
burstSprite.alpha = 0;
burstSprite.addChild(tField);
parentMC = _arg1;
parentMC.addChild(burstSprite);
animTimer = new Timer(animStepTime, animSteps);
animTimer.addEventListener(TimerEvent.TIMER, rescaleBurst);
animTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeBurst);
animTimer.start();
}
public function removeBurst(_arg1:TimerEvent){
burstSprite.removeChild(tField);
parentMC.removeChild(burstSprite);
tField = null;
burstSprite = null;
delete ??getglobalscope
[this];
}
public function rescaleBurst(_arg1:TimerEvent){
var _local2:Number;
_local2 = (_arg1.target.currentCount / animSteps);
burstSprite.scaleX = (((1 - _local2) * startScale) + (_local2 * endScale));
burstSprite.scaleY = (((1 - _local2) * startScale) + (_local2 * endScale));
burstSprite.alpha = (1 - _local2);
}
}
}//package
Section 11
//Select (Select)
package {
import flash.display.*;
public dynamic class Select extends MovieClip {
}
}//package
Section 12
//SwapSound (SwapSound)
package {
import flash.media.*;
public dynamic class SwapSound extends Sound {
}
}//package
Section 13
//WrongSwapSound (WrongSwapSound)
package {
import flash.media.*;
public dynamic class WrongSwapSound extends Sound {
}
}//package