@@ -41,8 +41,8 @@ function testJestConnection() {
41
41
42
42
// DOM Elements
43
43
44
- const playMatrixView = document . querySelector ( '.play-matrix' )
45
- const playerScoreView = document . querySelector ( '.info .score-span' )
44
+ const playMatrixView = document . querySelector ( '.player0 . play-matrix' )
45
+ const playerScoreView = document . querySelector ( '.player0 . info .score-span' )
46
46
const globalPlayButton = document . querySelector ( '.play-button' )
47
47
const pageMain = document . querySelector ( 'main' )
48
48
const playerCoreHTML = '<div class="info"><p>Score: <span class="score-span">000</span></p><ul class="controls"><p>Controls:</p></ul></div><div class="play-decorator"><div class="play-matrix"></div></div>'
@@ -242,13 +242,16 @@ const playerInputScheme = {
242
242
243
243
// **************************************************************************
244
244
// Build play window
245
-
246
245
class TetrisGame {
247
246
constructor ( playerNumber = 1 , displayParent = pageMain ) {
248
247
this . playerNumber = playerNumber
249
248
this . playerName = 'player' + playerNumber
250
249
this . displayParent = displayParent
250
+ this . playerSection = { }
251
+ this . playMatrixView = { }
251
252
this . coreHTML = playerCoreHTML
253
+ this . playMatrix = [ ]
254
+ this . landedShape = [ ]
252
255
253
256
this . initPlayspace ( )
254
257
}
@@ -260,7 +263,11 @@ class TetrisGame {
260
263
261
264
this . displayParent . appendChild ( newPlayerSection )
262
265
263
- this . playerSection = newPlayerSection
266
+ this . playMatrixView = newPlayerSection . querySelector ( '.play-matrix' )
267
+
268
+ const buildReturn = buildNewPlayMatrix ( playMatrixHeight + maxShapeSize , playMatrixWidth , this . playMatrixView )
269
+ this . playMatrix = buildReturn [ 0 ]
270
+ this . landedShape = buildReturn [ 1 ]
264
271
}
265
272
}
266
273
@@ -271,7 +278,7 @@ players.push(new TetrisGame)
271
278
272
279
const tetrominoSpawnYX = [ tetrominoSpawnXY [ 1 ] , tetrominoSpawnXY [ 0 ] ]
273
280
274
- function buildNewPlayMatrix ( height , width ) {
281
+ function buildNewPlayMatrix ( height , width , playMatrixView ) {
275
282
playMatrixView . innerHTML = ''
276
283
playMatrix = new Array
277
284
landedShape = new LandedShape
@@ -288,10 +295,10 @@ function buildNewPlayMatrix(height, width){
288
295
playMatrix [ y ] . push ( playCell )
289
296
}
290
297
}
291
- return ( playMatrix , landedShape )
298
+ return [ playMatrix , landedShape ]
292
299
}
293
300
294
- buildNewPlayMatrix ( playMatrixHeight + maxShapeSize , playMatrixWidth ) //todo: refactor to use return
301
+ buildNewPlayMatrix ( playMatrixHeight + maxShapeSize , playMatrixWidth , playMatrixView ) //todo: refactor to use return
295
302
296
303
// inject control legend
297
304
for ( const controlKey in playerInputScheme ) { //todo: refactor to for-of
0 commit comments