mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-27 10:03:48 +01:00
25 lines
522 B
TypeScript
25 lines
522 B
TypeScript
|
/**
|
||
|
* Represents a Hand of cards.
|
||
|
*
|
||
|
* This class is IMMUTABLE
|
||
|
*/
|
||
|
|
||
|
import { Card } from "./Card";
|
||
|
|
||
|
export class Hand {
|
||
|
|
||
|
constructor(readonly cards: readonly Card[]) {}
|
||
|
|
||
|
addCards(...cards: Card[]): Hand {
|
||
|
return new Hand([ ...this.cards, ...cards ]);
|
||
|
}
|
||
|
|
||
|
removeByIndex(i: number): Hand {
|
||
|
if (i >= this.cards.length) {
|
||
|
throw new Error(`Tried to remove invalid card from Hand by index: ${i}`);
|
||
|
}
|
||
|
|
||
|
return new Hand([ ...this.cards.slice().splice(i, 1) ])
|
||
|
}
|
||
|
|
||
|
}
|