Skip to content

Commit

Permalink
added getters and setters according to every game attribute, moved re…
Browse files Browse the repository at this point in the history
…nderDeck
  • Loading branch information
Pratham Gupta committed Aug 21, 2020
1 parent fd822e5 commit e33237d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
79 changes: 62 additions & 17 deletions client/js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,39 @@

class Game {
constructor () {
this.suits = ['spades', 'clubs', 'hearts', 'diams'] // Array of Card Suits
this.values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] // Array of possible card-ranks ie. values.

this.deck = []
this.players = []
// Array of Card Suits - should not accessed from outside the class
this._suits = ['spades', 'clubs', 'hearts', 'diams']
// Array of possible card-ranks ie. values - should not accessed from outside the class
this._values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']

// the cards in play for this game
this._deck = []
// ids of the cards for this game - should not accessed from outside the class
this._idNumber = 1

// the players for this game - should not mutated from outside class
this._players = []
// index of the player whose turn it currently is
this._turn = 0

this.centralStack = [] // Central stack to store cards that are clicked upon and moved by players
this.record = [] // Adding a record to store whether the last player bluffed or not
this.currentRank = '' // Data of which rank is currently being played
// Central stack to store cards that are moved by players
this._centralStack = []
// Adding a record to store whether the last player bluffed or not
this._record = ''
// Data of which rank is currently being played
this._currentRank = ''
}

this.idNumber = 1
get players () {
return this._players
}

get deck () {
return this._deck
}

set deck (deck) {
this._deck = deck
}

get turn () {
Expand All @@ -26,6 +47,30 @@ class Game {
this._turn = turn
}

get centralStack () {
return this._centralStack
}

set centralStack (stack) {
this._centralStack = stack
}

get record () {
return this._record
}

set record (record) {
this._record = record
}

get currentRank () {
return this._currentRank
}

set currentRank (rank) {
this._currentRank = rank
}

start () {
// input the number of players
let playerCount = window.prompt('Enter the number of players(Between 2 and 12): ')
Expand All @@ -45,7 +90,7 @@ class Game {
this.addDeck()
}

// shuffle
// shuffle the cards
this.shuffle()

// Creating n players based on user input
Expand All @@ -71,15 +116,15 @@ class Game {
// add a 54 card deck to the cards beinf used in this game
addDeck () {
// iterate over the suits and the values generating a new card.
this.suits.forEach((suit) => {
this.values.forEach((value) => {
this.deck.push(new Card(suit, value, this.idNumber++))
this._suits.forEach((suit) => {
this._values.forEach((value) => {
this.deck.push(new Card(suit, value, this._idNumber++))
})
})

// Two Joker Cards pushed to Deck.
this.deck.push(new Card('Joker', 'Joker', this.idNumber++))
this.deck.push(new Card('Joker', 'Joker', this.idNumber++))
this.deck.push(new Card('Joker', 'Joker', this._idNumber++))
this.deck.push(new Card('Joker', 'Joker', this._idNumber++))
}

shuffle () {
Expand All @@ -99,7 +144,7 @@ class Game {
createPlayers (playerCount) {
// create the players one at time and push them to the game object's players attribute
for (let i = 0; i < playerCount; i++) {
this.players.push(new Player('Player ' + (i + 1)))
this._players.push(new Player('Player ' + (i + 1)))
}

// Array to store the number of cards each player should get.
Expand All @@ -119,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].numberOfCards = parts[i]
}
}

Expand Down
File renamed without changes.

0 comments on commit e33237d

Please sign in to comment.