Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  2.  
  3.  
  4. <div id="app">
  5. <h1>Rock Paper Scissor Game</h1>
  6. <div class="score-wrapper">
  7. <div class="tavle"> Computer: {{ computerScore }}</div>
  8. <br>
  9. <div class="tavle"> User: {{ userScore }}</div>
  10. </div>
  11.  
  12.  
  13. <br>
  14. <br>
  15. <div class="choice">
  16. <div>
  17. Computer weapon: {{ computerWeapon }}
  18. </div>
  19. <br>
  20. <div> User weapon: {{ userWeapon }}</div>
  21. </div>
  22. <br>
  23. <!-- <select v-model="userWeapon">
  24. <option value="scissor">Scissor</option>
  25. <option value="rock">Rock</option>
  26. <option value="paper">Paper</option>
  27. </select>-->
  28. <br>
  29. <div>
  30. <button :class="{active : userWeapon === 'rock'}" @click="setUserWeapon('rock')">Rock</button>
  31. <button :class="{active : userWeapon === 'scissor'}" @click="setUserWeapon('scissor')">Scissor</button>
  32. <button :class="{active : userWeapon === 'paper'}" @click="setUserWeapon('paper')">Paper</button>
  33. </div>
  34. <br>
  35. <button class="play"
  36. @click="declareWinner">
  37. Spil
  38. </button>
  39. <br>
  40. <br>
  41. <div class="go">
  42. {{ log }}
  43. </div>
  44.  
  45. </div>
  46.  
  47. <style>
  48. button {
  49. width: 100px;
  50. cursor: pointer;
  51. padding: 2px;
  52. background-color: navy;
  53. color: white;
  54. }
  55. .active{
  56. background-color: orange;
  57. }
  58. .play {
  59. width: 150px;
  60. height: 70px;
  61. font-size: 20px;
  62. cursor: pointer;
  63. padding: 2px;
  64. background-color: navy;
  65. color: white;
  66. border-radius: 10px;
  67. box-shadow: 0px 10px 10px #888888;
  68. }
  69. .tavle{
  70. width: 150px;
  71. color:white;
  72. background-color: #999999;
  73. padding: 2px;
  74. text-align: center;
  75. }
  76. .score-wrapper{
  77. display: flex;
  78. width: 356px;
  79. justify-content: space-between;
  80.  
  81. }
  82. .choice{
  83. background-color: rgb(76, 219, 83);
  84. color: white;
  85. width: 350px;
  86. padding: 5px;
  87. }
  88. .go {
  89. background-color: #666666;
  90. width: 350px;
  91. color: white;
  92. padding:10px;
  93. }
  94. </style>
  95.  
  96. <script>
  97. var app = new Vue({
  98. el: "#app",
  99. data () {
  100. return {
  101. userScore: 0,
  102. computerScore: 0,
  103. computerWeapon: null,
  104. userWeapon: null,
  105. log: 'Tryk på "Spil" for at spille'
  106. };
  107. },
  108. methods: {
  109. computerDecision: function () {
  110. var number = Math.floor(Math.random() * 3);
  111. switch(number){
  112. case 0:
  113. this.computerWeapon = "rock";
  114. break
  115. case 1:
  116. this.computerWeapon = "scissor";
  117. break
  118. case 2:
  119. this.computerWeapon = "paper";
  120. break
  121. }
  122. },
  123. setUserWeapon: function (weapon){
  124. this.userWeapon = weapon
  125. },
  126. declareWinner: function () {
  127. this.computerDecision()
  128. console.log(this.computerWeapon)
  129. if (this.userWeapon === this.computerWeapon){
  130. this.log = "Tiebreak!"
  131. } else if (this.userWeapon==="rock" && this.computerWeapon === "scissor" ||
  132. this.userWeapon === "paper" && this.computerWeapon==="rock" || this.userWeapon==="scissor" && this.computerWeapon === "paper") {
  133. this.log = "User won!"
  134. this.userScore++;
  135. }
  136. else if (!this.userWeapon){
  137. this.log = "Fejl, husk at vælge dit Våben!"
  138. }
  139. else {
  140. this.log = "Computer won!"
  141. this.computerScore++;
  142. }
  143. }
  144. }
  145. });
  146. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement