trust/js/slides/2_Slides_Iterated.js

99 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-07-12 13:42:17 +00:00
SLIDES.push({
id: "iterated",
onjump: function(self){
// Iterated Simulation
2017-07-13 18:49:49 +00:00
self.add({id:"iterated", type:"Iterated", x:130, y:183});
2017-07-12 18:59:22 +00:00
self.objects.iterated.dehighlightPayoff();
2017-07-12 13:42:17 +00:00
},
onstart: function(self){
2017-07-13 18:49:49 +00:00
// Move it
self.objects.iterated.dom.style.top = 183;
// Scoreboard!
self.add({id:"scoreboard", type:"IteratedScoreboard", x:378, y:85});
// Extra info up top
_.yourTotalScore = 0;
self.add({
id:"info", type:"TextBox",
x:378, y:45, width:200, height:50, align:"center", size:15
});
var _showInfo = function(){
var infoWords = Words.get("iterated_info_1")+ROUND_INDEX+"/"+ROUNDS.length;
infoWords += "<br>";
infoWords += Words.get("iterated_info_2")+_.yourTotalScore;
self.objects.info.setText(infoWords);
};
2017-07-12 13:42:17 +00:00
// ROUNDS
var ROUNDS = [
{id:"tft", num:5},
2017-07-13 18:49:49 +00:00
{id:"all_d", num:4},
2017-07-12 13:42:17 +00:00
//{id:"all_c", num:4},
//{id:"grudge", num:5},
//{id:"prober", num:7}
];
ROUND_INDEX = 0;
ROUND_NUM = 0;
self.add({
2017-07-13 18:49:49 +00:00
id:"buttonCheat", type:"Button", x:275, y:453, uppercase:true,
2017-07-12 13:42:17 +00:00
text_id:"label_cheat",
message:"iterated/cheat"
});
self.add({
2017-07-13 18:49:49 +00:00
id:"buttonCooperate", type:"Button", x:495, y:450, uppercase:true,
2017-07-12 13:42:17 +00:00
text_id:"label_cooperate",
message:"iterated/cooperate"
});
2017-07-13 15:07:33 +00:00
listen(self, "iterated/round/start", function(){
2017-07-12 13:42:17 +00:00
publish("buttonCheat/deactivate");
publish("buttonCooperate/deactivate");
});
2017-07-13 18:49:49 +00:00
listen(self, "iterated/round/end", function(payoffA, payoffB){
2017-07-12 13:42:17 +00:00
publish("buttonCheat/activate");
publish("buttonCooperate/activate");
2017-07-13 18:49:49 +00:00
// Add score!
self.objects.scoreboard.addScore(payoffA, payoffB);
_.yourTotalScore += payoffA;
_showInfo();
2017-07-12 13:42:17 +00:00
// Next round
ROUND_NUM++;
if(ROUND_NUM >= ROUNDS[ROUND_INDEX].num){
// Next opponent
ROUND_NUM = 0;
ROUND_INDEX++;
if(ROUND_INDEX >= ROUNDS.length){
publish("slideshow/scratch"); // NEXT SLIDE, WHATEVER
}else{
publish("iterated/newOpponent",[ROUNDS[ROUND_INDEX].id]);
2017-07-13 18:49:49 +00:00
self.objects.scoreboard.reset();
_showInfo();
2017-07-12 13:42:17 +00:00
}
}
});
2017-07-13 18:49:49 +00:00
_showInfo();
2017-07-12 13:42:17 +00:00
},
onend: function(self){
2017-07-13 15:07:33 +00:00
unlisten(self);
2017-07-12 13:42:17 +00:00
self.clear();
}
});