Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Fichier principal de l'application.
- */
- /// <reference path="./coins.ts"/>
- /// <reference path="./product-factory.ts"/>
- enum VendingMachineSize {
- Small = 6,
- Medium = 9,
- Large = 12
- }
- class Cell {
- sold: boolean = false;
- constructor(public product: any, public stock: number = 3) {}
- }
- class VendingMachine {
- // Wrappe le total dans un ko.observable
- total = ko.observable(0);
- // Liste des pièces acceptées
- acceptedCoins = [new Quarter(), new Dime(), new Half(), new Dollar()];
- // Emplacements du distributeur
- cells: Cell[] = [];
- constructor(size: VendingMachineSize) {
- for (let i = 0; i < size; i++) {
- // Récupère un produit au hasard
- const product = getProduct();
- // Crée un emplacement avec ce produit
- const cell = new Cell(product);
- // Ajoute cet emplacement au distributeur
- this.cells.push(cell);
- }
- }
- acceptCoin(coin: Quarter | Dime | Half | Dollar) {
- const oldValue = this.total();
- this.total(oldValue + coin.value);
- }
- sayHello() {
- console.log('hello');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement