Skip to content

Commit

Permalink
getters and setters for player, card, structuring
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratham Gupta committed Aug 21, 2020
1 parent e33237d commit 2bd4c64
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 51 deletions.
12 changes: 6 additions & 6 deletions client/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qs/6.6.0/qs.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="js/Card.js"></script>
<script src="js/Game.js"></script>
<script src="js/Player.js"></script>
<script src="js/renderDeck.js"></script>
<script src="js/elements/Card.js"></script>
<script src="js/elements/Game.js"></script>
<script src="js/elements/Player.js"></script>
<script src="js/bluff.js"></script>
<script src="js/cardStack.js"></script>
<script src="js/bluffData.js"></script>
<script src="js/submitCard.js"></script>
<script src="js/modal.js"></script>
<script src="js/check.js"></script>
<script src="js/activate-deactivate/deactivateAllPlayers.js"></script>
<script src="js/activate-deactivate/activatePlayer.js"></script>
<script src="js/activate-deactivate/deactivatePlayer.js"></script>
<script src="js/render-elements/renderDeck.js"></script>
<script src="js/render-elements/renderPlayer.js"></script>
<script src="js/render-elements/renderCard.js"></script>
<script src="js/render-elements/renderButton.js"></script>
<script src="js/render-elements/renderStackCard.js"></script>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down
12 changes: 0 additions & 12 deletions client/js/Card.js

This file was deleted.

13 changes: 0 additions & 13 deletions client/js/Player.js

This file was deleted.

15 changes: 0 additions & 15 deletions client/js/cardStack.js

This file was deleted.

24 changes: 24 additions & 0 deletions client/js/elements/Card.js
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 3 additions & 3 deletions client/js/Game.js → client/js/elements/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}

Expand All @@ -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)
}
}
}
32 changes: 32 additions & 0 deletions client/js/elements/Player.js
Original file line number Diff line number Diff line change
@@ -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
}
}
File renamed without changes.
3 changes: 1 addition & 2 deletions client/js/render-elements/renderButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
})
Expand Down
15 changes: 15 additions & 0 deletions client/js/render-elements/renderStackCard.js
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 2bd4c64

Please sign in to comment.