Created
April 10, 2018 17:32
-
-
Save easierbycode/882a2a88246e04c1f0da1fc3cadecb75 to your computer and use it in GitHub Desktop.
lifelab-tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare var StateMachine: any; | |
import { Component } from '@angular/core'; | |
import { NavController } from 'ionic-angular'; | |
var r, o, s, a; | |
r = function() { | |
function t() {} | |
return t['random'] = function(t, e, n) { | |
var i, r, o, s; | |
if (n > t * e) | |
throw new Error("IT CANNOT BE DONE!!!!"); | |
for (i = this.emptyBoard(t, e), | |
r = 0; n > r; ) | |
o = ~~(Math.random() * t), | |
s = ~~(Math.random() * e), | |
i[o][s] || (i[o][s] = !0, | |
r++); | |
return i | |
} | |
, | |
t['emptyBoard'] = function(t, e) { | |
var n, i, r; | |
return n = function() { | |
var n, o, s; | |
for (s = [], | |
i = n = 0, | |
o = t; o >= 0 ? o > n : n > o; i = o >= 0 ? ++n : --n) | |
s.push(function() { | |
var t, n, i; | |
for (i = [], | |
r = t = 0, | |
n = e; n >= 0 ? n > t : t > n; r = n >= 0 ? ++t : --t) | |
i.push(!1); | |
return i | |
}()); | |
return s | |
}() | |
} | |
, | |
t['equals'] = function(t, e) { | |
var n, i, r, o, s, a, u, l; | |
for (l = n = 0, | |
r = t.length; r > n; l = ++n) | |
for (s = t[l], | |
u = i = 0, | |
o = s.length; o > i; u = ++i) | |
if (a = s[u], | |
a !== e[l][u]) | |
return !1; | |
return !0 | |
} | |
, | |
t['hasAllAnswers'] = function(t, e) { | |
var n, i, r, o, s, a, u, l; | |
for (l = n = 0, | |
r = t.length; r > n; l = ++n) | |
for (s = t[l], | |
u = i = 0, | |
o = s.length; o > i; u = ++i) | |
if (a = s[u], | |
a !== e[l][u] && e[l][u] === !1) | |
return !1; | |
return !0 | |
} | |
, | |
t['numFalsePositives'] = function(t, e) { | |
var n, i, r, o, s, a, u, l, c; | |
for (s = 0, | |
c = n = 0, | |
r = t.length; r > n; c = ++n) | |
for (a = t[c], | |
l = i = 0, | |
o = a.length; o > i; l = ++i) | |
u = a[l], | |
u !== e[c][l] && e[c][l] === !0 && s++; | |
return s | |
} | |
, | |
t | |
}(), | |
s = function() { | |
function t(t) { | |
var e, n; | |
this.actualAnswers = t, | |
this.userAnswers = function() { | |
var t, i, r, o; | |
for (r = this.actualAnswers, | |
o = [], | |
t = 0, | |
i = r.length; i > t; t++) | |
e = r[t], | |
o.push(function() { | |
var t, i, r; | |
for (r = [], | |
t = 0, | |
i = e.length; i > t; t++) | |
n = e[t], | |
r.push(!1); | |
return r | |
}()); | |
return o | |
} | |
.call(this), | |
this.blankBoard = r.emptyBoard(this.actualAnswers.length, this.actualAnswers[0].length), | |
this.squares = this.actualAnswers | |
} | |
return t.prototype.clickedSquare = function(t, e) { | |
return this.userAnswers[e][t] === !0 ? 0 : (this.userAnswers[e][t] = !0, | |
this.userAnswers[e][t] !== this.actualAnswers[e][t] ? -1 : 0) | |
} | |
, | |
t.prototype.checkWinCondition = function() { | |
return r.hasAllAnswers(this.actualAnswers, this.userAnswers) | |
} | |
, | |
t.prototype.numFalsePositives = function() { | |
return r.numFalsePositives(this.actualAnswers, this.userAnswers) | |
} | |
, | |
t | |
}(), | |
o = function() { | |
var t = setTimeout; | |
function n() { | |
this.remainingLives = 3, | |
this.stageNum = 1, | |
this.score = 0, | |
this.combo = 1, | |
this.blockTileClicks = !0, | |
this.highestStage = 0, | |
this.initStage(), | |
this.fsm = StateMachine.create({ | |
initial: "splash", | |
events: [{ | |
name: "start", | |
from: "splash", | |
to: "preflip" | |
}, { | |
name: "showanswers", | |
form: "preflip", | |
to: "flipped" | |
}, { | |
name: "hideanswers", | |
from: "flipped", | |
to: "usertest" | |
}, { | |
name: "endlevel", | |
from: "usertest", | |
to: "levelrecap" | |
}, { | |
name: "endlevelrecap", | |
from: "levelrecap", | |
to: "postrecap" | |
}, { | |
name: "closelevelrecap", | |
from: "postrecap", | |
to: "preflip" | |
}, { | |
name: "endgame", | |
form: "usertest", | |
to: "gameover" | |
}], | |
callbacks: { | |
onpreflip: function(e) { | |
return function() { | |
return e.initStage(), | |
t(function() { | |
return e.fsm.showanswers() | |
}, 500) | |
} | |
}(this), | |
onflipped: function(e) { | |
return function() { | |
return t(function() { | |
return e.fsm.hideanswers() | |
}, 1200) | |
} | |
}(this), | |
onlevelrecap: function(e) { | |
return function(n, i, r, o) { | |
return t(function() { | |
return e.fsm.endlevelrecap(o) | |
}, 500) | |
} | |
}(this), | |
onendlevelrecap: function(e) { | |
return function(n, i, r, o) { | |
return t(function() { | |
return e.fsm.closelevelrecap(o) | |
}, 500) | |
} | |
}(this), | |
onbeforecloselevelrecap: function(t) { | |
return function(e, n, i, r) { | |
return r ? t.stageNum++ : (t.remainingLives--, | |
t.outOfLives() ? (t.fsm.endgame(), | |
!1) : t.stageNum = Math.max(1, t.stageNum - 1)) | |
} | |
}(this) | |
} | |
}) | |
} | |
return n.prototype.classesForSquare = function(t, e) { | |
return { | |
active: this.isActive(t, e), | |
error: this.isError(t, e) | |
} | |
} | |
, | |
n.prototype.isActive = function(t, e) { | |
return this.getDisplaySquares()[e][t] === !0 | |
} | |
, | |
n.prototype.isError = function(t, e) { | |
switch (this.fsm.current) { | |
case "usertest": | |
case "levelrecap": | |
return this.stage.userAnswers[e][t] === !0 && this.stage.actualAnswers[e][t] === !1; | |
default: | |
return !1 | |
} | |
} | |
, | |
n.prototype.getDisplaySquares = function() { | |
switch (this.fsm.current) { | |
case "flipped": | |
return this.stage.actualAnswers; | |
case "usertest": | |
case "levelrecap": | |
return this.stage.userAnswers; | |
default: | |
return this.stage.blankBoard | |
} | |
} | |
, | |
n.prototype.initStage = function() { | |
var t, e, n; | |
return this.highestStage = Math.max(this.highestStage, this.stageNum), | |
e = this.getDimForStage(), | |
t = 2 + this.stageNum, | |
n = r.random(e, e, t), | |
this.stage = new s(n) | |
} | |
, | |
n.prototype.clickedSquare = function(t, e) { | |
var n, i; | |
if ("usertest" === this.fsm.current && this.stage.userAnswers[e][t] !== !0) | |
return i = this.stage.clickedSquare(t, e), | |
0 === i ? (n = this.combo * this.stageNum, | |
this.lastClickScore = n, | |
this.score += n, | |
this.combo++) : this.combo = 1, | |
this.stage.numFalsePositives() >= 3 ? this.fsm.endlevel(!1) : this.stage.checkWinCondition() ? this.fsm.endlevel(!0) : void 0 | |
} | |
, | |
n.prototype.outOfLives = function() { | |
return this.remainingLives <= 0 | |
} | |
, | |
n.prototype.getDimForStage = function() { | |
return ~~Math.sqrt(9 + 3 * this.stageNum) | |
} | |
, | |
n.prototype.individualSquareWidth = function() { | |
var t; | |
return t = Math.floor(this.maxWidthForDevice() / this.getDimForStage() - 1), | |
{ | |
width: t + "px", | |
height: t + "px", | |
borderWidth: t / 16 + "px", | |
borderRadius: t / 8 + "px" | |
} | |
} | |
, | |
n.prototype.maxWidthForDevice = function() { | |
return Math.min(440, window.innerWidth - 50) | |
} | |
, | |
n.prototype.save = function() { | |
var t; | |
return this.saving = !0, | |
t = { | |
score: this.score, | |
highest_level: this.highestStage | |
}//, | |
// e({ | |
// method: "POST", | |
// url: "/tests/memory.json", | |
// data: t | |
// }).then(function(t) { | |
// window.location = "/dashboard" | |
// }) | |
} | |
, | |
n | |
}(), | |
a = function() { | |
// return n.$apply() | |
} | |
/* | |
Generated class for the Memory page. | |
See http://ionicframework.com/docs/v2/components/#navigation for more info on | |
Ionic pages and navigation. | |
*/ | |
@Component({ | |
selector: 'page-memory', | |
templateUrl: 'memory.html' | |
}) | |
export class Memory { | |
testManager; | |
constructor(public navCtrl: NavController) { | |
this.testManager = new o; | |
} | |
ionViewDidLoad() { | |
console.log('Hello Memory Page'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { NavController } from 'ionic-angular'; | |
/* | |
Generated class for the NumberMemory page. | |
See http://ionicframework.com/docs/v2/components/#navigation for more info on | |
Ionic pages and navigation. | |
*/ | |
@Component({ | |
selector: 'page-number-memory', | |
templateUrl: 'number-memory.html' | |
}) | |
export class NumberMemory { | |
currentAnswer; | |
level; | |
state; | |
timeLimit; | |
timerStartedAt; | |
userAnswer; | |
constructor(public navCtrl: NavController) { | |
this.state = "SPLASH"; | |
this.level = 0; | |
} | |
nextQuestion() { | |
this.userAnswer = undefined; | |
var e, n, i, r; | |
this.state = "QUESTION", | |
this.level += 1, | |
i = this.level, | |
n = "" + Math.floor(9 * Math.random() + 1), | |
r = function() { | |
var t, n, r; | |
for (r = [], | |
e = t = 0, | |
n = i - 1; n >= 0 ? n > t : t > n; e = n >= 0 ? ++t : --t) | |
r.push("" + Math.floor(10 * Math.random())); | |
return r | |
}(), | |
this.currentAnswer = n + r.join(""), | |
this.timeLimit = 800 * i + 1e3, | |
this.timerStartedAt = new Date, | |
setTimeout(function(t) { | |
return function() { | |
return t.promptForAnswer() | |
} | |
}(this), this.timeLimit) | |
} | |
promptForAnswer() { | |
this.state = "PROMPT" | |
} | |
submitAnswer(t) { | |
this.userAnswer = t, | |
this.state = "SHOWANSWER" | |
} | |
currentAnswerIsCorrect() { | |
return this.userAnswer === this.currentAnswer | |
} | |
wasDigitRight(t) { | |
return this.userAnswer[t] === this.currentAnswer[t] | |
} | |
onKeydown(t) { | |
13 === t.which && "SHOWANSWER" === this.state && this.currentAnswerIsCorrect() && this.nextQuestion() | |
} | |
getMainClass() { | |
switch (this.state) { | |
case "SHOWANSWER": | |
return this.currentAnswerIsCorrect() ? "correct" : "incorrect"; | |
default: | |
return this.state.toLowerCase() | |
} | |
} | |
getDisplayTimer() { | |
return 1 - ((new Date).getTime() - this.timerStartedAt.getTime()) / this.timeLimit | |
} | |
save() { | |
// e({ | |
// method: "POST", | |
// url: "/tests/number-memory", | |
// params: { | |
// score: this.level, | |
// lastNumber: this.currentAnswer, | |
// lastResponse: this.userAnswer | |
// } | |
// }).then(function() { | |
// window.location = "/dashboard" | |
// }) | |
} | |
ionViewDidLoad() { | |
console.log('Hello NumberMemory Page'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment