Skip to content

Commit 69eb5a0

Browse files
authored
Merge pull request #234 from FreddieN/dev
Add number of play in Flip activity
2 parents b66335f + 1ec1f3c commit 69eb5a0

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

activities/Flip.activity/css/activity.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ background-size: contain;
6161
border-radius: 5.5px;
6262
background-color: #C0C0C0;
6363
}
64+
#flip-count {
65+
flex: 1;
66+
text-align: center;
67+
font-size: 8vh;
68+
font-weight: 800;
69+
padding-bottom: 2vh;
70+
}

activities/Flip.activity/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
<!-- The content of your activity goes inside the canvas -->
3434
<div id="canvas" style="overflow-y: hidden;">
35+
<div id='flip-count'><span id="fliptext"><span data-l10n-id="turntext"></span><span id="turnno"></span></span></div>
3536
<canvas id="actualcanvas"></canvas>
3637
</div>
3738
</body>

activities/Flip.activity/js/activity.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
define(["sugar-web/activity/activity",'easeljs','tweenjs','activity/game','activity/flipdot'], function (act) {
1+
define(["sugar-web/activity/activity", "webL10n", 'easeljs','tweenjs','activity/game','activity/flipdot'], function (act, webL10n) {
22

33
// Manipulate the DOM only when it is ready.
44
requirejs(['domReady!'], function (doc) {
@@ -9,7 +9,15 @@ define(["sugar-web/activity/activity",'easeljs','tweenjs','activity/game','activ
99
act.getXOColor(function (error, colors) {
1010
runactivity(act,doc,colors,env,datastore,sizepalette);
1111
});
12-
});
12+
env.getEnvironment(function(err, environment) {
13+
currentenv = environment;
14+
15+
// Set current language to Sugarizer
16+
var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
17+
var language = environment.user ? environment.user.language : defaultLanguage;
18+
webL10n.language.code = language;
19+
});
20+
});
1321
});
1422

1523
});
@@ -23,11 +31,14 @@ function runactivity(act,doc,colors,env,datastore,sizepalette){
2331
function init(){
2432
canvas = document.getElementById('actualcanvas');
2533
canvas.width = window.innerWidth;
26-
canvas.height = window.innerHeight-55;
34+
canvas.height = window.innerHeight-200;
2735
stage = new createjs.Stage(canvas);
2836
stage.update();
2937
stage.mouseEventsEnabled = true;
3038

39+
document.getElementById("flip-count").style.color = colors['stroke'];
40+
document.getElementById("fliptext").style.borderBottom = "5px solid #00ff1b";
41+
3142
createjs.Ticker.setFPS(30);
3243
createjs.Ticker.addEventListener("tick", handleTick);
3344
function handleTick() {
@@ -39,7 +50,7 @@ function runactivity(act,doc,colors,env,datastore,sizepalette){
3950
window.addEventListener('resize', resizeCanvas, false);
4051
function resizeCanvas() {
4152
canvas.width = window.innerWidth;
42-
canvas.height = window.innerHeight-55;
53+
canvas.height = window.innerHeight-200;
4354
g.initialiseFromArray();
4455
}
4556

activities/Flip.activity/js/game.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
44
this.circleswidth = 0;
55
this.circlesheight = 0;
66
this.colours = [xocolor.stroke,xocolor.fill];
7+
this.level = 4;
8+
this.turns = 1;
79

810
this.gridwidth = 7;
911
this.gridheight = 7;
@@ -17,7 +19,6 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
1719
this.solveTimeout;
1820
this.newGameTimeout;
1921

20-
2122
//Helper functions
2223
this.radiusFromX = function(){
2324
this.margin = 1/50*stage.canvas.width;
@@ -64,8 +65,10 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
6465
}
6566

6667
//Flipping
67-
6868
this.flip = function(x,y,playing,stack){
69+
this.turns = this.turns+1;
70+
document.getElementById("turnno").innerHTML = " " + (this.turns);
71+
this.drawIndicator();
6972
if (playing===undefined){playing=true;}
7073
if (stack===undefined){stack=true;}
7174
if (stack){
@@ -91,6 +94,28 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
9194
}
9295
}
9396
}
97+
this.drawIndicator = function() {
98+
diffind = this.turns - this.level*3;
99+
console.log(diffind);
100+
switch(diffind){
101+
case 40:
102+
document.getElementById("fliptext").style.borderBottom = "5px solid #f00";
103+
break;
104+
case 30:
105+
document.getElementById("fliptext").style.borderBottom = "5px solid #ff410b";
106+
break;
107+
case 20:
108+
document.getElementById("fliptext").style.borderBottom = "5px solid #ff7e00";
109+
break;
110+
case 10:
111+
document.getElementById("fliptext").style.borderBottom = "5px solid #c7ff00";
112+
break;
113+
case 5:
114+
document.getElementById("fliptext").style.borderBottom = "5px solid #00ff1b";
115+
console.log("12");
116+
break;
117+
}
118+
}
94119

95120
this.getRandomInt = function(min, max) {
96121
return Math.floor(Math.random() * (max - min + 1)) + min;
@@ -143,6 +168,8 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
143168
arr.startgridwidth = this.startgridwidth;
144169
arr.startgridheight = this.startgridheight;
145170
arr.dots = [];
171+
arr.turns = this.turns;
172+
arr.indcolour = document.getElementById("fliptext").style.borderBottom;
146173
for (var x = 0; x<this.startgridwidth; x++){
147174
temparr = [];
148175
for (var y = 0; y<this.startgridheight; y++){
@@ -232,19 +259,26 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
232259
for (var i = 0; i<14; i++){
233260
this.flipRandomDot();
234261
}
262+
this.turns = 1;
263+
document.getElementById("turnno").innerHTML = " " + (this.turns);
264+
document.getElementById("fliptext").style.borderBottom = "5px solid #00ff1b";
235265
}
236266

237267
this.setSize = function(size){
238268
this.startgridwidth = size;
239269
this.startgridheight = size;
240270
this.newGame();
271+
this.level = size;
241272
}
242273

243274
this.init = function(){
244275
//console.log("init");
245276
//console.log(activity.getDatastoreObject());
246277
this.palette = new sizepalette.SizePalette(this,doc.getElementById('size-button'),undefined);
247278
activity.getDatastoreObject().getMetadata(this.init_canaccessdatastore.bind(this));
279+
document.getElementById("turnno").innerHTML = " " + (this.turns);
280+
this.drawIndicator();
281+
this.palette.setUsed();
248282
}
249283

250284
this.init_canaccessdatastore = function(error,mdata){
@@ -271,6 +305,8 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
271305
this.stack = data.stack;
272306
this.startgridwidth = data.startgridwidth;
273307
this.startgridheight = data.startgridheight;
308+
this.turns = data.turns;
309+
document.getElementById("fliptext").style.borderBottom = data.indcolour;
274310
clearTimeout(this.newGameTimeout);
275311
clearTimeout(this.solveTimeout);
276312
stage.removeAllChildren();

activities/Flip.activity/localization.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ five-button.title = 5x5 grid
88
six-button.title = 6x6 grid
99
seven-button.title = 7x7 grid
1010
size-button.title = Change size of grid
11+
turntext = Turn
1112

1213
[en]
1314
activity-button.title = Flip Activity
@@ -17,4 +18,8 @@ solve-button.title = Solve the puzzle
1718
four-button.title = 4x4 grid
1819
five-button.title = 5x5 grid
1920
six-button.title = 6x6 grid
20-
seven-button.title = 7x7 grid
21+
seven-button.title = 7x7 grid
22+
turntext = Turn
23+
24+
[fr]
25+
turntext = Tour

0 commit comments

Comments
 (0)