{"size": 915, "ext": "js", "max_stars_repo_path": "src/backend/Dealer.js", "max_stars_repo_name": "poftadeh/BattleofACI", "max_stars_repo_stars_event_min_datetime": "2018-08-27T06:29:36.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-29T21:32:27.000Z", "max_issues_repo_path": "src/backend/Dealer.js", "max_issues_repo_name": "poftadeh/BattleofACI", "max_issues_repo_issues_event_min_datetime": "2020-09-05T16:41:58.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-08T21:00:09.000Z", "max_forks_repo_path": "src/backend/Dealer.js", "max_forks_repo_name": "poftadeh/BattleofACI", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 22.3170731707, "max_line_length": 71, "alphanum_fraction": 0.5606557377}
import Deck from './Deck.js';

class Dealer {
    constructor() {
        this.deck = new Deck();
    }

    dealCardToPlayer(player) {
        if (!player.hasMaxCards()) {
            const card = this.deck.drawCard();
            player.hand.addCard(card);
        }
    }

    dealSpecificCardToPlayer(player, card) {
        if (!player.hasMaxCards()) {
            player.hand.addCard(card);
        }
    }

    collectDiscards(cards) {
       this.deck.addToDiscards(cards); 
    }

    dealCardsToAllPlayers(players, numOfCards) {
        for(let i = 0; i < numOfCards; i++) 
            players.forEach((player) => this.dealCardToPlayer(player));
    }

    mergeDiscardsWithDeck() {
        this.deck.cards = this.deck.cards.concat(this.deck.discards);
        this.deck.discards = [];
        this.shuffleDeck();
    }
    
    shuffleDeck() {
        this.deck.shuffle();
    }
}

export default Dealer;