Frame 1
stop();
Frame 2
playGame_btn.onPress = function () {
_root.gotoAndPlay("Start");
};
instructions_btn.onPress = function () {
_root.gotoAndPlay("Instructions");
};
website_btn.onRelease = function () {
getURL ("http://www.jonmiles.co.uk", "_blank");
};
stop();
Frame 4
next_btn.onPress = function () {
gotoAndStop ("Guessing");
};
stop();
Frame 5
board_mc.blackPeg_mc.makeUnmoveable();
board_mc.cyanPeg_mc.makeUnmoveable();
board_mc.greenPeg_mc.makeUnmoveable();
board_mc.redPeg_mc.makeUnmoveable();
board_mc.whitePeg_mc.makeUnmoveable();
board_mc.yellowPeg_mc.makeUnmoveable();
next_btn.onPress = function () {
gotoAndStop ("Clues");
};
Frame 6
green_mc.correct();
white1_mc.kinda();
white2_mc.kinda();
next_btn.onPress = function () {
_root.gotoAndStop("Scoring");
};
Frame 7
return_btn.onPress = function () {
_root.gotoAndStop("Title");
};
Frame 8
function playAgain() {
playAgain_mc._visible = true;
confirmPlayAgain_btn._visible = true;
cancelPlayAgain_btn._visible = true;
}
function hideInterface() {
playAgain_mc._visible = false;
confirmPlayAgain_btn._visible = false;
cancelPlayAgain_btn._visible = false;
}
var BLACK = 0;
var CYAN = 1;
var GREEN = 2;
var RED = 3;
var YELLOW = 4;
var WHITE = 5;
stop();
var game = new CodeBreaker();
hideInterface();
confirmPlayAgain_btn.onPress = function () {
game.reset();
hideInterface();
};
cancelPlayAgain_btn.onPress = function () {
game.remove();
gotoAndStop ("Title");
};
Symbol 10 MovieClip [peg] Frame 1
#initclip 9
Object.registerClass("peg", Peg);
#endinitclip
stop();
Symbol 13 MovieClip [cover] Frame 1
this.stop();
Symbol 13 MovieClip [cover] Frame 61
this.stop();
_parent.codeRevealed();
Symbol 13 MovieClip [cover] Frame 121
this.stop();
_parent.codeCovered();
Symbol 17 MovieClip [light] Frame 1
#initclip 6
Object.registerClass("light", Light);
#endinitclip
this.stop();
Symbol 19 MovieClip [slot] Frame 1
#initclip 7
Object.registerClass("slot", Slot);
#endinitclip
this.stop();
Symbol 21 MovieClip [board] Frame 1
#initclip 8
Object.registerClass("board", Board);
#endinitclip
Symbol 24 MovieClip Frame 1
stop();
onEnterFrame = function () {
framesLoaded = Math.ceil((_parent.getBytesLoaded() / _parent.getBytesTotal()) * 100);
gotoAndStop(framesLoaded);
if (framesLoaded >= 90) {
_root.gotoAndPlay("Title");
}
};
Symbol 71 MovieClip [__Packages.Light] Frame 0
class Light extends MovieClip
{
var gotoAndStop;
function Light () {
super();
}
function correct() {
gotoAndStop("correct");
}
function kinda() {
gotoAndStop("kinda");
}
function reset() {
gotoAndStop("Off");
}
}
Symbol 72 MovieClip [__Packages.Slot] Frame 0
class Slot extends MovieClip
{
var _x, _y, _parent;
function Slot () {
super();
}
function fill(myPeg) {
peg = myPeg;
peg._x = _x;
peg._y = _y;
peg.setSlot(this);
_parent.pegFilled();
}
function getPeg() {
return(peg);
}
function isFilled() {
if (peg != null) {
return(true);
}
return(false);
}
function lock() {
locked = true;
peg.makeUnmoveable();
}
function unlock() {
locked = false;
peg.makeMoveable();
}
function remove() {
if (locked == false) {
peg = null;
_parent.pegRemoved();
return(true);
}
return(false);
}
var BLACK = 0;
var CYAN = 1;
var GREEN = 2;
var RED = 3;
var YELLOW = 4;
var WHITE = 5;
var filled = false;
var locked = false;
var peg = null;
}
Symbol 73 MovieClip [__Packages.Peg] Frame 0
class Peg extends MovieClip
{
var onPress, useHandCursor, onRelease, color, gotoAndStop;
function Peg () {
super();
makeMoveable();
}
function makeMoveable() {
onPress = function () {
if (this.inSlot()) {
if (this.slot.remove() == true) {
this.slot = null;
// unexpected jump
}
return(undefined);
} else {
var _local2 = this._parent.attachMovie("peg", "peg" + this._parent.getNextHighestDepth(), this._parent.getNextHighestDepth(), {game:this.game});
_local2.setColor(this.color);
_local2._x = this._x;
_local2._y = this._y;
}
this.swapDepths(this._parent.getNextHighestDepth());
this.startDrag();
this.onRelease = function () {
this.stopDrag();
if (this.game.checkPeg(this) == false) {
this.removeMovieClip();
} else {
var _local2 = new Sound();
_local2.attachSound("pegClick" + Math.round((Math.random() * 1) + 1));
_local2.start();
this.onRelease = null;
}
};
};
}
function makeUnmoveable() {
useHandCursor = false;
onPress = null;
onRelease = null;
}
function inSlot() {
if (slot != null) {
return(true);
}
return(false);
}
function setSlot(mySlot) {
slot = mySlot;
}
function getColor() {
return(color);
}
function setColor(color) {
this.color = color;
switch (color) {
case BLACK :
gotoAndStop("Black");
break;
case CYAN :
gotoAndStop("Cyan");
break;
case GREEN :
gotoAndStop("Green");
break;
case RED :
gotoAndStop("Red");
break;
case WHITE :
gotoAndStop("White");
break;
case YELLOW :
gotoAndStop("Yellow");
}
}
var BLACK = 0;
var CYAN = 1;
var GREEN = 2;
var RED = 3;
var YELLOW = 4;
var WHITE = 5;
var slot = null;
}
Symbol 74 MovieClip [__Packages.CodeBreaker] Frame 0
class CodeBreaker
{
var gameBoard_mc;
function CodeBreaker () {
initGame();
}
function currentGuess() {
return(guess);
}
function guessesAllowed() {
return(guesses);
}
function checkPeg(myPeg) {
return(gameBoard_mc.placePeg(myPeg));
}
function pegPlaced() {
pegs++;
if (pegs == 4) {
score = score - 1;
_root.score_txt.text = score;
if (gameBoard_mc.checkGuess() == true) {
win();
} else if (guessesLeft() == true) {
guess++;
pegs = 0;
} else {
lose();
}
}
}
function guessesLeft() {
if (guess < guesses) {
return(true);
}
return(false);
}
function pegRemoved() {
pegs--;
}
function win() {
gameBoard_mc.revealCode();
total = total + score;
games = games + 1;
_root.total_txt.text = total;
_root.games_txt.text = games;
}
function lose() {
gameBoard_mc.revealCode();
games = games + 1;
_root.games_txt.text = games;
}
function initGame() {
_root.attachMovie("board", "gameBoard_mc", _root.getNextHighestDepth(), {game:this, _x:200.5, _y:55});
gameBoard_mc = _root.gameBoard_mc;
newGame();
}
function reset() {
gameBoard_mc.coverCode();
score = 10;
_root.score_txt.text = score;
}
function newGame() {
gameBoard_mc.clear();
gameBoard_mc.makeCode();
pegs = 0;
guess = 1;
}
function remove() {
gameBoard_mc.remove();
removeMovieClip(gameBoard_mc);
}
var guess = 1;
var total = 0;
var score = 10;
var games = 0;
var guesses = 10;
var pegs = 0;
}
Symbol 75 MovieClip [__Packages.Board] Frame 0
class Board extends MovieClip
{
var _height, attachMovie, getNextHighestDepth, game, cover, removeMovieClip;
function Board () {
super();
makeBoard();
makePegs();
}
function makePegs() {
var _local2;
var _local3 = _height - 20;
_local2 = attachMovie("peg", "blackPeg_mc", getNextHighestDepth(), {game:game, _x:0, _y:_local3});
_local2.setColor(BLACK);
_local2 = attachMovie("peg", "cyanPeg_mc", getNextHighestDepth(), {game:game, _x:30, _y:_local3});
_local2.setColor(CYAN);
_local2 = attachMovie("peg", "greenPeg_mc", getNextHighestDepth(), {game:game, _x:60, _y:_local3});
_local2.setColor(GREEN);
_local2 = attachMovie("peg", "redPeg_mc", getNextHighestDepth(), {game:game, _x:90, _y:_local3});
_local2.setColor(RED);
_local2 = attachMovie("peg", "whitePeg_mc", getNextHighestDepth(), {game:game, _x:120, _y:_local3});
_local2.setColor(WHITE);
_local2 = attachMovie("peg", "yellowPeg_mc", getNextHighestDepth(), {game:game, _x:150, _y:_local3});
_local2.setColor(YELLOW);
}
function makeBoard() {
var _local4 = 0;
var _local6 = _height - 30;
var _local7 = 0;
while (_local7 < game.guessesAllowed()) {
var _local2 = 0;
while (_local2 < 4) {
var _local3 = attachMovie("slot", ("slot" + _local4) + "_mc", getNextHighestDepth());
_local3._x = (_local2 + 1) * 30;
_local3._y = _local6;
slots[_local4] = _local3;
var _local5 = attachMovie("light", ("light" + _local4) + "_mc", getNextHighestDepth());
_local5._x = (_local2 - 4.25) * 30;
_local5._y = _local6;
lights[_local4] = _local5;
_local4++;
_local2++;
}
_local6 = _local6 - (_local3._height + (_local3._height / 2));
_local7++;
}
cover = attachMovie("cover", "codeCover_mc", getNextHighestDepth());
cover._y = -40;
}
function makeCode() {
var _local2 = 0;
while (_local2 < 4) {
var _local3 = attachMovie("peg", "codePeg" + _local2, -16380 + _local2);
code[_local2] = Math.round(Math.random() * 5);
_local3._x = (_local2 + 1) * 30;
_local3._y = -25;
_local3.useHandCursor = false;
_local3.onPress = null;
_local3.setColor(code[_local2]);
_local2++;
}
}
function placePeg(myPeg) {
var _local3 = 0;
while (_local3 < 4) {
var _local4 = ((game.currentGuess() - 1) * 4) + _local3;
var _local2 = slots[_local4];
if (myPeg.hitTest(_local2) && (!_local2.isFilled())) {
_local2.fill(myPeg);
return(true);
}
_local3++;
}
return(false);
}
function checkGuess() {
var _local9 = false;
var _local8 = 0;
var _local6 = 0;
var _local4 = Array(3);
var _local5 = 0;
while (_local5 < 4) {
var _local7 = ((game.currentGuess() - 1) * 4) + _local5;
_local4[_local5] = slots[_local7].getPeg().getColor();
slots[_local7].lock();
_local5++;
}
var _local3 = Array(3);
_local5 = 0;
while (_local5 < 4) {
_local3[_local5] = code[_local5];
_local5++;
}
_local5 = 0;
while (_local5 < 4) {
if (_local3[_local5] == _local4[_local5]) {
_local8++;
_local4[_local5] = null;
_local3[_local5] = null;
}
_local5++;
}
if (_local8 < 4) {
_local5 = 0;
while (_local5 < 4) {
if (_local4[_local5] != null) {
var _local2 = 0;
while (_local2 < 4) {
if ((_local3[_local2] != null) && (_local3[_local2] == _local4[_local5])) {
_local6++;
_local4[_local5] = null;
_local3[_local2] = null;
}
_local2++;
}
}
_local5++;
}
} else {
_local9 = true;
}
_local5 = 0;
while (_local5 < 4) {
var _local7 = ((game.currentGuess() - 1) * 4) + _local5;
if (_local8 > 0) {
lights[_local7].correct();
_local8--;
} else if (_local6 > 0) {
lights[_local7].kinda();
_local6--;
}
_local5++;
}
return(_local9);
}
function pegFilled() {
game.pegPlaced();
}
function pegRemoved() {
game.pegRemoved();
}
function revealCode() {
cover.gotoAndPlay("Reveal");
}
function coverCode() {
cover.gotoAndPlay("Cover");
}
function codeRevealed() {
_root.playAgain();
}
function codeCovered() {
game.newGame();
}
function clear() {
var _local2 = 0;
while (_local2 < slots.length) {
lights[_local2].reset();
slots[_local2].unlock();
var _local3 = slots[_local2].getPeg();
_local3.removeMovieClip();
slots[_local2].remove();
_local2++;
}
}
function remove() {
var _local2 = 0;
while (_local2 < slots.length) {
var _local3 = slots[_local2].getPeg();
(removeMovieClip());// not popped
(removeMovieClip());// not popped
(removeMovieClip());// not popped
_local2++;
}
}
var BLACK = 0;
var CYAN = 1;
var GREEN = 2;
var RED = 3;
var YELLOW = 4;
var WHITE = 5;
var pegs = 0;
var code = Array(3);
var lights = new Array(39);
var slots = new Array(39);
}