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.

220 lines
7.0 KiB

  1. export default class Style {
  2. constructor(gameInstanz) {
  3. this._game = gameInstanz;
  4. this._cardOnDeck = null;
  5. this._drawCardRunnig = false;
  6. this._firstDraw = $('#first-draw');
  7. this._firstPut = $('#first-put');
  8. this._firstPutAnim = $('#first-put-anim');
  9. $('#drawCard').on('click', () => {
  10. this.game.currentPlayerInstanz.drawCard(1);
  11. this.refreshDebug();
  12. });
  13. this.firstDraw.on('mouseenter', () => {
  14. this.drawCardAnim(true, false);
  15. });
  16. this.firstDraw.on('mouseleave', () => {
  17. this.drawCardAnim(false, false);
  18. });
  19. this.firstDraw.on('click', () => {
  20. this.game.currentPlayerInstanz.drawCard(1);
  21. this.drawCardAnim(false, true);
  22. this.refreshHtml();
  23. });
  24. }
  25. refreshHtml() {
  26. if (this._cardOnDeck !== this.game.cardOnDeck) {
  27. console.log(" ewfw")
  28. this.putCardAnim();
  29. this._cardOnDeck = this.game.cardOnDeck;
  30. } else {
  31. this.firstPut.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  32. this.firstPutAnim.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  33. }
  34. this.showPlayerDeck(this.game.currentPlayerInstanz, true);
  35. this.refreshDebug();
  36. }
  37. refreshDebug() {
  38. $('#drawCard').css('background-color', 'white');
  39. $("#player").html("Spieler: " + this.game.currentPlayerInstanz.name);
  40. $("#playerCards").html("Karten: ");
  41. for (let i = 0; i < this.game.currentPlayerInstanz.hand.length; i++) {
  42. $('#playerCards').append(this.game.currentPlayerInstanz.hand[i].name + " - " + this.game.currentPlayerInstanz.hand[i].color);
  43. $('#playerCards').append('<button id="button' + i + '">+</button> | ');
  44. $('#button' + i).on('click', () => {
  45. this.game.currentPlayerInstanz.putCard(i);
  46. setTimeout(() => {
  47. this.refreshHtml();
  48. }, 100);
  49. });
  50. if (this.game.currentPlayerInstanz.hand[i].canPut) $('#button' + i).css('background-color', 'green');
  51. }
  52. $('#playerCards').append("" + this.game.currentPlayerInstanz.hand.length)
  53. $("#cardOnDeck").html("Karte auf dem Tisch: " + this.game.cardOnDeck.name + " - " + this.game.cardOnDeck.color);
  54. $("#playerInGame").html("Spieler im Spiel: " + this.game.players.length);
  55. if (!this.game.currentPlayerInstanz.canPlay) $('#drawCard').css('background-color', 'red');
  56. }
  57. putCardAnim() {
  58. this.firstPutAnim.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  59. this.firstPutAnim.css('transition', 'top 0.5s, opacity 0.3s');
  60. this.firstPutAnim.css('top', '47vh');
  61. this.firstPutAnim.css('opacity', '1');
  62. setTimeout(() => {
  63. this.firstPutAnim.css('transition', '');
  64. this.firstPutAnim.css('top', '30vh');
  65. this.firstPutAnim.css('opacity', '0');
  66. this.firstPut.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  67. this.firstPut.css('opacity', '1');
  68. }, 500);
  69. }
  70. showPlayerDeck(player, click) {
  71. console.log("anzeigen")
  72. $('#playerDeck').html("");
  73. let currentPlayerHand = player.hand;
  74. let width = window.innerWidth;
  75. let height = window.innerHeight;
  76. let percent = 0;
  77. let top = window.innerHeight * 0.68;
  78. let cardAmount = currentPlayerHand.length;
  79. for (let i = 0; i < cardAmount; i++) {
  80. console.log(this.game.currentPlayer);
  81. currentPlayerHand.xPos = 0;
  82. currentPlayerHand.yPos = 0;
  83. $('#playerDeck').append('<div id="card' + i + '" class="pictureCard">' + '<img src="./img/cards/' + currentPlayerHand[i].color + '/' + currentPlayerHand[i].name + '.png' + '"></div>');
  84. currentPlayerHand[i].xPos = (width * (((43 + cardAmount / 2 * 5) - percent)) / 100);
  85. currentPlayerHand[i].yPos = top;
  86. console.log(i + ' ' + currentPlayerHand[i].yPos);
  87. let card = $('#card' + i);
  88. let put = false;
  89. if (click) {
  90. let yPos = currentPlayerHand[i].yPos;
  91. card.on('mouseenter', () => {
  92. if (!put) card.css('top', yPos - 60);
  93. })
  94. card.on('mouseleave', () => {
  95. if (!put) card.css('top', yPos);
  96. })
  97. card.on('click', () => {
  98. if (!this.game.players[this.game.currentPlayer].hand[i].canPut) return;
  99. put = true
  100. let lastPlayer = player;
  101. player.putCard(i);
  102. card.css('top', yPos - height * 0.2);
  103. card.css('opacity', 0);
  104. setTimeout(() => {
  105. this.refreshHtml();
  106. }, 400);
  107. })
  108. }
  109. card.css('left', currentPlayerHand[i].xPos + 'px');
  110. card.css('top', top + 'px')
  111. $('.pictureCard')
  112. percent += 5;
  113. }
  114. }
  115. drawCardAnim(enable, playerDraw) {
  116. if (this.drawCardRunning) return;
  117. this.drawCardRunning = true;
  118. if (playerDraw) {
  119. this.firstDraw.css('transition', 'min-width 0.5s, top 0.5s, opacity 0.5s');
  120. this.firstDraw.css('min-width', '35vh');
  121. this.firstDraw.css('top', '60vh');
  122. this.firstDraw.css('opacity', 0);
  123. setTimeout(() => {
  124. this.firstDraw.css('transition', '');
  125. this.firstDraw.css('top', '47vh');
  126. this.firstDraw.css('min-width', '20vh');
  127. this.firstDraw.css('opacity', '1');
  128. this.drawCardRunning = false;
  129. }, 500);
  130. } else {
  131. if (enable) {
  132. this.firstDraw.css('transition', 'min-width 0.35s, top 0.5s');
  133. this.firstDraw.css('min-width', '27vh');
  134. this.firstDraw.css('top', '50vh');
  135. } else {
  136. this.firstDraw.css('transition', 'min-width 1s, top 0.5s');
  137. this.firstDraw.css('top', '47vh');
  138. this.firstDraw.css('min-width', '20vh');
  139. }
  140. this.drawCardRunning = false;
  141. }
  142. }
  143. showDebug() {
  144. $('#debug').show();
  145. this.refreshDebug();
  146. }
  147. hideDebug() {
  148. $('#debug').hide();
  149. }
  150. get game() {
  151. return this._game;
  152. }
  153. get firstDraw() {
  154. return this._firstDraw;
  155. }
  156. get firstPut() {
  157. return this._firstPut;
  158. }
  159. get firstPutAnim() {
  160. return this._firstPutAnim;
  161. }
  162. get drawCardRunning() {
  163. return this._drawCardRunnig;
  164. }
  165. set drawCardRunning(bool) {
  166. this._drawCardRunnig = bool;
  167. }
  168. }