| 1 | <template lang="pug"> |
| 2 | .row |
| 3 | .col-sm-12 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2 |
| 4 | .button-group |
| 5 | button(@click="display='rules'") Read the rules |
| 6 | button(v-show="!gameInProgress" @click="watchComputerGame") |
| 7 | | Observe a sample game |
| 8 | button(v-show="!gameInProgress" @click="playAgainstComputer") |
| 9 | | Beat the computer! |
| 10 | button(v-show="gameInProgress" @click="stopGame") |
| 11 | | Stop game |
| 12 | div(v-show="display=='rules'" v-html="content" class="section-content") |
| 13 | Game(v-show="display=='computer'" :mycolor="mycolor" :fen="fen" |
| 14 | :mode="mode" :sub-mode="subMode" |
| 15 | @computer-think="gameInProgress=false" @game-over="stopGame") |
| 16 | </template> |
| 17 | |
| 18 | <script> |
| 19 | import Game from "@/components/Game.vue"; |
| 20 | import { store } from "@/store"; |
| 21 | export default { |
| 22 | name: 'my-rules', |
| 23 | data: function() { |
| 24 | return { |
| 25 | st: store.state, |
| 26 | content: "", |
| 27 | display: "rules", |
| 28 | mode: "computer", |
| 29 | subMode: "", //'auto' for game CPU vs CPU |
| 30 | gameInProgress: false, |
| 31 | mycolor: "w", |
| 32 | fen: "", |
| 33 | }; |
| 34 | }, |
| 35 | mounted: function() { |
| 36 | // Method to replace diagrams in loaded HTML |
| 37 | const replaceByDiag = (match, p1, p2) => { |
| 38 | const args = this.parseFen(p2); |
| 39 | return getDiagram(args); |
| 40 | }; |
| 41 | // (AJAX) Request to get rules content (plain text, HTML) |
| 42 | this.content = |
| 43 | require("raw-loader!pug-plain-loader!@/rules/" + |
| 44 | this.$route.params["vname"] + "/" + this.st.lang + ".pug") |
| 45 | .replace(/(fen:)([^:]*):/g, replaceByDiag); |
| 46 | }, |
| 47 | methods: { |
| 48 | parseFen(fen) { |
| 49 | const fenParts = fen.split(" "); |
| 50 | return { |
| 51 | position: fenParts[0], |
| 52 | marks: fenParts[1], |
| 53 | orientation: fenParts[2], |
| 54 | shadow: fenParts[3], |
| 55 | }; |
| 56 | }, |
| 57 | startGame: function() { |
| 58 | if (this.gameInProgress) |
| 59 | return; |
| 60 | this.gameInProgress = true; |
| 61 | this.mode = "computer"; |
| 62 | this.display = "computer"; |
| 63 | this.fen = V.GenRandInitFen(); |
| 64 | }, |
| 65 | stopGame: function() { |
| 66 | this.gameInProgress = false; |
| 67 | this.mode = "analyze"; |
| 68 | }, |
| 69 | playAgainstComputer: function() { |
| 70 | this.subMode = ""; |
| 71 | this.startGame(); |
| 72 | }, |
| 73 | watchComputerGame: function() { |
| 74 | this.subMode = "auto"; |
| 75 | this.startGame(); |
| 76 | }, |
| 77 | }, |
| 78 | }; |
| 79 | </script> |