0

My task is to make a trading card game (eg Top Trumps in the UK, or Magic the Gathering) and create two decks of 15 cards each. I have 30 unique items with values attached. I want to create two decks of 15 cards each, where the first deck is a totally random selection of 15 cards and the second deck pulls the 15 variables from the array that weren't pulled by the first deck. Is this possible?

This is what our code looks like currently:

class Trumps {
constructor(name, age, power, length, danger){
    this._name=name;
    this._age=age;
    this._power=power;
    this._length=length;
}
get name () {
    return this._name;
}
get age () {
    return this._age;
}
get power() {
    return this._power;
}
get length() {
    return this._length;
}
get danger() {
    return this._danger
}

 }
 class Dragon extends Trumps {
 constructor (color, name, age, power, length, danger, wingSize, 
heightOfFlight){
 super (name, age, power, length, danger);
    // this._color=color;
    this._wingSize=wingSize;    
    this._heightOfFlight=heightOfFlight; 
 }
 }

    let John = new Dragon ('Blue, John', 98, 22, 15, 46, 87, 12)
let Dave = new Dragon ('Green, Dave', 24, 15, 16, 98, 95, 54)
let Steve = new Dragon ('Red, Steve', 75, 18, 24, 15, 99, 46)
let George = new Dragon ('Yellow, George', 100, 22, 15, 13, 48, 78)
let Andy = new Dragon ('Blue, Andy', 44, 55, 61, 88, 4, 23)
let Emma = new Dragon ('Bronze, Emma', 22, 19, 95, 16, 100, 55)
let Sheila = new Dragon ('Gold, Sheila', 100, 98, 91, 44, 12, 67)
let Cory = new Dragon ('Black, Cory', 39, 38, 48, 84, 45, 12)
let Hassan = new Dragon ('Blue, Hassan', 15, 37, 24, 53, 73, 01)
let Michelle = new Dragon ('Green, Michelle', 78, 89, 21, 27, 60, 05)
let Jameel = new Dragon ('Yellow, Jameel', 65, 1, 58, 91, 10, 52)
let Kieran = new Dragon ('Brown, Kieran', 13, 25, 91, 51, 71, 77)
let Braun = new Dragon ('Green, Braun', 31, 10, 69, 17, 43, 12)
let Jim = new Dragon ('Yellow, Jim', 79, 31, 98, 58, 82, 96)
let Andrew = new Dragon ('Green, Andrew', 34, 46, 73, 48, 30, 23)
let India = new Dragon ('Orange, India', 51, 81, 83, 62, 28, 44)
let Shelly = new Dragon ('Blue, Shelly', 20, 48, 73, 60, 76, 62)
let Niamh = new Dragon ('Black, Niamh', 8, 86, 64, 18, 28, 25)
let Jakub = new Dragon ('Orange, Jakub', 66, 36, 26, 48, 20, 67)
let Leonard = new Dragon ('Bronze, Leonard', 46, 27, 100, 24, 55, 78)
let Tom = new Dragon ('Blue, Tom', 66, 17, 54, 40, 7, 92)
let Chris = new Dragon ('Yellow, Chris', 65, 96, 2, 73, 57, 24)
let Stephen = new Dragon ('Bronze, Stephen', 23, 34, 26, 27, 68, 31)
let Alex = new Dragon ('Green, Alex', 10, 15, 18, 26, 40, 23)
let Chromie = new Dragon ('Bronze, Chromie', 39, 87, 98, 99, 79, 55 )
let Autumn = new Dragon ('Blue, Autumn', 100, 100, 100, 100, 100, 100)
let Sapphire = new Dragon ('Blue, Sapphire', 15, 25, 10, 1, 8, 100)
let Cindy = new Dragon ('Green, Cindy', 61, 56, 55, 23, 33, 55 )
let Yang = new Dragon ('Yellow, Yang', 73, 19, 24, 67, 98, 100)
let Bob = new Dragon ('Gold, Bob', 100, 30, 15, 61, 34, 77)

let allCards = [John, Dave, Steve, George, Andy, Emma, Sheila, Cory, Hassan, Michelle, Jameel, Kieran, Braun, Jim, Andrew,
India, Shelly, Niamh, Jakub, Leonard, Tom, Chris, Stephen, Alex, Chromie, Autumn, Sapphire, Cindy, Yang, Bob]

I want to make two variables, deck1 and deck2, pulling two sets of 15 objects from the allCards array. I have been attempting to use the math.random function but I was wondering if there is a way to make the function pulling deck2 dependent on the values pulled by the random algorithm pulling objects for deck1.

blackout
  • 1
  • 2
  • You could shuffle the array and [`slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) it into 2 parts: [How to randomize (shuffle) a JavaScript array?](https://stackoverflow.com/questions/2450954) – adiga Jul 18 '19 at 10:25
  • Also, [How to efficiently randomly select array item without repeats?](https://stackoverflow.com/questions/17891173) – adiga Jul 18 '19 at 10:31
  • This is exactly what I'm looking for. Thank you! – blackout Jul 18 '19 at 11:00

0 Answers0