W
W
WarriorKodeK2018-02-21 22:55:47
JavaScript
WarriorKodeK, 2018-02-21 22:55:47

How to create a class correctly?

Hey guys. I was sent a test task with one of the best companies in my city for the position of Trainee JS Developer. The job involves creating a Bingo game.
The bottom line is this:
There are 3 inputs for

  1. Entering the number of players (from 2 to 5)
  2. Entering the number of bingo cards (from 1 to 3)
  3. Numbers for the cells of this very card.
If there are more players than cards, then some player can have 2 cards.
Example of a bingo card - https://codepen.io/Slasher_/pen/paVoKX
I want to divide it all into classes (i.e. class Card, class Player...)
Question:
How can I correctly create a player class based on the received number withinput'a
(если в input вводится число 2, то должно создаваться 2 объекта Player.)
?
Idea:
Create a Player class that will have an id, probably an array of cards that belong to it...
Help with advice please. I don't require an implementation, just an idea how to organize it (even if it's some kind of pseudocode).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-02-22
@WarriorKodeK

Let the inputs change only the values ​​of this.playersCount , this.cardsCount and this.numbersCount .
You don't need any id for the players, let them just lie in the array. Create by clicking on the "create game" or "create cards" button:

class Game {
   // some stuff

  createGame() {
    this.players = [];

    for (let i = 0; i < this.playersCount; i++) {
     const player = new Player({
        name: `Player ${i}`,
        cards: this.createCards()
      });
   
      this.players.push(player);
    }
  }

  createCards() {
    // some stuff
  }

  // some stuff
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question