AppGame.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div>
  3. <div class="row">
  4. <div class="col-12 col-md-8 offset-sm-2 col-lg-6 offset-md-3">
  5. <button class="btn btn-danger" @click="stopGame">
  6. Stop game
  7. </button>
  8. <input type="text" v-model="chatMessage" @keydown.enter="sendChat" />
  9. <button
  10. class="btn btn-primary"
  11. @click="sendChat"
  12. :disabled="chatMessage === ''"
  13. >
  14. Chat
  15. </button>
  16. </div>
  17. </div>
  18. <hr />
  19. <component :is="gameStepDisplay" :select-heroes="true"></component>
  20. </div>
  21. </template>
  22. <script>
  23. import { mapGetters } from 'vuex';
  24. import { socketService } from '../main';
  25. import HeroesDisplay from '../common/heroes-display/HeroesDisplay';
  26. import OnlineWait from './components/OnlineWait';
  27. import GameBoard from './components/GameBoard';
  28. export default {
  29. components: {
  30. HeroesDisplay,
  31. OnlineWait,
  32. GameBoard
  33. },
  34. data() {
  35. return {
  36. chatMessage: ''
  37. };
  38. },
  39. computed: {
  40. ...mapGetters({
  41. gameState: 'game/state'
  42. }),
  43. gameStepDisplay() {
  44. let componentToDisplay = '';
  45. switch (this.gameState) {
  46. case null:
  47. case '':
  48. case '0_INIT':
  49. componentToDisplay = 'online-wait';
  50. break;
  51. case '1_SELECT_FACTION':
  52. case '1_SELECT_DRAFT':
  53. case '1_SELECT_TOURNAMENT':
  54. componentToDisplay = 'heroes-display';
  55. break;
  56. case '2_CHANGE_UP_TO_3_CARDS':
  57. componentToDisplay = 'game-board';
  58. break;
  59. default:
  60. componentToDisplay = 'online-wait';
  61. break;
  62. }
  63. return componentToDisplay;
  64. }
  65. },
  66. methods: {
  67. stopGame() {
  68. this.$store.dispatch('stopGame');
  69. this.$store.dispatch('game/resetGameState');
  70. },
  71. sendChat() {
  72. socketService.chat(this.chatMessage);
  73. this.chatMessage = '';
  74. }
  75. },
  76. created() {}
  77. };
  78. </script>
  79. <style></style>