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.

158 lines
4.9 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.refreshHtml();
  22. this.drawCardAnim(false, true);
  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.refreshDebug();
  35. }
  36. refreshDebug() {
  37. $('#drawCard').css('background-color', 'white');
  38. $("#player").html("Spieler: " + this.game.currentPlayerInstanz.name);
  39. $("#playerCards").html("Karten: ");
  40. for (let i = 0; i < this.game.currentPlayerInstanz.hand.length; i++) {
  41. $('#playerCards').append(this.game.currentPlayerInstanz.hand[i].name + " - " + this.game.currentPlayerInstanz.hand[i].color);
  42. $('#playerCards').append('<button id="button' + i + '">+</button> | ');
  43. $('#button' + i).on('click', () => {
  44. this.game.currentPlayerInstanz.putCard(i);
  45. this.refreshHtml();
  46. });
  47. if (this.game.currentPlayerInstanz.hand[i].canPut)
  48. $('#button' + i).css('background-color', 'green');
  49. }
  50. $('#playerCards').append("" + this.game.currentPlayerInstanz.hand.length)
  51. $("#cardOnDeck").html("Karte auf dem Tisch: " + this.game.cardOnDeck.name + " - " + this.game.cardOnDeck.color);
  52. $("#playerInGame").html("Spieler im Spiel: " + this.game.players.length);
  53. if (!this.game.currentPlayerInstanz.canPlay)
  54. $('#drawCard').css('background-color', 'red');
  55. }
  56. putCardAnim() {
  57. this.firstPutAnim.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  58. this.firstPutAnim.css('transition', 'top 0.5s, opacity 0.3s');
  59. this.firstPutAnim.css('top', '47vh');
  60. this.firstPutAnim.css('opacity', '1');
  61. setTimeout(() => {
  62. this.firstPutAnim.css('transition', '');
  63. this.firstPutAnim.css('top', '30vh');
  64. this.firstPutAnim.css('opacity', '0');
  65. this.firstPut.attr('src', './img/stackCards/' + this.game.cardOnDeck.color + '/' + this.game.cardOnDeck.name + '.png');
  66. this.firstPut.css('opacity', '1');
  67. }, 500);
  68. }
  69. drawCardAnim(enable, playerDraw) {
  70. if(this.drawCardRunning) return;
  71. this.drawCardRunning = true;
  72. if (playerDraw) {
  73. this.firstDraw.css('transition', 'min-width 0.5s, top 0.5s, opacity 0.5s');
  74. this.firstDraw.css('min-width', '35vh');
  75. this.firstDraw.css('top', '60vh');
  76. this.firstDraw.css('opacity', 0);
  77. setTimeout(()=>{
  78. this.firstDraw.css('transition', '');
  79. this.firstDraw.css('top', '47vh');
  80. this.firstDraw.css('min-width', '20vh');
  81. this.firstDraw.css('opacity', '1');
  82. this.drawCardRunning = false;
  83. }, 500);
  84. } else {
  85. if (enable) {
  86. this.firstDraw.css('transition', 'min-width 0.35s, top 0.5s');
  87. this.firstDraw.css('min-width', '27vh');
  88. this.firstDraw.css('top', '50vh');
  89. } else {
  90. this.firstDraw.css('transition', 'min-width 1s, top 0.5s');
  91. this.firstDraw.css('top', '47vh');
  92. this.firstDraw.css('min-width', '20vh');
  93. }
  94. this.drawCardRunning = false;
  95. }
  96. }
  97. showDebug() {
  98. $('#debug').show();
  99. this.refreshDebug();
  100. }
  101. hideDebug() {
  102. $('#debug').hide();
  103. }
  104. get game() {
  105. return this._game;
  106. }
  107. get firstDraw() {
  108. return this._firstDraw;
  109. }
  110. get firstPut() {
  111. return this._firstPut;
  112. }
  113. get firstPutAnim() {
  114. return this._firstPutAnim;
  115. }
  116. get drawCardRunning(){
  117. return this._drawCardRunnig;
  118. }
  119. set drawCardRunning(bool){
  120. this._drawCardRunnig = bool;
  121. }
  122. }