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.

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