From 2bd4c640bd2a5b61728b0ba9fb9d55f2348da1d9 Mon Sep 17 00:00:00 2001 From: Pratham Gupta Date: Fri, 21 Aug 2020 18:51:25 +0530 Subject: [PATCH] getters and setters for player, card, structuring --- client/index.ejs | 12 ++++---- client/js/Card.js | 12 -------- client/js/Player.js | 13 -------- client/js/cardStack.js | 15 --------- client/js/elements/Card.js | 24 +++++++++++++++ client/js/{ => elements}/Game.js | 6 ++-- client/js/elements/Player.js | 32 ++++++++++++++++++++ client/js/{submitCard.js => modal.js} | 0 client/js/render-elements/renderButton.js | 3 +- client/js/render-elements/renderStackCard.js | 15 +++++++++ 10 files changed, 81 insertions(+), 51 deletions(-) delete mode 100644 client/js/Card.js delete mode 100644 client/js/Player.js delete mode 100644 client/js/cardStack.js create mode 100644 client/js/elements/Card.js rename client/js/{ => elements}/Game.js (96%) create mode 100644 client/js/elements/Player.js rename client/js/{submitCard.js => modal.js} (100%) create mode 100644 client/js/render-elements/renderStackCard.js diff --git a/client/index.ejs b/client/index.ejs index 0086511..6e49ed4 100644 --- a/client/index.ejs +++ b/client/index.ejs @@ -4,21 +4,21 @@ - - - - + + + - - + + + diff --git a/client/js/Card.js b/client/js/Card.js deleted file mode 100644 index c410ef3..0000000 --- a/client/js/Card.js +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* - * Card class whose objects are used inside Game Decks. - */ - -class Card { - constructor (cardSuit, cardValue, cardId) { - this.suit = cardSuit - this.value = cardValue - this.id = cardId - } -} diff --git a/client/js/Player.js b/client/js/Player.js deleted file mode 100644 index bae9f25..0000000 --- a/client/js/Player.js +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint-disable no-unused-vars */ -// Creating the player containing the name of the player, -// number of cards of the player and cards that the player has -// and the cards he has selected - -class Player { - constructor (name) { - this.name = name - this.cards = [] - this.numberOfCards = 0 - this.selectedCards = [] - } -} diff --git a/client/js/cardStack.js b/client/js/cardStack.js deleted file mode 100644 index f4a9b95..0000000 --- a/client/js/cardStack.js +++ /dev/null @@ -1,15 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* - * To add 'dummy' flipped cards to the rendered Central Deck - * This is different from the CentralDeck array that actually stores the cards moved to the central deck - */ - -function cardStack () { - const movedCard = document.createElement('div') - movedCard.className = 'Card' - const movedCardText = document.createElement('div') - movedCardText.innerHTML = 'BLUFF!?' - movedCardText.className = 'cardRank' - movedCard.appendChild(movedCardText) - document.getElementById('CentralStack').appendChild(movedCard) -} diff --git a/client/js/elements/Card.js b/client/js/elements/Card.js new file mode 100644 index 0000000..b7c7685 --- /dev/null +++ b/client/js/elements/Card.js @@ -0,0 +1,24 @@ +/* eslint-disable no-unused-vars */ +/* + * Card class whose objects are used inside Game Decks. + */ + +class Card { + constructor (cardSuit, cardValue, cardId) { + this._suit = cardSuit + this._value = cardValue + this._id = cardId + } + + get suit () { + return this._suit + } + + get value () { + return this._value + } + + get id () { + return this._id + } +} diff --git a/client/js/Game.js b/client/js/elements/Game.js similarity index 96% rename from client/js/Game.js rename to client/js/elements/Game.js index 941f79d..a172acc 100644 --- a/client/js/Game.js +++ b/client/js/elements/Game.js @@ -164,7 +164,7 @@ class Game { // Attaching the number of cards each player gets to the player, to keep track of the number of cards the player has for (let i = 0; i < playerCount; i++) { - this._players[i].numberOfCards = parts[i] + this._players[i].cards.length = parts[i] } } @@ -173,9 +173,9 @@ class Game { let temp = this.deck for (let j = 0; j < this.players.length; j++) { // Giving the slice of cards each player will get - this.players[j].cards = temp.slice(0, this.players[j].numberOfCards) + this.players[j].cards = temp.slice(0, this.players[j].cards.length) // Reamaining cards for the next iteration - temp = temp.splice(this.players[j].numberOfCards) + temp = temp.splice(this.players[j].cards.length) } } } diff --git a/client/js/elements/Player.js b/client/js/elements/Player.js new file mode 100644 index 0000000..ed708d7 --- /dev/null +++ b/client/js/elements/Player.js @@ -0,0 +1,32 @@ +/* eslint-disable no-unused-vars */ +// Creating the player containing the name of the player, +// number of cards of the player and cards that the player has +// and the cards he has selected + +class Player { + constructor (name) { + this._name = name + this._cards = [] + this._selectedCards = [] + } + + get name () { + return this._name + } + + get cards () { + return this._cards + } + + set cards (cards) { + this._cards = cards + } + + get selectedCards () { + return this._selectedCards + } + + set selectedCards (cards) { + this._selectedCards = cards + } +} diff --git a/client/js/submitCard.js b/client/js/modal.js similarity index 100% rename from client/js/submitCard.js rename to client/js/modal.js diff --git a/client/js/render-elements/renderButton.js b/client/js/render-elements/renderButton.js index b3117b1..77fb4c1 100644 --- a/client/js/render-elements/renderButton.js +++ b/client/js/render-elements/renderButton.js @@ -15,9 +15,8 @@ function renderButton (game) { // Adding the clicked Card to Central Stack array game.centralStack.push(card) player.cards.splice(i, 1) - player.numberOfCards = player.cards.length // rendering another flipped card to central deck - cardStack() + renderStackCard() } }) }) diff --git a/client/js/render-elements/renderStackCard.js b/client/js/render-elements/renderStackCard.js new file mode 100644 index 0000000..1a67bcf --- /dev/null +++ b/client/js/render-elements/renderStackCard.js @@ -0,0 +1,15 @@ +/* eslint-disable no-unused-vars */ +/* + * To add 'dummy' flipped cards to the rendered Central Deck + * This is different from the CentralDeck array that actually stores the cards moved to the central deck + */ + +function renderStackCard () { + const card = document.createElement('div') + card.className = 'Card' + const cardText = document.createElement('div') + cardText.innerHTML = 'BLUFF!?' + cardText.className = 'cardRank' + card.appendChild(cardText) + document.getElementById('CentralStack').appendChild(card) +}