Advertisement
Guest User

thierry-angular

a guest
Jan 22nd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /**
  2. * Fichier principal de l'application.
  3. */
  4. /// <reference path="./coins.ts"/>
  5. /// <reference path="./product-factory.ts"/>
  6.  
  7. enum VendingMachineSize {
  8. Small = 6,
  9. Medium = 9,
  10. Large = 12
  11. }
  12.  
  13. class Cell {
  14. sold: boolean = false;
  15. constructor(public product: any, public stock: number = 3) {}
  16. }
  17.  
  18. class VendingMachine {
  19. // Wrappe le total dans un ko.observable
  20. total = ko.observable(0);
  21.  
  22. // Liste des pièces acceptées
  23. acceptedCoins = [new Quarter(), new Dime(), new Half(), new Dollar()];
  24.  
  25. // Emplacements du distributeur
  26. cells: Cell[] = [];
  27.  
  28. constructor(size: VendingMachineSize) {
  29. for (let i = 0; i < size; i++) {
  30. // Récupère un produit au hasard
  31. const product = getProduct();
  32. // Crée un emplacement avec ce produit
  33. const cell = new Cell(product);
  34. // Ajoute cet emplacement au distributeur
  35. this.cells.push(cell);
  36. }
  37. }
  38.  
  39. acceptCoin(coin: Quarter | Dime | Half | Dollar) {
  40. const oldValue = this.total();
  41. this.total(oldValue + coin.value);
  42. }
  43.  
  44. sayHello() {
  45. console.log('hello');
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement