Frame 1
stopAllSounds();
Frame 5
stop();
Frame 6
function GetNewScore(PrevScore, ValScoreBille, NbBillesSupp, ValNbBillesMinPourSupp) {
return((ValScoreBille * ((NbBillesSupp + NbBillesSupp) - ValNbBillesMinPourSupp)) + PrevScore);
}
function InitTabJeu(TabJeu, MaxLignes, MaxColonnes, BillesMax, DepColInit) {
var CptLg;
var CptCol;
var TabTmp;
var RndCaseDecalRemplir;
CptLg = 0;
while (CptLg < MaxLignes) {
CptCol = 0;
RndCaseDecalRemplir = DepColInit + Math.floor(Math.random() * 4);
CptCol = 0;
while (CptCol < MaxColonnes) {
if (CptCol >= RndCaseDecalRemplir) {
TabJeu[CptLg + (CptCol * MaxLignes)] = Math.floor(Math.random() * BillesMax) + 1;
} else {
TabJeu[CptLg + (CptCol * MaxLignes)] = 0;
}
CptCol++;
}
CptLg++;
}
}
function CreationTabJeu(MaxLignes, MaxColonnes) {
var Cpt;
var TabJeu;
TabJeu = new Array();
Cpt = 0;
while (Cpt < (MaxLignes * MaxColonnes)) {
TabJeu.push(0);
Cpt++;
}
return(TabJeu);
}
function DuplicationClipBilles(BillesMovieClip, StrClipBilles, MaxLignes, MaxColonnes) {
var CptLg;
var CptCol;
var BilleObj;
CptLg = 0;
while (CptLg < MaxLignes) {
CptCol = 0;
while (CptCol < MaxColonnes) {
duplicateMovieClip (BillesMovieClip, ((StrClipBilles + CptLg) + "_") + CptCol, (CptLg + (MaxLignes * CptCol)) + 1);
CptCol++;
}
CptLg++;
}
}
function GetNewBilleToPlay(TabJeu, ValNbBillesMax) {
var Cpt;
var TableCptBilles;
var TotalBilles;
var RndNb;
TableCptBilles = new Array();
Cpt = 0;
while (ValNbBillesMax >= Cpt) {
TableCptBilles.push(0);
Cpt++;
}
TotalBilles = 0;
Cpt = 0;
while (Cpt < TabJeu.length) {
TableCptBilles[TabJeu[Cpt]]++;
if (TabJeu[Cpt]) {
TotalBilles++;
}
Cpt++;
}
RndNb = Math.floor(Math.random() * TotalBilles) + 1;
Cpt = 1;
while (0 < RndNb) {
RndNb = RndNb - TableCptBilles[Cpt];
Cpt++;
}
delete TableCptBilles;
return(Cpt - 1);
}
function CalculNbBillesParCouleur(TabJeu, ValNbBillesMax) {
var Cpt;
var TableCptBilles;
TableCptBilles = new Array();
Cpt = 0;
while (ValNbBillesMax >= Cpt) {
TableCptBilles.push(0);
Cpt++;
}
Cpt = 0;
while (Cpt < TabJeu.length) {
TableCptBilles[TabJeu[Cpt++]]++;
}
return(TableCptBilles);
}
function GetTableIndexMax(Table, PrevIndex) {
var Cpt;
var NewIdMax;
var Boucle;
if (PrevIndex < 0) {
(NewIdMax = 1);
(Cpt = 1);
while (Cpt < Table.length) {
if (Table[Cpt] >= Table[NewIdMax]) {
NewIdMax = Cpt;
}
Cpt++;
}
} else {
NewIdMax = 0;
Boucle = 1;
Cpt = 1;
while ((Cpt < Table.length) && (Boucle)) {
if ((Table[Cpt] == Table[PrevIndex]) && (Cpt != PrevIndex)) {
NewIdMax = Cpt;
Boucle = 0;
} else if ((Table[Cpt] < Table[PrevIndex]) && (Table[Cpt] >= Table[NewIdMax])) {
NewIdMax = Cpt;
}
Cpt++;
}
if (!NewIdMax) {
NewIdMax = Math.floor(Math.random() * (Table.length - 1)) + 1;
}
}
return(NewIdMax);
}
function TableJeuVide(TabJeu) {
var Cpt;
Cpt = 0;
while ((!TabJeu[Cpt]) && (Cpt < TabJeu.length)) {
Cpt++;
}
return(Cpt == TabJeu.length);
}
function AfficheJeu(TabJeu, StrClipBilles, MaxLignes, MaxColonnes, XStart, YStart, CaseLength) {
var CptLg;
var CptCol;
var Cpt;
var BilleObj;
Cpt = 0;
CptCol = 0;
while (CptCol < MaxColonnes) {
CptLg = 0;
while (CptLg < MaxLignes) {
BilleObj = eval (((StrClipBilles + CptLg) + "_") + CptCol);
BilleObj._x = (XStart + (CptLg * CaseLength)) + (CaseLength / 2);
BilleObj._y = (YStart + (CptCol * CaseLength)) + (CaseLength / 2);
if (TabJeu[Cpt] == 0) {
BilleObj._visible = 0;
} else {
BilleObj._visible = 1;
BilleObj.gotoAndStop(TabJeu[Cpt]);
}
Cpt++;
CptLg++;
}
CptCol++;
}
}
function InitAlphaClipBilles(StrClipBilles, MaxLignes, MaxColonnes) {
var CptLg;
var CptCol;
var BilleObj;
CptCol = 0;
while (CptCol < MaxColonnes) {
CptLg = 0;
while (CptLg < MaxLignes) {
BilleObj = eval (((StrClipBilles + CptLg) + "_") + CptCol);
BilleObj._alpha = 100;
CptLg++;
}
CptCol++;
}
}
function GetIndexFromMouse(XMouse, YMouse, XStartTable, YStartTable, CaseLength, TableMaxLg, TableMaxCol) {
var XTable;
var YTable;
XTable = Math.floor((XMouse - XStartTable) / CaseLength);
YTable = Math.floor((YMouse - YStartTable) / CaseLength);
if ((((XTable >= 0) && (XTable < TableMaxLg)) && (YTable >= 0)) && (YTable < TableMaxCol)) {
return(XTable + (YTable * TableMaxLg));
}
return(-1);
}
function GetXCaseForNewBille(XMouse, XStartTable, CaseLength, TableMaxLg) {
var XTable;
XTable = Math.floor((XMouse - XStartTable) / CaseLength);
if (XTable < 0) {
return(0);
}
if (XTable >= TableMaxLg) {
return(TableMaxLg - 1);
}
return(XTable);
}
function SuppBillesTable(TableBilles, IndexTableBilles, MaxLg, MaxCol, NbBillesSupp) {
var Cpt;
var Count;
var TableIndexVerif = null;
Count = 0;
if (TableBilles[IndexTableBilles] != 0) {
TableIndexVerif = CreationTabJeu(MaxLg, MaxCol);
DetTableIndexBillesSupp(TableBilles, IndexTableBilles, MaxLg, MaxCol, TableIndexVerif);
Count = 0;
Cpt = 0;
while (Cpt < TableIndexVerif.length) {
if (TableIndexVerif[Cpt]) {
Count++;
}
Cpt++;
}
if (Count >= NbBillesSupp) {
Cpt = 0;
while (Cpt < TableIndexVerif.length) {
if (TableIndexVerif[Cpt]) {
TableBilles[Cpt] = 0;
}
Cpt++;
}
}
delete TableIndexVerif;
}
return(Count);
}
function RafraichirTabBilles(TableBilles, MaxLg, MaxCol, ValVide) {
var CptLg;
var CptCol;
var IdColVide;
var IdColPlein;
var IdTabColVide;
var IdTabColPlein;
CptLg = 0;
while (CptLg < MaxLg) {
IdColVide = MaxCol - 1;
IdColPlein = MaxCol - 2;
while (IdColPlein >= 0) {
IdTabColVide = CptLg + (IdColVide * MaxLg);
IdTabColPlein = CptLg + (IdColPlein * MaxLg);
if (TableBilles[IdTabColVide] == ValVide) {
if (TableBilles[IdTabColPlein] != ValVide) {
TableBilles[IdTabColVide] = TableBilles[IdTabColPlein];
TableBilles[IdTabColPlein] = ValVide;
IdColVide--;
}
} else {
IdColVide--;
}
IdColPlein--;
}
CptLg++;
}
}
function AfficherSuppBillesAlpha(TableBilles, MaxLg, MaxCol, StrClipBilles, ValAlpha) {
var Cpt;
var CptX;
var CptY;
var BillesObj;
Cpt = 0;
CptY = 0;
while (CptY < MaxCol) {
CptX = 0;
while (CptX < MaxLg) {
BillesObj = eval (((StrClipBilles + CptX) + "_") + CptY);
if (TableBilles[Cpt] != BillesObj._currentFrame) {
BillesObj._alpha = ValAlpha;
}
Cpt++;
CptX++;
}
CptY++;
}
}
function RafraichirAffichageTableBilles(TableBilles, MaxLg, MaxCol, StrClipBilles) {
var Cpt;
var CptX;
var CptY;
var BillesObj;
Cpt = 0;
CptY = 0;
while (CptY < MaxCol) {
CptX = 0;
while (CptX < MaxLg) {
BillesObj = eval (((StrClipBilles + CptX) + "_") + CptY);
if (TableBilles[Cpt] == 0) {
BillesObj._visible = 0;
} else {
BillesObj.gotoAndStop(TableBilles[Cpt]);
BillesObj._visible = 1;
}
Cpt++;
CptX++;
}
CptY++;
}
}
function DetTableIndexBillesSupp(TableBilles, IndexTableBilles, MaxLg, MaxCol, TableIndex) {
var XTable;
var YTable;
var NewIndex;
TableIndex[IndexTableBilles] = 1;
XTable = IndexTableBilles % MaxLg;
YTable = Math.floor(IndexTableBilles / MaxLg);
NewIndex = (XTable - 1) + (YTable * MaxLg);
if ((((XTable - 1) >= 0) && (!TableIndex[NewIndex])) && (TableBilles[IndexTableBilles] == TableBilles[NewIndex])) {
DetTableIndexBillesSupp(TableBilles, NewIndex, MaxLg, MaxCol, TableIndex);
}
NewIndex = (XTable + 1) + (YTable * MaxLg);
if ((((XTable + 1) < MaxLg) && (!TableIndex[NewIndex])) && (TableBilles[IndexTableBilles] == TableBilles[NewIndex])) {
DetTableIndexBillesSupp(TableBilles, NewIndex, MaxLg, MaxCol, TableIndex);
}
NewIndex = XTable + ((YTable - 1) * MaxLg);
if ((((YTable - 1) >= 0) && (!TableIndex[NewIndex])) && (TableBilles[IndexTableBilles] == TableBilles[NewIndex])) {
DetTableIndexBillesSupp(TableBilles, NewIndex, MaxLg, MaxCol, TableIndex);
}
NewIndex = XTable + ((YTable + 1) * MaxLg);
if ((((YTable + 1) < MaxCol) && (!TableIndex[NewIndex])) && (TableBilles[IndexTableBilles] == TableBilles[NewIndex])) {
DetTableIndexBillesSupp(TableBilles, NewIndex, MaxLg, MaxCol, TableIndex);
}
}
G_SCREEN_WIDTH = 350;
G_SCREEN_HEIGHT = 350;
G_CASE_SIZE = 18;
G_START_X = 65;
G_START_Y = 123;
BtnClickOk = 0;
ScoreBille = 35;
ScoreTotal = 0;
ValNbBillesSupp = 0;
PrevIndexTable = 0;
CurrentIndexTable = 0;
YPosNewBille = G_START_Y - (G_CASE_SIZE / 2);
NbBillesMinPourSupp = 3;
ValAlphaBillesSupp = 30;
NbMaxLignes = 15;
NbMaxColonnes = 12;
NbBillesMax = 5;
NomClipBilles = "Billes_";
GameArray = null;
CompteBillesArray = null;
IndexCompteBillesArray = 0;
InitBillesColonnes = 4;
ValFrameCurrentBille = -1;
ValCaseXBille = 0;
Frame 7
DuplicationClipBilles(_root.ClipBille, NomClipBilles, NbMaxLignes, NbMaxColonnes);
GameArray = CreationTabJeu(NbMaxLignes, NbMaxColonnes);
InitTabJeu(GameArray, NbMaxLignes, NbMaxColonnes, NbBillesMax, InitBillesColonnes);
AfficheJeu(GameArray, NomClipBilles, NbMaxLignes, NbMaxColonnes, G_START_X, G_START_Y, G_CASE_SIZE);
Frame 8
ValFrameCurrentBille = GetNewBilleToPlay(GameArray, NbBillesMax);
ClipCurrentBille.gotoAndStop(ValFrameCurrentBille);
Frame 9
if (BtnClickOk) {
BtnClickOk = 0;
ClipCanon.play();
PrevIndexTable = ValCaseXBille;
CurrentIndexTable = ValCaseXBille;
if (GameArray[CurrentIndexTable] != 0) {
gotoAndPlay (50);
} else {
GameArray[CurrentIndexTable] = ValCurrentBille;
CurrentIndexTable = CurrentIndexTable + NbMaxLignes;
RafraichirAffichageTableBilles(GameArray, NbMaxLignes, NbMaxColonnes, NomClipBilles);
gotoAndPlay (15);
}
} else {
play();
}
Frame 10
prevFrame();
Frame 15
if ((CurrentIndexTable >= (NbMaxLignes * NbMaxColonnes)) || (GameArray[CurrentIndexTable] != 0)) {
gotoAndPlay (29);
} else {
GameArray[PrevIndexTable] = 0;
GameArray[CurrentIndexTable] = ValFrameCurrentBille;
PrevIndexTable = CurrentIndexTable;
CurrentIndexTable = CurrentIndexTable + NbMaxLignes;
RafraichirAffichageTableBilles(GameArray, NbMaxLignes, NbMaxColonnes, NomClipBilles);
}
Frame 18
gotoAndPlay (15);
Frame 29
ValNbBillesSupp = SuppBillesTable(GameArray, PrevIndexTable, NbMaxLignes, NbMaxColonnes, NbBillesMinPourSupp);
if (ValNbBillesSupp >= NbBillesMinPourSupp) {
ScoreTotal = GetNewScore(ScoreTotal, ScoreBille, ValNbBillesSupp, NbBillesMinPourSupp);
TextScore = "Score :\n" + ScoreTotal;
AfficherSuppBillesAlpha(GameArray, NbMaxLignes, NbMaxColonnes, NomClipBilles, ValAlphaBillesSupp);
}
Frame 34
InitAlphaClipBilles(NomClipBilles, NbMaxLignes, NbMaxColonnes);
RafraichirTabBilles(GameArray, NbMaxLignes, NbMaxColonnes, 0);
RafraichirAffichageTableBilles(GameArray, NbMaxLignes, NbMaxColonnes, NomClipBilles);
if (TableJeuVide(GameArray)) {
gotoAndPlay (50);
} else {
gotoAndPlay (8);
}
Frame 47
stop();
Frame 50
delete GameArray;
GameArray = CreationTabJeu(NbMaxLignes, NbMaxColonnes);
AfficheJeu(GameArray, NomClipBilles, NbMaxLignes, NbMaxColonnes, G_START_X, G_START_Y, G_CASE_SIZE);
stop();
Symbol 18 Button
on (release) {
gotoAndPlay (6);
}
Symbol 28 MovieClip Frame 1
stop();
Symbol 29 Button
on (release) {
BtnClickOk = 1;
}
Symbol 35 MovieClip Frame 1
stop();
Symbol 40 MovieClip Frame 1
_root.ValCaseXBille = _root.GetXCaseForNewBille(_root._xmouse, _root.G_START_X, _root.G_CASE_SIZE, _root.NbMaxLignes);
_root.ClipCanon._x = (_root.G_START_X + (_root.G_CASE_SIZE / 2)) + (_root.ValCaseXBille * _root.G_CASE_SIZE);
play();
Symbol 40 MovieClip Frame 2
prevFrame();
Symbol 43 Button
on (release) {
InitTabJeu(GameArray, NbMaxLignes, NbMaxColonnes, NbBillesMax, InitBillesColonnes);
AfficheJeu(GameArray, NomClipBilles, NbMaxLignes, NbMaxColonnes, G_START_X, G_START_Y, G_CASE_SIZE);
ScoreTotal = 0;
TextScore = "Score :\n0";
gotoAndPlay (8);
}
Symbol 44 Button
on (release) {
gotoAndPlay (1);
}