如何创建一个输出类的各种实例的“ x”数量的函数?

时间:2019-04-26 03:02:26

标签: javascript

我正在创造一种经典的记忆游戏。我有一个卡片原型,并且有好卡片和坏卡片的实例。我想创建一个函数,处理每张卡的特定数量。例如,我要分发16张牌:4xammo,4xbeers,2x雪茄,2xsnakes,2enemigos和2x蝎子。

我不确定是否首先创建实例是执行此操作的正确方法,还是不确定是否必须在deal函数中使它们成功。

 <section class="memory-game">

 </section>

      class Card {
        constructor(name, image, health, ammo) {
          this.name = name
          this.image = image
          this.health = health
          this.ammo = ammo
        }
      }

      // Good Cards
      const ammo = new Card('ammunition', null, 1, null),
            beer = new Card('beer', null, 1, null),
            cigar = new Card('cigar', null, 1, null)

      // Bad Cards
      const enemigo = new Card('enemigo', null, -1, null),
            bandito = new Card('bandito', null, null, -1),
            snake = new Card('snake', null, -1, null),
            scorpion = new Card('scorpion', null, -1, null)

      function dealCards() {

      }

预期结果是将发行16张卡,每张卡都从卡原型中提取并具有自己的属性。

2 个答案:

答案 0 :(得分:2)

我建议将实例存储在static boolean isPlaintext(Buffer buffer) { try { Buffer prefix = new Buffer(); long byteCount = buffer.size() < 64 ? buffer.size() : 64; buffer.copyTo(prefix, 0, byteCount); for (int i = 0; i < 16; i++) { if (prefix.exhausted()) { break; } int codePoint = prefix.readUtf8CodePoint(); if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) { return false; } } return true; } catch (EOFException e) { return false; // Truncated UTF-8 sequence. } }

像这样:

Array

答案 1 :(得分:0)

是的,您应该在Deal函数中实例化。

我所做的是写一些清单,列出要处理的每张卡的卡数量以及卡的规格。

然后,我将遍历列表中的每个项目,然后在给定适当规格的情况下实例化Physical Plan == *Sort [defectProbability#2 DESC NULLS LAST], true, 0 +- Exchange rangepartitioning(defectProbability#2 DESC NULLS LAST, 25) +- *Project [expectedQuantity#0, cameraCaptureTimestampUtc#1, defectProbability#2, binScannableId#3, warehouseId#4, defectResult#5] +- *Filter ((isnotnull(rank#35) && (rank#35 = 1)) && (((((((expectedQuantity#0 = 0) && (defectProbability#2 > 0.99)) || ((expectedQuantity#0 = 1) && (defectProbability#2 > 0.98))) || ((expectedQuantity#0 = 2) && (defectProbability#2 > 0.99))) || ((expectedQuantity#0 = 3) && (defectProbability#2 > 0.99))) || ((expectedQuantity#0 = 4) && (defectProbability#2 > 0.99))) || ((expectedQuantity#0 = 5) && (defectProbability#2 > 0.99)))) +- Window [rank(cameraCaptureTimestampUtc#1) windowspecdefinition(binScannableId#3, warehouseId#4, cameraCaptureTimestampUtc#1 DESC NULLS LAST, ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS rank#35], [binScannableId#3, warehouseId#4], [cameraCaptureTimestampUtc#1 DESC NULLS LAST] +- *Sort [binScannableId#3 ASC NULLS FIRST, warehouseId#4 ASC NULLS FIRST, cameraCaptureTimestampUtc#1 DESC NULLS LAST], false, 0 +- Exchange hashpartitioning(binScannableId#3, warehouseId#4, 25) +- Union :- Scan ExistingRDD[expectedQuantity#0,cameraCaptureTimestampUtc#1,defectProbability#2,binScannableId#3,warehouseId#4,defectResult#5] +- *FileScan json [expectedQuantity#13,cameraCaptureTimestampUtc#14,defectProbability#15,binScannableId#16,warehouseId#17,defectResult#18] Batched: false, Format: JSON, Location: InMemoryFileIndex[s3://vbi-autocount-chunking-prod-nafulfillment2/TPA1/2019/04/25/12/vbi-ac-chunk..., PartitionFilters: [], PushedFilters: [], ReadSchema: struct<expectedQuantity:int,cameraCaptureTimestampUtc:string,defectProbability:double,binScannabl... 类时再次迭代要处理的卡数。我为规格使用了一个数组,因此我可以轻松地使用rest参数实例化Card类。

我使Deal函数成为类中的一种方法,目的只是为了保持一致。我制作的这个Card类可以修改为接受Dealer的列表。但是现在,我将使其保持静态以简化操作。

{specs: [], amount: 0}