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.

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