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.

252 lines
8.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, true, true);
  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. let playerInstanz = this.game.currentPlayerInstanz;
  21. this.drawCardAnim(false, true);
  22. playerInstanz.drawCard(1, true, true);
  23. });
  24. }
  25. refreshHtml() {
  26. this.refreshCardOnDeck();
  27. this.showPlayerDeck(this.game.currentPlayerInstanz, true, false, 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.showPlayerDeck(this.game.currentPlayerInstanz, false, true, false);
  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, lastDraw, anim) {
  74. $('#playerDeck').html("");
  75. let currentPlayerHand = player.hand;
  76. let width = window.innerWidth;
  77. let height = window.innerHeight;
  78. let percent = 0;
  79. let top = window.innerHeight * 0.68;
  80. let cardAmount = currentPlayerHand.length;
  81. for (let i = 0; i < cardAmount; i++) {
  82. currentPlayerHand.xPos = 0;
  83. currentPlayerHand.yPos = 0;
  84. $('#playerDeck').append('<div id="card' + i + '" class="pictureCard">' + '<img src="./img/cards/' + currentPlayerHand[i].color + '/' + currentPlayerHand[i].name + '.png' + '"></div>');
  85. currentPlayerHand[i].xPos = (width * (((43 + cardAmount / 2 * 5) - percent)) / 100);
  86. currentPlayerHand[i].yPos = top;
  87. console.log(i + ' ' + currentPlayerHand[i].yPos);
  88. let card = $('#card' + i);
  89. let put = false;
  90. if (click) {
  91. let yPos = currentPlayerHand[i].yPos;
  92. card.on('mouseenter', () => {
  93. if (!put && !anim) card.css('top', yPos - 60 + 'px');
  94. })
  95. card.on('mouseleave', () => {
  96. if (!put && !anim) card.css('top', yPos);
  97. })
  98. card.on('click', () => {
  99. if (!this.game.players[this.game.currentPlayer].hand[i].canPut || anim) return;
  100. put = true
  101. let lastPlayer = player;
  102. player.putCard(i);
  103. card.css('top', yPos - height * 0.2);
  104. card.css('opacity', 0);
  105. setTimeout(() => {
  106. this.refreshCardOnDeck();
  107. }, 400);
  108. })
  109. }
  110. if(anim){
  111. card.css('top', height);
  112. setTimeout(()=>{
  113. card.css('top', top + 'px')
  114. card.css('left', (width * 45 / 100));
  115. setTimeout(()=>{
  116. card.css('left', currentPlayerHand[i].xPos + 'px');
  117. card.css('top', top + 'px')
  118. anim = false;
  119. }, 250);
  120. },100);
  121. } else {
  122. card.css('left', currentPlayerHand[i].xPos + 'px');
  123. card.css('top', top + 'px')
  124. }
  125. if(lastDraw && i === cardAmount - 1){
  126. card.css('opacity', 0);
  127. card.css('top', currentPlayerHand[i].yPos - 100);
  128. setTimeout(()=>{
  129. card.css('left', currentPlayerHand[i].xPos + 'px');
  130. card.css('top', top + 'px')
  131. card.css('opacity', 1);
  132. },50);
  133. }
  134. percent += 5;
  135. }
  136. }
  137. drawCardAnim(enable, playerDraw) {
  138. if (this.drawCardRunning) return;
  139. this.drawCardRunning = true;
  140. if (playerDraw) {
  141. this.firstDraw.css('transition', 'min-width 0.5s, top 0.5s, opacity 0.5s');
  142. this.firstDraw.css('min-width', '35vh');
  143. this.firstDraw.css('top', '60vh');
  144. this.firstDraw.css('opacity', 0);
  145. setTimeout(() => {
  146. this.firstDraw.css('transition', '');
  147. this.firstDraw.css('top', '47vh');
  148. this.firstDraw.css('min-width', '20vh');
  149. this.firstDraw.css('opacity', '1');
  150. this.drawCardRunning = false;
  151. }, 500);
  152. } else {
  153. if (enable) {
  154. this.firstDraw.css('transition', 'min-width 0.35s, top 0.5s');
  155. this.firstDraw.css('min-width', '27vh');
  156. this.firstDraw.css('top', '50vh');
  157. } else {
  158. this.firstDraw.css('transition', 'min-width 1s, top 0.5s');
  159. this.firstDraw.css('top', '47vh');
  160. this.firstDraw.css('min-width', '20vh');
  161. }
  162. this.drawCardRunning = false;
  163. }
  164. }
  165. animDrawCard(){
  166. }
  167. showDebug() {
  168. $('#debug').show();
  169. this.refreshDebug();
  170. }
  171. hideDebug() {
  172. $('#debug').hide();
  173. }
  174. get game() {
  175. return this._game;
  176. }
  177. get firstDraw() {
  178. return this._firstDraw;
  179. }
  180. get firstPut() {
  181. return this._firstPut;
  182. }
  183. get firstPutAnim() {
  184. return this._firstPutAnim;
  185. }
  186. get drawCardRunning() {
  187. return this._drawCardRunnig;
  188. }
  189. set drawCardRunning(bool) {
  190. this._drawCardRunnig = bool;
  191. }
  192. }