Frame 1
function relayfunc(a, b) {
igame.DrawHistogram(a, b);
}
mc = this.createEmptyMovieClip("field", 10);
igame = new game(mc, 1);
flash.external.ExternalInterface.addCallback("Histogram", null, relayfunc);
Symbol 9 MovieClip [__Packages.game] Frame 0
class game
{
var mc, p0, p1, p2, s, u, tf, rtf, labelsf, instruction, ScoreGame, DrawGame, DrawColor, sp, radius, Inaccuracy, result, GameNumber, TotalTime, RoundStartTime, TimeReported, GameScores, GamesPlayed, GameNames, FinalDelay, GameActive, TimerRunning, mouseDown, GameScored;
function game (mcp, game) {
mc = mcp;
p0 = new point();
p1 = new point();
p2 = new point();
s = new point();
u = new point();
tf = new TextFormat();
tf.size = 18;
tf.font = "Arial";
rtf = new TextFormat();
rtf.size = 14;
rtf.font = "Arial";
ClearScores();
InitGame();
_root.onEnterFrame = function () {
_root.igame.EnterFrame();
};
_root.onMouseDown = function () {
_root.igame.MouseDown();
};
_root.onMouseUp = function () {
_root.igame.MouseUp();
};
_root.Next.onPress = function () {
_root.igame.NextPress();
};
_root.PlayAgain.onPress = function () {
_root.igame.PlayAgainPress();
};
}
function CreateLabel(text, x, y) {
var _local2 = "label" + labelnum;
mc.createTextField(_local2, labelnum, x, y, (text + "").length * labelsf.size, labelsf.size * 2);
mc[_local2].text = text;
mc[_local2].setTextFormat(labelsf);
labelnum = labelnum + 1;
}
function ClearLabels() {
var _local2 = labelnum;
labelnum = 0;
while (labelnum < _local2) {
CreateLabel("", 0, 0);
}
labelnum = 0;
}
function FmtNum(Num) {
var _local2;
Num = Math.round(Num * 10) / 10;
_local2 = Num;
if (Num == int(Num)) {
_local2 = _local2 + ".0";
}
return(_local2);
}
function FmtNum2(Num) {
var _local1;
_local1 = ((Math.round(Num * 100) / 100) + 0.001) + "";
return(_local1.substring(0, _local1.indexOf(".") + 3));
}
function Game0() {
instruction = "Adjust to make a parallelogram";
p0.random();
p1.random();
p2.random();
s.x = (p1.x + p2.x) - p0.x;
s.y = (p1.y + p2.y) - p0.y;
if ((s.x < 50) || (s.x > 350)) {
} else if ((s.y < 70) || (s.y > 350)) {
} else if (p0.lenTo(p1) < 70) {
} else if (p0.lenTo(p2) < 70) {
} else if ((p0.lenTo(p1) * p0.lenTo(p2)) > 25000) {
} else if (p0.slopeFromSquare(p1) < 0.1) {
} else if (p0.slopeFromSquare(p2) < 0.1) {
} else {
var _local2 = p0.angleSpan(p1, p2);
if (_local2 < 0.697777777777778) {
} else if (_local2 > 2.44222222222222) {
} else {
}
}
u = s.randomOffset(30);
ScoreGame = ScoreGame_g;
DrawGame = function (showsoln) {
this.p1.moveTo();
this.mc.lineStyle(2, 0, 100);
this.p0.lineTo();
this.p2.lineTo();
this.mc.lineStyle(2, this.DrawColor, 100);
this.p1.moveTo();
this.sp.lineTo();
this.p2.lineTo();
this.mc.lineStyle(1, this.DrawColor, 100);
this.sp.square();
};
}
function Game1() {
instruction = "Find the mid-point of the line segment";
p0.random();
p1.random();
if (p0.lenTo(p1) < 190) {
} else if (p0.lenTo(p1) > 300) {
} else {
p0.x = Math.round(p0.x / 2) * 2;
p0.y = Math.round(p0.y / 2) * 2;
p1.x = Math.round(p1.x / 2) * 2;
p1.y = Math.round(p1.y / 2) * 2;
}
s.x = (p0.x + p1.x) / 2;
s.y = (p0.y + p1.y) / 2;
u = s.randomOffset(30);
ScoreGame = ScoreGame_g;
DrawGame = function (showsoln) {
this.mc.lineStyle(2, 0, 100);
this.p0.crosshair();
this.p1.crosshair();
this.mc.lineStyle(2, this.DrawColor, 100);
this.p0.moveTo();
this.sp.lineTo();
this.p1.lineTo();
this.mc.lineStyle(1, this.DrawColor, 100);
this.sp.square();
};
}
function Game2() {
instruction = "Bisect the angle";
var _local5;
var _local4;
p0.random();
p1.random();
p2.random();
var _local2 = ((p1.x - p0.x) * (p2.y - p0.y)) - ((p2.x - p0.x) * (p1.y - p0.y));
if (_local2 < 0) {
_local2 = -_local2;
}
if (_local2 < 5000) {
} else if ((p0.lenTo(p1) < 150) || (p0.lenTo(p2) < 150)) {
} else {
_local5 = new vector(p0, p1);
_local4 = new vector(p0, p2);
var _local3 = (_local5.angleTo(_local4) * 180) / Math.PI;
if ((_local3 < 45) | (_local3 > 100)) {
} else {
}
}
var _local6 = _local5.bisect(_local4);
s = _local6.endPoint();
u = s.randomOffset(60);
ScoreGame = ScoreGame_angle;
DrawGame = function (showsoln) {
this.mc.lineStyle(2, 0, 100);
this.p1.moveTo();
this.p0.lineTo();
this.p2.lineTo();
this.p0.arrowTo(this.sp, this.DrawColor);
};
}
function Game3() {
instruction = "Mark the point equidistant to the edges";
p0.random();
p1.random();
p2.random();
var _local2 = ((p1.x - p0.x) * (p2.y - p0.y)) - ((p2.x - p0.x) * (p1.y - p0.y));
if (_local2 < 0) {
_local2 = -_local2;
}
if (_local2 < 25000) {
} else if (_local2 > 75000) {
} else {
}
var _local4;
var _local3;
var _local6;
var _local5;
_local4 = new vector(p0, p1);
_local3 = new vector(p0, p2);
_local6 = _local4.bisect(_local3);
_local4 = new vector(p1, p2);
_local3 = new vector(p1, p0);
_local5 = _local3.bisect(_local4);
_local6.draw();
_local5.draw();
s = _local6.intersect(_local5);
u = s.randomOffset(30);
DrawGame = DrawGame3;
ScoreGame = ScoreGame_g;
}
function DrawGame3(showsoln) {
p0.moveTo();
mc.lineStyle(2, 0, 100);
p1.lineTo();
p2.lineTo();
p0.lineTo();
if (showsoln) {
mc.lineStyle(1, DrawColor, 100);
var _local2 = new vector(p0, p1);
var _local3 = _local2.distPoint(s);
s.circle(_local3);
}
mc.lineStyle(1, DrawColor, 100);
sp.crosshair();
sp.square();
}
function Game4() {
instruction = "Mark the center of the circle";
radius = (Math.random() * 40) + 120;
p0.x = Math.round(((Math.random() * ((500 - (radius * 2)) - 20)) + radius) + 10);
p0.y = Math.round(((Math.random() * ((500 - (radius * 2)) - 50)) + radius) + 30);
s.x = p0.x;
s.y = p0.y;
u = s.randomOffset(40);
ScoreGame = ScoreGame_g;
DrawGame = function (showsoln) {
this.mc.lineStyle(2, 0, 100);
this.p0.circle(this.radius);
this.mc.lineStyle(1, this.DrawColor, 100);
this.sp.crosshair();
this.sp.square();
};
}
function Game5() {
instruction = "Make a right angle";
p0.random();
p1.random();
if (p0.lenTo(p1) < 200) {
} else if (p0.slopeFromSquare(p1) < 0.2) {
} else {
s.x = p0.x + (p1.y - p0.y);
s.y = p0.y - (p1.x - p0.x);
if ((s.x > 440) | (s.x < 60)) {
} else if ((s.y > 460) | (s.y < 60)) {
} else {
}
}
u = s.randomOffset(50);
ScoreGame = ScoreGame_angle;
DrawGame = function (showsoln) {
this.mc.lineStyle(2, 0, 100);
this.p0.moveTo();
this.p1.lineTo();
this.p0.arrowTo(this.sp, this.DrawColor);
};
}
function Game6() {
instruction = "Find the point of convergence";
var _local4;
s.x = Math.round(150 + (Math.random() * 200));
s.y = Math.round(160 + (Math.random() * 200));
var _local8 = [p0, p1, p2];
var _local6;
_local4 = 0;
for ( ; _local4 < 3 ; _local4++) {
var _local7 = _local8[_local4];
for(;;){
_local7.x = 100 + (Math.random() * 300);
_local7.y = 100 + (Math.random() * 300);
var _local5 = s.lenTo(_local7);
if ((_local5 < 100) || (_local5 > 220)) {
} else {
_local6 = false;
var _local2 = 0;
while (_local2 < _local4) {
if (s.angleSpan(_local8[_local2], _local7) < 0.523333333333333) {
_local6 = true;
}
_local2++;
}
if (!_local6) {
continue;
}
}
};
}
u = s.randomOffset(50);
ScoreGame = ScoreGame_g;
DrawGame = function (showsoln) {
var _local5 = [this.p0, this.p1, this.p2];
var _local3;
this.mc.lineStyle(1, this.DrawColor, 100);
_local3 = 0;
while (_local3 < 3) {
this.sp.moveTo();
_local5[_local3].lineTo();
_local3++;
}
this.mc.lineStyle(2, 0, 100);
_local3 = 0;
while (_local3 < 3) {
var _local4 = _local5[_local3];
var _local2 = this.s.vectorTo(_local4);
_local2.normalize();
_local2.x = (_local2.x * 200) + _local4.x;
_local2.y = (_local2.y * 200) + _local4.y;
_local2.moveTo();
_local2.arrowTo(_local4);
_local3++;
}
this.mc.lineStyle(1, this.DrawColor, 100);
this.sp.crosshair();
this.sp.square();
};
}
function ScoreGame_g() {
Inaccuracy = s.lenTo(u);
Inaccuracy = Math.round(Inaccuracy * 10) / 10;
result = ("Accurate to " + FmtNum(Inaccuracy)) + " units";
}
function ScoreGame_angle() {
var _local2 = (p0.angleSpan(u, s) * 180) / Math.PI;
if (_local2 > 90) {
_local2 = _local2 - 180;
}
if (_local2 < -90) {
_local2 = _local2 + 180;
}
Inaccuracy = Math.round((Math.abs(_local2) * 2) * 10) / 10;
result = ("Accurate to " + FmtNum(Inaccuracy)) + " units";
}
function InitGame() {
switch (GameNumber) {
case 0 :
Game0();
break;
case 1 :
Game1();
break;
case 2 :
Game2();
break;
case 3 :
Game3();
break;
case 4 :
Game4();
break;
case 5 :
Game5();
break;
case 6 :
Game6();
}
_root.instr.text = instruction;
_root.instr.setTextFormat(tf);
_root.result.text = "";
mc.clear();
DrawColor = 255;
DrawIt(0);
}
function DrawIt(ShowSoln) {
sp = (ShowSoln ? (s) : (u));
DrawGame(ShowSoln);
}
function ScoreIt() {
TotalTime = TotalTime + (getTimer() - RoundStartTime);
TimeReported = TotalTime;
flash.external.ExternalInterface.call("TotalTime", TotalTime);
trace("scoreit " + TotalTime);
mc.clear();
DrawColor = 45056;
DrawIt(1);
DrawColor = 255;
DrawIt(0);
ScoreGame();
_root.result.text = result;
_root.result.setTextFormat(rtf);
GameScores[GameNumber].push(Inaccuracy);
GamesPlayed = GamesPlayed + 1;
flash.external.ExternalInterface.call("OneScore", GameNames[GameNumber], GameNumber, Inaccuracy);
if (GamesPlayed >= (NumGameTypes * 3)) {
FinalDelay = 20;
}
}
function DrawHistogram(YourScore, Bars) {
var _local3 = 300;
var _local2;
var _local8 = 1;
var _local9;
var _local4 = 0;
while (_local4 < 50) {
if (Bars[_local4] > _local8) {
_local8 = Bars[_local4];
}
_local4++;
}
_local9 = 150 / _local8;
_local4 = 0;
while (_local4 < 50) {
var _local5;
var _local7 = 7;
_local2 = (_local4 * 9) + 20;
if (Bars[_local4]) {
_local5 = _local3 - (Bars[_local4] * _local9);
} else {
_local5 = _local3;
}
mc.moveTo(_local2, _local3);
mc.lineStyle(1, 9474192, 100);
mc.beginFill(12632256);
mc.lineTo(_local2 + _local7, _local3);
mc.lineTo(_local2 + _local7, _local5);
mc.lineTo(_local2, _local5);
mc.lineTo(_local2, _local3);
mc.endFill();
_local4++;
}
var _local10 = new TextFormat();
_local10.size = 16;
_local10.font = "Arial";
_local10.align = "left";
labelsf = _local10;
_local4 = 0;
while (_local4 <= 25) {
_local2 = (_local4 * 18) + 20;
mc.moveTo(_local2, _local3 + 2);
mc.lineTo(_local2, _local3 + 8);
CreateLabel(_local4, _local2 - 8, _local3 + 10);
_local4 = _local4 + 2;
}
CreateLabel("best", 12, _local3 + 25);
CreateLabel("worse", 430, _local3 + 25);
_local2 = (YourScore * 18) + 20;
var _local5 = (_local3 - (Bars[Math.floor(YourScore * 2)] * _local9)) - 5;
mc.lineStyle(2, 255, 100);
mc.moveTo(_local2, _local5);
mc.lineTo(_local2, _local3 - 165);
mc.moveTo(_local2 - 3, _local5 - 8);
mc.lineTo(_local2, _local5);
mc.lineTo(_local2 + 3, _local5 - 8);
labelsf.size = 18;
labelsf.color = 255;
CreateLabel("You", _local2 - 18, _local3 - 190);
labelsf.color = 0;
labelsf.size = 17;
CreateLabel("Scores distribution of last 10,000 games:", 12, _local3 - 220);
}
function EndGame() {
var _local4;
var _local3;
var _local6;
var _local8;
var _local9 = [];
mc.clear();
GameActive = false;
_local8 = 0;
_local6 = _local8;
_local3 = 0;
while (_local3 < NumGameTypes) {
var _local5;
var _local10;
_local5 = 0;
_local4 = 0;
while (_local4 < GameScores[_local3].length) {
_local5 = _local5 + GameScores[_local3][_local4];
_local4++;
}
_local6 = _local6 + _local5;
_local8 = _local8 + GameScores[_local3].length;
_local9[_local3] = _local5 / GameScores[_local3].length;
_local3++;
}
_local6 = _local6 / _local8;
_root.instr.text = "Game Completed";
_root.result.text = "";
_root.PlayAgain._y = 465;
labelsf = tf;
CreateLabel("Overall score: " + FmtNum2(_local6), 162, 370);
CreateLabel("Total time: " + FmtNum2(TotalTime / 1000), 170, 400);
var _local7 = Math.round(_local6 * 100000);
_local6 = _local7 / 100000;
_local7 = (_local7 + 11721) - ((_local7 % 11722) * 2);
_local7 = (_local7 + 621) - ((_local7 % 622) * 2);
_local7 = _local7 + Math.floor(TotalTime / 11);
flash.external.ExternalInterface.call("FinalScore", _local6, TotalTime, _local9, _local7);
}
function NextGame() {
GameNumber = GameNumber + 1;
if (GameNumber >= NumGameTypes) {
GameNumber = 0;
}
InitGame();
RoundStartTime = getTimer();
TimerRunning = true;
}
function NextPress() {
if (!mouseDown) {
GameScored = false;
_root.Next._y = -20;
if (GamesPlayed < (NumGameTypes * 3)) {
NextGame();
} else {
EndGame();
}
}
}
function ClearScores() {
GameScores = [];
var _local3 = 0;
while (_local3 < NumGameTypes) {
GameScores[_local3] = [];
_local3++;
}
ClearLabels();
GameNumber = 0;
GamesPlayed = 0;
TotalTime = 0;
TimeReported = 0;
GameScored = false;
GameActive = true;
TotalTime = 0;
TimerRunning = false;
FinalDelay = 0;
_root.Next._y = -100;
_root.PlayAgain._y = -100;
GameNames = ["Parallelogram", "Midpoint", "Bisect angle", "Triangle center", "Circle center", "Right angle", "Convergence"];
flash.external.ExternalInterface.call("GameStart", GameNames);
flash.external.ExternalInterface.call("TotalTime", 0);
}
function PlayAgainPress() {
ClearScores();
InitGame();
}
function EnterFrame() {
if (!GameActive) {
return(undefined);
}
if (mouseDown) {
u.x = _xmouse;
u.y = _ymouse;
mc.clear();
DrawIt(0);
}
var _local2;
_local2 = (TotalTime + getTimer()) - RoundStartTime;
if (TimerRunning && ((_local2 - TimeReported) > 100)) {
TimeReported = _local2;
flash.external.ExternalInterface.call("TotalTime", TimeReported);
trace("time = " + TimeReported);
}
if (FinalDelay) {
if ((--FinalDelay) == 0) {
NextPress();
}
}
}
function MouseDown() {
if (!GameActive) {
return(undefined);
}
if (!GameScored) {
mouseDown = true;
if (!TimerRunning) {
RoundStartTime = getTimer();
TimerRunning = true;
}
Mouse.hide();
EnterFrame();
}
}
function MouseUp() {
Mouse.show();
if (!GameActive) {
return(undefined);
}
if (!GameScored) {
if (mouseDown) {
mouseDown = false;
ScoreIt();
GameScored = true;
TimerRunning = false;
_root.Next._y = 495;
}
}
}
static var NumGameTypes = 7;
var labelnum = 0;
}
Symbol 10 MovieClip [__Packages.point] Frame 0
class point
{
var x, y;
function point () {
}
function random() {
x = Math.round((Math.random() * 350) + 75);
y = Math.round((Math.random() * 350) + 80);
}
function set(px, py) {
x = px;
y = py;
}
function lenTo(p2) {
var _local3;
_local3 = Math.sqrt(((p2.x - x) * (p2.x - x)) + ((p2.y - y) * (p2.y - y)));
return(_local3);
}
function angleSpan(p1, p2) {
var _local4 = Math.atan2(p1.y - y, p1.x - x);
var _local3 = Math.atan2(p2.y - y, p2.x - x);
var _local2 = _local4 - _local3;
if (_local2 < 0) {
_local2 = -_local2;
}
if (_local2 > Math.PI) {
_local2 = (Math.PI*2) - _local2;
}
return(_local2);
}
function vectorTo(p1) {
var _local2 = new point();
_local2.x = p1.x - x;
_local2.y = p1.y - y;
return(_local2);
}
function slopeFromSquare(p1) {
var _local2 = Math.abs(p1.x - x);
var _local3 = Math.abs(p1.y - y);
if (_local3 > _local2) {
var _local4 = _local2;
_local2 = _local3;
_local3 = _local2;
}
return(_local3 / _local2);
}
function randomOffset(dist) {
var _local2 = new point();
_local2.x = x + ((Math.random() - 0.5) * (dist * 2));
_local2.y = y + ((Math.random() - 0.5) * (dist * 2));
return(_local2);
}
function normalize() {
var _local2 = Math.sqrt((x * x) + (y * y));
x = x / _local2;
y = y / _local2;
}
function moveTo() {
_root.mc.moveTo(x, y);
}
function lineTo() {
_root.mc.lineTo(x, y);
}
function crosshair() {
_root.mc.moveTo(x - 5, y);
_root.mc.lineTo(x + 5, y);
_root.mc.moveTo(x, y - 5);
_root.mc.lineTo(x, y + 5);
}
function square() {
_root.mc.moveTo(x + 8, y + 8);
_root.mc.lineTo(x + 8, y - 8);
_root.mc.lineTo(x - 8, y - 8);
_root.mc.lineTo(x - 8, y + 8);
_root.mc.lineTo(x + 8, y + 8);
}
function arrowTo(to, color) {
_root.mc.lineStyle(2, color, 100);
moveTo(x, y);
to.lineTo();
var _local6 = new point();
var _local5 = new point();
var _local3 = vectorTo(to);
_local3.normalize();
_local3.x = _local3.x * -10;
_local3.y = _local3.y * -10;
_root.mc.lineStyle(1, color, 100);
_local6.x = (to.x + _local3.x) - (_local3.y / 2);
_local6.y = (to.y + _local3.y) + (_local3.x / 2);
_local5.x = (to.x + _local3.x) + (_local3.y / 2);
_local5.y = (to.y + _local3.y) - (_local3.x / 2);
_local6.moveTo();
to.lineTo();
_local5.lineTo();
}
function circle(radius) {
_root.mc.moveTo(x + radius, y);
arc(0, (Math.PI*2), radius);
}
function arc(a1, a2, radius) {
var _local11 = radius;
var _local13 = Math.floor(Math.abs(a2 - a1) * 1.5) + 1;
var _local10 = (a2 - a1) / _local13;
var _local12 = radius / Math.cos(_local10 / 2);
var _local4 = a1;
var _local5 = a1 - (_local10 / 2);
_root.mc.lineTo(x + (Math.cos(_local4) * _local11), y + (Math.sin(_local4) * _local11));
var _local3 = 0;
while (_local3 < _local13) {
_local4 = _local4 + _local10;
_local5 = _local5 + _local10;
var _local9 = _local11 * Math.cos(_local4);
var _local8 = _local11 * Math.sin(_local4);
var _local7 = _local12 * Math.cos(_local5);
var _local6 = _local12 * Math.sin(_local5);
_root.mc.curveTo(x + _local7, y + _local6, x + _local9, y + _local8);
_local3++;
}
}
}
Symbol 11 MovieClip [__Packages.vector] Frame 0
class vector
{
var x, y, dx, dy;
function vector (p1, p2) {
x = p1.x;
y = p1.y;
dx = p2.x - x;
dy = p2.y - y;
}
function angleTo(v2) {
var _local4 = Math.atan2(dy, dx);
var _local3 = Math.atan2(v2.dy, v2.dx);
var _local2 = _local4 - _local3;
if (_local2 < 0) {
_local2 = -_local2;
}
if (_local2 > Math.PI) {
_local2 = (Math.PI*2) - _local2;
}
return(_local2);
}
function clone() {
var _local2 = new vector();
_local2.x = x;
_local2.y = y;
_local2.dx = dx;
_local2.dy = dy;
return(_local2);
}
function bisect(v2) {
var _local2 = clone();
var _local3 = v2.clone();
_local2.normalize();
_local3.normalize();
_local2.dx = _local2.dx + _local3.dx;
_local2.dy = _local2.dy + _local3.dy;
_local2.normalize();
var _local4 = (vlength() + v2.vlength()) / 2;
_local2.dx = _local2.dx * _local4;
_local2.dy = _local2.dy * _local4;
return(_local2);
}
function intersect(v2) {
function add_arr(a1, a2, mult) {
var _local1 = 0;
while (_local1 < 3) {
a1[_local1] = a1[_local1] + (a2[_local1] * mult);
_local1++;
}
}
var _local6;
var _local13;
var _local11;
var _local5;
var _local12;
var _local10;
var _local4 = [dy, -dx, (x * dy) - (y * dx)];
var _local3 = [v2.dy, -v2.dx, (v2.x * v2.dy) - (v2.y * v2.dx)];
if (Math.abs(_local3[0]) > Math.abs(_local4[0])) {
var _local9 = _local3;
_local3 = _local4;
_local4 = _local9;
}
add_arr(_local3, _local4, (-_local3[0]) / _local4[0]);
add_arr(_local4, _local3, (-_local4[1]) / _local3[1]);
var _local8 = new point();
_local8.set(_local4[2] / _local4[0], _local3[2] / _local3[1]);
return(_local8);
}
function distPoint(p) {
var _local2 = ((-(p.x - x)) * dy) + ((p.y - y) * dx);
return(_local2 / vlength());
}
function endPoint() {
var _local2 = new point();
_local2.set(x + dx, y + dy);
return(_local2);
}
function vlength() {
return(Math.sqrt((dx * dx) + (dy * dy)));
}
function normalize() {
var _local2 = Math.sqrt((dx * dx) + (dy * dy));
dx = dx / _local2;
dy = dy / _local2;
}
function draw() {
_root.mc.moveTo(x, y);
_root.mc.lineTo(x + dx, y + dy);
}
}