Skip to content

Commit 3ed0ba7

Browse files
committed
duplicate play field
1 parent a216dc3 commit 3ed0ba7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

scripts/tetris.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ function testJestConnection() {
4444
const playMatrixView = document.querySelector('.play-matrix')
4545
const playerScoreView = document.querySelector('.info .score-span')
4646
const globalPlayButton = document.querySelector('.play-button')
47+
const pageMain = document.querySelector('main')
48+
const playerCoreHTML = '<div class="info"><p>Score:&nbsp;<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>'
4749
// **************************************************************************
4850
// Variables
4951

5052
const isDebugMode = false
5153

54+
const players = []
55+
5256
const playMatrixHeight = 20
5357
const playMatrixWidth = 16
5458
let playMatrix = new Array
@@ -238,6 +242,33 @@ const playerInputScheme = {
238242

239243
// **************************************************************************
240244
// Build play window
245+
246+
class TetrisGame {
247+
constructor(playerNumber = 1, displayParent = pageMain){
248+
this.playerNumber = playerNumber
249+
this.playerName = 'player' + playerNumber
250+
this.displayParent = displayParent
251+
this.coreHTML = playerCoreHTML
252+
253+
this.initPlayspace()
254+
}
255+
256+
initPlayspace(){
257+
const newPlayerSection = document.createElement('section')
258+
newPlayerSection.classList.add(this.playerName)
259+
newPlayerSection.innerHTML = this.coreHTML
260+
261+
this.displayParent.appendChild(newPlayerSection)
262+
263+
this.playerSection = newPlayerSection
264+
}
265+
}
266+
267+
players.push(new TetrisGame)
268+
269+
270+
271+
241272
const tetrominoSpawnYX = [tetrominoSpawnXY[1],tetrominoSpawnXY[0]]
242273

243274
function buildNewPlayMatrix(height, width){

0 commit comments

Comments
 (0)