You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.8 KiB

  1. export default class Style {
  2. constructor(gameInstanz) {
  3. this._game = gameInstanz;
  4. this._cardOnDeck = null;
  5. this._firstDraw = $('#first-draw');
  6. this._firstPut = $('#first-put');
  7. this._firstPutAnim = $('#first-put-anim');
  8. $('#drawCard').on('click', () => {
  9. this.game.currentPlayerInstanz.drawCard(1);
  10. this.refreshDebug();
  11. });
  12. this.firstDraw.on('mouseenter', () => {
  13. this.drawCardAnim(true, false);
  14. });
  15. this.firstDraw.on('mouseleave', () => {
  16. this.drawCardAnim(false, false);
  17. });
  18. this.firstDraw.on('click', () => {
  19. this.game.currentPlayerInstanz.drawCard(1);
  20. this.refreshHtml();
  21. this.drawCardAnim(false, true);
  22. });
  23. }
  24. refreshHtml() {
  25. if (this._cardOnDeck !== this.game.cardOnDeck) {
  26. console.log(" ewfw")
  27. this.putCardAnim();
  28. this._cardOnDeck = this.game.cardOnDeck;
  29. } else {
  30. this.firstPut.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  31. this.firstPutAnim.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  32. }
  33. this.refreshDebug();
  34. }
  35. refreshDebug() {
  36. $('#drawCard').css('background-color', 'white');
  37. $("#player").html("Spieler: " + this.game.currentPlayerInstanz.name);
  38. $("#playerCards").html("Karten: ");
  39. for (let i = 0; i < this.game.currentPlayerInstanz.hand.length; i++) {
  40. $('#playerCards').append(this.game.currentPlayerInstanz.hand[i].name + " - " + this.game.currentPlayerInstanz.hand[i].color);
  41. $('#playerCards').append('<button id="button' + i + '">+</button> | ');
  42. $('#button' + i).on('click', () => {
  43. this.game.currentPlayerInstanz.putCard(i);
  44. this.refreshHtml();
  45. });
  46. if (this.game.currentPlayerInstanz.hand[i].canPut)
  47. $('#button' + i).css('background-color', 'green');
  48. }
  49. $('#playerCards').append("" + this.game.currentPlayerInstanz.hand.length)
  50. $("#cardOnDeck").html("Karte auf dem Tisch: " + this.game.cardOnDeck.name + " - " + this.game.cardOnDeck.color);
  51. $("#playerInGame").html("Spieler im Spiel: " + this.game.players.length);
  52. if (!this.game.currentPlayerInstanz.canPlay)
  53. $('#drawCard').css('background-color', 'red');
  54. }
  55. putCardAnim() {
  56. this.firstPutAnim.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  57. this.firstPutAnim.css('transition', 'top 0.5s, opacity 0.3s');
  58. this.firstPutAnim.css('top', '47vh');
  59. this.firstPutAnim.css('opacity', '1');
  60. setTimeout(() => {
  61. this.firstPutAnim.css('transition', '');
  62. this.firstPutAnim.css('top', '30vh');
  63. this.firstPutAnim.css('opacity', '0');
  64. this.firstPut.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  65. this.firstPut.css('opacity', '1');
  66. }, 500);
  67. }
  68. drawCardAnim(enable, playerDraw) {
  69. if (playerDraw) {
  70. this.firstDraw.css('transition', 'min-width 0.5s, top 0.5s, opacity 0.5s');
  71. this.firstDraw.css('min-width', '35vh');
  72. this.firstDraw.css('top', '60vh');
  73. this.firstDraw.css('opacity', 0);
  74. setTimeout(()=>{
  75. this.firstDraw.css('transition', '');
  76. this.firstDraw.css('top', '47vh');
  77. this.firstDraw.css('min-width', '20vh');
  78. this.firstDraw.css('opacity', '1');
  79. }, 500);
  80. } else {
  81. if (enable) {
  82. this.firstDraw.css('transition', 'min-width 0.35s, top 0.5s');
  83. this.firstDraw.css('min-width', '27vh');
  84. this.firstDraw.css('top', '50vh');
  85. setTimeout(() => {
  86. this.firstDraw.css('transition', '')
  87. }, 500);
  88. } else {
  89. this.firstDraw.css('transition', 'min-width 1s, top 0.5s');
  90. this.firstDraw.css('top', '47vh');
  91. this.firstDraw.css('min-width', '20vh');
  92. setTimeout(() => {
  93. this.firstDraw.css('transition', '')
  94. }, 1000);
  95. }
  96. }
  97. }
  98. showDebug() {
  99. $('#debug').show();
  100. this.refreshDebug();
  101. }
  102. hideDebug() {
  103. $('#debug').hide();
  104. }
  105. get game() {
  106. return this._game;
  107. }
  108. get firstDraw() {
  109. return this._firstDraw;
  110. }
  111. get firstPut() {
  112. return this._firstPut;
  113. }
  114. get firstPutAnim() {
  115. return this._firstPutAnim;
  116. }
  117. }