Frame 1
function Bishop() {
super();
}
function King() {
super();
}
function Knight() {
super();
}
function Queen() {
super();
}
function Rook() {
super();
}
function Pawn() {
super();
}
function BoardPointer(x, y, Visible, Target1, Target2, Colour, InactiveRGB, ActiveRGB) {
this.addProperty("x", this.GetX, this.SetX);
this.addProperty("y", this.GetY, this.SetY);
this.xp = x;
this.yp = y;
this.Visible = Visible;
this.Target1 = Target1;
this.Target2 = Target2;
this.T1C = new Color(this.Target1);
this.T2C = new Color(this.Target2);
this.InactiveRGB = InactiveRGB;
this.ActiveRGB = ActiveRGB;
this.Colour = Colour;
this.Draw();
}
function Cookie(CookieName) {
this.CookieName = CookieName;
this.Load();
}
function InitializeGame() {
_global.Board = new Array();
var i = 0;
while (i < 8) {
Board.push(new Array());
var l = 0;
while (l < 8) {
Board[i].push(null);
l++;
}
i++;
}
BlackPieces = new Array();
WhitePieces = new Array();
BlackPieces.push(Container.attachMovie("BRo", "BRo0", 10001, {x:0, y:0}));
BlackPieces.push(Container.attachMovie("BKn", "BKn0", 10002, {x:1, y:0}));
BlackPieces.push(Container.attachMovie("BBi", "BBi0", 10003, {x:2, y:0}));
BlackPieces.push(Container.attachMovie("BQu", "BQu", 10004, {x:3, y:0}));
BlackPieces.push(Container.attachMovie("BKi", "BKi", 10005, {x:4, y:0}));
BlackPieces.push(Container.attachMovie("BBi", "BBi1", 10006, {x:5, y:0}));
BlackPieces.push(Container.attachMovie("BKn", "BKn1", 10007, {x:6, y:0}));
BlackPieces.push(Container.attachMovie("BRo", "BRo1", 10008, {x:7, y:0}));
var i = 0;
while (i < 8) {
BlackPieces.push(Container.attachMovie("BPa", "BPa" + i, 10009 + i, {x:i, y:1}));
WhitePieces.push(Container.attachMovie("WPa", "WPa" + i, 10017 + i, {x:i, y:6}));
i++;
}
WhitePieces.push(Container.attachMovie("WRo", "WRo0", 10025, {x:0, y:7}));
WhitePieces.push(Container.attachMovie("WKn", "WKn0", 10026, {x:1, y:7}));
WhitePieces.push(Container.attachMovie("WBi", "WBi0", 10027, {x:2, y:7}));
WhitePieces.push(Container.attachMovie("WQu", "WQu", 10028, {x:3, y:7}));
WhitePieces.push(Container.attachMovie("WKi", "WKi", 10029, {x:4, y:7}));
WhitePieces.push(Container.attachMovie("WBi", "WBi1", 10030, {x:5, y:7}));
WhitePieces.push(Container.attachMovie("WKn", "WKn1", 10031, {x:6, y:7}));
WhitePieces.push(Container.attachMovie("WRo", "WRo1", 10032, {x:7, y:7}));
Container.attachMovie("Selector", "BS1", 10043, {_xscale:95, _yscale:95});
Container.attachMovie("Selector", "BS2", 10041, {_xscale:95, _yscale:95, _rotation:180});
BlackPointer = new BoardPointer(0, 0, true, Container.BS1, Container.BS2, "B", 102, 255);
Container.attachMovie("Selector", "WS1", 10040, {_xscale:95, _yscale:95});
Container.attachMovie("Selector", "WS2", 10042, {_xscale:95, _yscale:95, _rotation:180});
WhitePointer = new BoardPointer(7, 7, true, Container.WS1, Container.WS2, "W", 26112, 65280);
Container.attachMovie("Selector", "BS3", 10053, {_xscale:80, _yscale:80, _alpha:70});
Container.attachMovie("Selector", "BS4", 10051, {_xscale:80, _yscale:80, _alpha:70, _rotation:180});
BlackSelection = new BoardPointer(0, 0, false, Container.BS3, Container.BS4, "B", 102, 255);
Container.attachMovie("Selector", "WS3", 10050, {_xscale:80, _yscale:80, _alpha:70});
Container.attachMovie("Selector", "WS4", 10052, {_xscale:80, _yscale:80, _alpha:70, _rotation:180});
WhiteSelection = new BoardPointer(7, 7, false, Container.WS3, Container.WS4, "W", 26112, 65280);
switch (Settings.KingEnergy) {
case 0 :
MaxEnergy = 1;
break;
case 1 :
MaxEnergy = 100;
break;
case 2 :
MaxEnergy = 300;
break;
case 3 :
MaxEnergy = 1000;
}
WhiteEnergy = MaxEnergy;
BlackEnergy = MaxEnergy;
i = 0;
while (i < 3) {
this["Input" + i] = null;
if (Settings.P1Input == i) {
this["Input" + i] = "Black";
}
if (Settings.P2Input == i) {
this["Input" + i] = "White";
}
i++;
}
if (Input2 != null) {
Checkboard.onRelease = function () {
_root.DoMove(Input2);
};
Checkboard.useHandCursor = false;
}
LastMovedWhite = null;
LastMovedBlack = null;
WhitePiecesLeft = 16;
WhiteMoves = 0;
BlackPiecesLeft = 16;
BlackMoves = 0;
BloodCounter = 0;
CheckThreats();
GameOn = true;
onEnterFrame = FrameEntered;
}
function DoMove(Colour) {
var sel = this[Colour + "Selection"];
var poi = this[Colour + "Pointer"];
if (sel.Visible) {
var p = Board[sel.x][sel.y];
if (p["Is" + Colour]()) {
if ((sel.x != poi.x) || (sel.y != poi.y)) {
if (p.Move(poi.x, poi.y)) {
this["LastMoved" + Colour] = p;
}
}
}
sel.Hide();
} else {
var p = Board[poi.x][poi.y];
if (!p["Is" + Colour]()) {
return(undefined);
}
if (Settings.ConsecutiveMoves == 0) {
if (p == this["LastMoved" + Colour]) {
return(undefined);
}
}
sel.Go(poi.x, poi.y);
}
}
function KeyDown() {
if (!GameOn) {
return(undefined);
}
var k = Key.getCode();
if (k == 8) {
EndGame("Game interrupted.");
}
if (Input0 != null) {
if (k == 87) {
this[Input0 + "Pointer"].y--;
}
if (k == 83) {
this[Input0 + "Pointer"].y++;
}
if (k == 65) {
this[Input0 + "Pointer"].x--;
}
if (k == 68) {
this[Input0 + "Pointer"].x++;
}
if (k == 32) {
DoMove(Input0);
}
}
if (Input1 != null) {
if (k == 38) {
this[Input1 + "Pointer"].y--;
}
if (k == 40) {
this[Input1 + "Pointer"].y++;
}
if (k == 37) {
this[Input1 + "Pointer"].x--;
}
if (k == 39) {
this[Input1 + "Pointer"].x++;
}
if ((k == 96) || (k == 45)) {
DoMove(Input1);
}
}
}
function EndGame(msg) {
Result = msg;
GameOn = false;
BlackPointer.Hide();
WhitePointer.Hide();
BlackSelection.Hide();
WhiteSelection.Hide();
delete onEnterFrame;
nextFrame();
}
function FrameEntered() {
if (Input2 != null) {
if ((((_xmouse > 20) && (_ymouse > 5)) && (_xmouse < 660)) && (_ymouse < 645)) {
this[Input2 + "Pointer"].x = Math.floor((_xmouse - 20) / 80);
this[Input2 + "Pointer"].y = Math.floor((_ymouse - 5) / 80);
}
}
if ((WhiteThreat + BlackThreat) == 0) {
return(undefined);
}
WhiteEnergy = WhiteEnergy - WhiteThreat;
BlackEnergy = BlackEnergy - BlackThreat;
WhiteEnergyBar.gotoAndStop(Math.min(300, Math.round(300 - ((300 * WhiteEnergy) / MaxEnergy))));
BlackEnergyBar.gotoAndStop(Math.min(300, Math.round(300 - ((300 * BlackEnergy) / MaxEnergy))));
if (WhiteEnergy < 0) {
Blood(Container.WKi.x, Container.WKi.y, "W", true);
Container.WKi.removeMovieClip();
EndGame("Black player wins!");
}
if (BlackEnergy < 0) {
Blood(Container.BKi.x, Container.BKi.y, "B", true);
Container.BKi.removeMovieClip();
EndGame("White player wins!");
}
}
function Blood(x, y, c, k) {
var multiplier = 0;
if (k) {
multiplier = 5;
}
var a = 0;
switch (Settings.Blood) {
case 0 :
return(undefined);
case 1 :
a = 3;
break;
case 2 :
a = 10;
break;
case 3 :
a = 30;
}
var i = 0;
while (i < (Math.round(((Math.random() * a) * 3) * multiplier) + a)) {
BloodCounter++;
var b = Container.attachMovie("Blood", "B" + BloodCounter, BloodCounter, {_x:40 + (x * 80), _y:40 + (y * 80)});
b._rotation = Math.floor(Math.random() * 360);
b._xscale = Math.floor(Math.random() * (150 + (a * 3)));
b._yscale = Math.floor(Math.random() * (150 + (a * 3)));
b._alpha = 30 + Math.floor(Math.random() * 30);
b.gotoAndStop(Math.floor(Math.random() * 20) + 1);
i++;
}
var i = 0;
while (i < (Math.round((Math.random() * a) * multiplier) + a)) {
BloodCounter++;
var b = Container.attachMovie(((c == "W") ? "WhiteShards" : "BlackShards"), "B" + BloodCounter, BloodCounter, {_x:(x * 80) + (Math.random() * 80), _y:(y * 80) + (Math.random() * 80)});
b._xscale = Math.floor(Math.random() * 50) + 30;
b._yscale = Math.floor(Math.random() * 50) + 30;
b._rotation = Math.floor(Math.random() * 360);
b.gotoAndStop(Math.floor(Math.random() * 13) + 1);
i++;
}
}
function IsThreatened(x, y, Colour) {
if (Colour == "B") {
var i = 0;
while (i < BlackPieces.length) {
var p = BlackPieces[i];
if ((p.x == x) && (p.y == y)) {
} else if (p.Threatens(x, y)) {
return(true);
}
i++;
}
} else {
var i = 0;
while (i < WhitePieces.length) {
var p = WhitePieces[i];
if ((p.x == x) && (p.y == y)) {
} else if (p.Threatens(x, y)) {
return(true);
}
i++;
}
}
return(false);
}
function CheckThreats() {
WhiteThreat = 0;
BlackThreat = 0;
var i = 0;
while (i < BlackPieces.length) {
if (BlackPieces[i].CanMove(Container.WKi.x, Container.WKi.y)) {
WhiteThreat++;
}
i++;
}
var i = 0;
while (i < WhitePieces.length) {
if (WhitePieces[i].CanMove(Container.BKi.x, Container.BKi.y)) {
BlackThreat++;
}
i++;
}
if (WhiteThreat == 0) {
Container.WKi.Blinker.gotoAndStop(1);
} else {
Container.WKi.Blinker.play();
}
if (BlackThreat == 0) {
Container.BKi.Blinker.gotoAndStop(1);
} else {
Container.BKi.Blinker.play();
}
}
function ChangeSetting(n) {
if (n == 1) {
do {
Settings.P1Input = (Settings.P1Input + 1) % 3;
} while (Settings.P1Input == Settings.P2Input);
}
if (n == 2) {
do {
Settings.P2Input = (Settings.P2Input + 1) % 3;
} while (Settings.P1Input == Settings.P2Input);
}
if (n == 3) {
Settings.ConsecutiveMoves = (Settings.ConsecutiveMoves + 1) % 2;
}
if (n == 4) {
Settings.KingEnergy = (Settings.KingEnergy + 1) % 4;
}
if (n == 5) {
Settings.Blood = (Settings.Blood + 1) % 4;
}
DisplaySettings();
Settings.save();
}
function DisplaySettings() {
S1.text = InputLabels[Settings.P1Input];
S2.text = InputLabels[Settings.P2Input];
S3.text = ConsecutiveLabels[Settings.ConsecutiveMoves];
S4.text = EnergyLabels[Settings.KingEnergy];
S5.text = BloodLabels[Settings.Blood];
}
PieceBase = function () {
this._xscale = 80;
this._yscale = 80;
this.Go(this.x, this.y);
this.Color = this._name.charAt(0);
};
PieceBase.prototype = new MovieClip();
PieceBase.prototype.IsWhite = function () {
return(this.Color == "W");
};
PieceBase.prototype.IsBlack = function () {
return(this.Color == "B");
};
PieceBase.prototype.Go = function (nx, ny) {
Board[this.x][this.y] = null;
this.x = nx;
this.y = ny;
this._x = 40 + (nx * 80);
this._y = 40 + (ny * 80);
Board[this.x][this.y] = this;
};
PieceBase.prototype.Threatens = function (nx, ny) {
return(this.CanMove(nx, ny));
};
PieceBase.prototype.Move = function (nx, ny) {
if (this.CanMove(nx, ny)) {
return(this.FinishMove(nx, ny));
}
};
PieceBase.prototype.FinishMove = function (nx, ny) {
var p = Board[nx][ny];
if (p.Color == this.Color) {
return(false);
}
if (p instanceof King) {
return(false);
}
if (p != null) {
_root.Blood(nx, ny, p.Color, false);
p.removeMovieClip();
if (this.IsWhite()) {
_root.BlackPiecesLeft--;
} else {
_root.WhitePiecesLeft--;
}
}
this.Go(nx, ny);
_root.CheckThreats();
if (this.IsWhite()) {
_root.WhiteMoves++;
} else {
_root.BlackMoves++;
}
return(true);
};
PieceBase.prototype.IsEmpty = function (x, y) {
return(Board[x][y] == null);
};
PieceBase.prototype.IsEnemy = function (x, y) {
if (this.IsEmpty(x, y)) {
return(false);
}
return(Board[x][y].Color != this.Color);
};
PieceBase.prototype.IsRouteClear = function (x, y) {
var tx = this.x;
var ty = this.y;
var First = true;
while ((tx != x) || (ty != y)) {
if (!First) {
if (Board[tx][ty] != null) {
return(false);
}
}
if (x < tx) {
tx--;
}
if (x > tx) {
tx++;
}
if (y < ty) {
ty--;
}
if (y > ty) {
ty++;
}
First = false;
}
return(true);
};
Bishop.prototype = new PieceBase();
Object.registerClass("BBi", Bishop);
Object.registerClass("WBi", Bishop);
Bishop.prototype.CanMove = function (nx, ny) {
var dx = (this.x - nx);
var dy = (this.y - ny);
var ok = false;
if (Math.abs(dx) == Math.abs(dy)) {
ok = true;
}
if (!ok) {
return(false);
}
return(this.IsRouteClear(nx, ny));
};
King.prototype = new PieceBase();
Object.registerClass("BKi", King);
Object.registerClass("WKi", King);
King.prototype.CanMove = function (nx, ny) {
var dx = Math.abs(this.x - nx);
var dy = Math.abs(this.y - ny);
if ((dx > 1) || (dy > 1)) {
return(false);
}
if (_root.IsThreatened(nx, ny, ((this.Color == "B") ? "W" : "B"))) {
return(false);
}
return(true);
};
Knight.prototype = new PieceBase();
Object.registerClass("BKn", Knight);
Object.registerClass("WKn", Knight);
Knight.prototype.CanMove = function (nx, ny) {
var dx = Math.abs(this.x - nx);
var dy = Math.abs(this.y - ny);
if (((dx == 1) && (dy == 2)) || ((dx == 2) && (dy == 1))) {
return(true);
}
return(false);
};
Queen.prototype = new PieceBase();
Object.registerClass("BQu", Queen);
Object.registerClass("WQu", Queen);
Queen.prototype.CanMove = function (nx, ny) {
var dx = (this.x - nx);
var dy = (this.y - ny);
var ok = false;
if ((dx == 0) || (dy == 0)) {
ok = true;
}
if (Math.abs(dx) == Math.abs(dy)) {
ok = true;
}
if (!ok) {
return(false);
}
return(this.IsRouteClear(nx, ny));
};
Rook.prototype = new PieceBase();
Object.registerClass("BRo", Rook);
Object.registerClass("WRo", Rook);
Rook.prototype.CanMove = function (nx, ny) {
var dx = (this.x - nx);
var dy = (this.y - ny);
var ok = false;
if ((dx == 0) || (dy == 0)) {
ok = true;
}
if (!ok) {
return(false);
}
return(this.IsRouteClear(nx, ny));
};
Pawn.prototype = new PieceBase();
Object.registerClass("BPa", Pawn);
Object.registerClass("WPa", Pawn);
Pawn.prototype.Threatens = function (nx, ny) {
var dx = (this.x - nx);
var dy = (this.y - ny);
var Direction = ((this.Color == "B") ? -1 : 1);
if ((dy == Direction) && (Math.abs(dx) == 1)) {
return(true);
}
return(false);
};
Pawn.prototype.CanMove = function (nx, ny) {
var dx = (this.x - nx);
var dy = (this.y - ny);
var Direction = ((this.Color == "B") ? -1 : 1);
if ((dy == Direction) && (dx == 0)) {
return(this.IsEmpty(nx, ny));
}
if (((dy == (Direction * 2)) && (dx == 0)) && (this.y == (3.5 + (Direction * 2.5)))) {
if (!this.IsEmpty(nx, ny + Direction)) {
return(false);
}
return(this.IsEmpty(nx, ny));
}
if ((dy == Direction) && (Math.abs(dx) == 1)) {
return(this.IsEnemy(nx, ny));
}
return(false);
};
BoardPointer.prototype.GetX = function () {
return(this.xp);
};
BoardPointer.prototype.SetX = function (value) {
this.xp = (value + 8) % 8;
this.Draw();
};
BoardPointer.prototype.GetY = function () {
return(this.yp);
};
BoardPointer.prototype.SetY = function (value) {
this.yp = (value + 8) % 8;
this.Draw();
};
BoardPointer.prototype.Draw = function () {
this.Target1._visible = this.Visible;
this.Target2._visible = this.Visible;
if (!this.Visible) {
return(undefined);
}
this.Target1._x = (this.xp * 80) + 41;
this.Target1._y = (this.yp * 80) + 41;
this.Target2._x = (this.xp * 80) + 41;
this.Target2._y = (this.yp * 80) + 41;
var t = (Board[this.xp][this.yp].Color == this.Colour);
this.T1C.setRGB((t ? (this.ActiveRGB) : (this.InactiveRGB)));
this.T2C.setRGB((t ? (this.ActiveRGB) : (this.InactiveRGB)));
};
BoardPointer.prototype.Go = function (x, y) {
this.xp = x;
this.yp = y;
this.Visible = true;
this.Draw();
};
BoardPointer.prototype.Hide = function () {
this.Visible = false;
this.Draw();
};
Cookie.prototype.Load = function () {
var so = SharedObject.getLocal(this.CookieName);
for (var n in so.data) {
if (n == "CookieName") {
continue;
}
this[n] = so.data[n];
}
};
Cookie.prototype.Save = function () {
var so = SharedObject.getLocal(this.CookieName);
for (var n in this) {
if (n == "CookieName") {
continue;
}
so.data[n] = this[n];
}
return(so.flush());
};
if (!Initialized) {
KeyListener = new Object();
KeyListener.Parent = this;
KeyListener.onKeyDown = function () {
this.Parent.KeyDown();
};
KeyListener.onKeyUp = function () {
this.Parent.KeyUp();
};
Key.addListener(KeyListener);
InputLabels = new Array("W, A, S and D / Space", "Arrow keys / Numpad zero", "Mouse");
ConsecutiveLabels = new Array("No", "Yes");
EnergyLabels = new Array("Zero (game will end in check)", "100", "300", "1000");
BloodLabels = new Array("None", "Petty", "Feasible", "Ridiculous");
Settings = new Cookie("Settings");
if (Settings.P1Input == null) {
Settings.P1Input = 1;
}
if (Settings.P2Input == null) {
Settings.P2Input = 2;
}
if (Settings.ConsecutiveMoves == null) {
Settings.ConsecutiveMoves = 0;
}
if (Settings.KingEnergy == null) {
Settings.KingEnergy = 1;
}
if (Settings.Blood == null) {
Settings.Blood = 2;
}
Initialized = true;
}
MainTitle.gotoAndStop(Math.floor(Math.random() * 10) + 1);
stop();
Frame 3
DisplaySettings();
Frame 4
InitializeGame();
Symbol 92 Button
on (release) {
gotoAndStop (2);
}
Symbol 93 Button
on (release) {
gotoAndStop (3);
}
Symbol 94 Button
on (release) {
gotoAndStop (4);
}
Symbol 106 Button
on (release) {
gotoAndStop (1);
}
Symbol 111 Button
on (release) {
ChangeSetting(1);
}
Symbol 112 Button
on (release) {
ChangeSetting(2);
}
Symbol 113 Button
on (release) {
ChangeSetting(3);
}
Symbol 114 Button
on (release) {
ChangeSetting(4);
}
Symbol 115 Button
on (release) {
ChangeSetting(5);
}
Symbol 140 MovieClip Frame 1
stop();
Symbol 148 Button
on (release) {
gotoAndStop (1);
}