如何从数组中提取两组唯一变量?

时间:2019-07-18 10:23:10

标签: javascript arrays

我的任务是制作一个纸牌游戏(例如,英国的顶级王牌或聚会魔术),并创建两个15张卡片的套牌。我有30个具有附加值的独特商品。我想创建两个卡片组,每个卡片组15张卡片,其中第一个卡片组是完全随机选择的15张卡片,第二个卡片组从数组中拉出了第一个卡片组未提取的15个变量。这可能吗?

这是我们当前代码的样子:

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]

我要创建两个变量:deck1和deck2,从allCards数组中提取两组15个对象。我一直在尝试使用math.random函数,但我想知道是否有一种方法可以使该函数根据依赖于由随机算法为deck1提取对象的值所提取的值来提取deck2。

0 个答案:

没有答案