From 3121f9f60886b291103bfb10b26803196b7e4e6b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 31 Dec 2022 18:13:35 +0100 Subject: Refactored game creation --- utils/board.js | 59 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'utils') diff --git a/utils/board.js b/utils/board.js index 72c7951..f9a3b9d 100644 --- a/utils/board.js +++ b/utils/board.js @@ -18,9 +18,9 @@ export const emptyBoard = [ export const letters_total = 102; -export function makeLettersBag () { - return { - letters : { +export class Bag { + constructor() { + this.letters = { JOKER:{count:2, points:0 }, E:{count:15, points:1}, A:{count:9, points:1}, I:{count:9, points:1}, N:{count:6, points:1}, O:{count:6, points:1}, R:{count:6, points:1}, S:{count:6, points:1}, T:{count:6, points:1}, U:{count:6, points:1}, L:{count:5, points:1}, D:{count:3, points:2}, G:{count:2, points:2}, M:{count:3, points:2}, @@ -28,35 +28,34 @@ export function makeLettersBag () { F:{count:2, points:4}, H:{count:2, points:4}, V:{count:2, points:4}, J:{count:1, points:8}, Q:{count:1, points:8}, K:{count:1, points:10}, W:{count:1, points:10}, X:{count:1, points:10}, Y:{count:1, points:10}, Z:{count:1, points:10}, - }, - remaining: letters_total, - }; -} - -const allLetters = Object.keys(makeLettersBag().letters); - -export function pickLetters(bag, count) { - if (count > bag.remaining) { - count = bag.remaining; + }; + this.remaining = letters_total; } - let ret = []; - for (let i=0; i this.remaining) { + count = this.remaining; + } + let ret = []; + for (let i=0; i