@@ -4,6 +4,8 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
4
4
this . circleswidth = 0 ;
5
5
this . circlesheight = 0 ;
6
6
this . colours = [ xocolor . stroke , xocolor . fill ] ;
7
+ this . level = 4 ;
8
+ this . turns = 1 ;
7
9
8
10
this . gridwidth = 7 ;
9
11
this . gridheight = 7 ;
@@ -17,7 +19,6 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
17
19
this . solveTimeout ;
18
20
this . newGameTimeout ;
19
21
20
-
21
22
//Helper functions
22
23
this . radiusFromX = function ( ) {
23
24
this . margin = 1 / 50 * stage . canvas . width ;
@@ -64,8 +65,10 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
64
65
}
65
66
66
67
//Flipping
67
-
68
68
this . flip = function ( x , y , playing , stack ) {
69
+ this . turns = this . turns + 1 ;
70
+ document . getElementById ( "turnno" ) . innerHTML = " " + ( this . turns ) ;
71
+ this . drawIndicator ( ) ;
69
72
if ( playing === undefined ) { playing = true ; }
70
73
if ( stack === undefined ) { stack = true ; }
71
74
if ( stack ) {
@@ -91,6 +94,28 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
91
94
}
92
95
}
93
96
}
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
+ }
94
119
95
120
this . getRandomInt = function ( min , max ) {
96
121
return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
@@ -143,6 +168,8 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
143
168
arr . startgridwidth = this . startgridwidth ;
144
169
arr . startgridheight = this . startgridheight ;
145
170
arr . dots = [ ] ;
171
+ arr . turns = this . turns ;
172
+ arr . indcolour = document . getElementById ( "fliptext" ) . style . borderBottom ;
146
173
for ( var x = 0 ; x < this . startgridwidth ; x ++ ) {
147
174
temparr = [ ] ;
148
175
for ( var y = 0 ; y < this . startgridheight ; y ++ ) {
@@ -232,19 +259,26 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
232
259
for ( var i = 0 ; i < 14 ; i ++ ) {
233
260
this . flipRandomDot ( ) ;
234
261
}
262
+ this . turns = 1 ;
263
+ document . getElementById ( "turnno" ) . innerHTML = " " + ( this . turns ) ;
264
+ document . getElementById ( "fliptext" ) . style . borderBottom = "5px solid #00ff1b" ;
235
265
}
236
266
237
267
this . setSize = function ( size ) {
238
268
this . startgridwidth = size ;
239
269
this . startgridheight = size ;
240
270
this . newGame ( ) ;
271
+ this . level = size ;
241
272
}
242
273
243
274
this . init = function ( ) {
244
275
//console.log("init");
245
276
//console.log(activity.getDatastoreObject());
246
277
this . palette = new sizepalette . SizePalette ( this , doc . getElementById ( 'size-button' ) , undefined ) ;
247
278
activity . getDatastoreObject ( ) . getMetadata ( this . init_canaccessdatastore . bind ( this ) ) ;
279
+ document . getElementById ( "turnno" ) . innerHTML = " " + ( this . turns ) ;
280
+ this . drawIndicator ( ) ;
281
+ this . palette . setUsed ( ) ;
248
282
}
249
283
250
284
this . init_canaccessdatastore = function ( error , mdata ) {
@@ -271,6 +305,8 @@ function Game(stage,xocolor,doc,datastore,activity,sizepalette){
271
305
this . stack = data . stack ;
272
306
this . startgridwidth = data . startgridwidth ;
273
307
this . startgridheight = data . startgridheight ;
308
+ this . turns = data . turns ;
309
+ document . getElementById ( "fliptext" ) . style . borderBottom = data . indcolour ;
274
310
clearTimeout ( this . newGameTimeout ) ;
275
311
clearTimeout ( this . solveTimeout ) ;
276
312
stage . removeAllChildren ( ) ;
0 commit comments