add eslint working conf

This commit is contained in:
2020-04-29 21:05:38 +02:00
parent ffe8c167cb
commit ebb1c58f90
33 changed files with 866 additions and 846 deletions

View File

@@ -8,12 +8,12 @@
</template>
<script>
import HangmanIndex from "./HangMan/HangmanIndex";
import HangmanIndex from './HangMan/HangmanIndex'
export default {
name: "GameIndex",
components: {
HangmanIndex
}
export default {
name: 'GameIndex',
components: {
HangmanIndex
}
}
</script>

View File

@@ -3,7 +3,7 @@
<h1 class="text-3xl text-center text-orange-900 font-bold">Pendu</h1>
<p class="text-center mb-4">Trouve le mot du pendu - Saisi les lettres</p>
<div class="flex justify-center dic-select">
<div v-for="(dic, key) in dictionary">
<div v-for="(dic, key) in dictionary" :key="key">
<a v-if="!selectedWord" class="btn-primary mr-1" @click="selectWord">{{ key }}</a>
</div>
</div>
@@ -46,116 +46,116 @@
</template>
<script>
import json from './dict.json'
import json from './dict.json'
export default {
name: "Hangman",
data: function () {
return {
dictionary: json,
letterBox: '',
figureParts: [],
correctLetters: [],
wrongLetters: [],
wrongLettersEl: '',
selectedWord: '',
wordEl: '',
finalMessage: '',
popup: false,
notification: false,
}
export default {
name: 'Hangman',
data: function () {
return {
dictionary: json,
letterBox: '',
figureParts: [],
correctLetters: [],
wrongLetters: [],
wrongLettersEl: '',
selectedWord: '',
wordEl: '',
finalMessage: '',
popup: false,
notification: false,
}
},
mounted() {
this.figureParts = this.$el.querySelectorAll('.figure-part')
window.addEventListener('keyup', this.keyMessage)
},
methods: {
selectWord(e) {
this.selectedWord = this.dictionary[e.target.textContent][Math.floor(Math.random() * this.dictionary[e.target.textContent].length)].toLowerCase()
this.displayWord()
this.popup = false
},
mounted() {
this.figureParts = this.$el.querySelectorAll('.figure-part')
window.addEventListener('keyup', this.keyMessage)
},
methods: {
selectWord(e) {
this.selectedWord = this.dictionary[e.target.textContent][Math.floor(Math.random() * this.dictionary[e.target.textContent].length)].toLowerCase()
this.displayWord()
this.popup = false
},
keyMessage(e) {
if(e.keyCode >= 65 && e.keyCode <= 90) {
const letter = e.key
keyMessage(e) {
if(e.keyCode >= 65 && e.keyCode <= 90) {
const letter = e.key
if(this.selectedWord.includes(letter)) {
if(!this.correctLetters.includes(letter)) {
this.correctLetters.push(letter)
if(this.selectedWord.includes(letter)) {
if(!this.correctLetters.includes(letter)) {
this.correctLetters.push(letter)
this.displayWord()
} else {
this.showNotification()
}
this.displayWord()
} else {
if(!this.wrongLetters.includes(letter)) {
this.wrongLetters.push(letter);
this.showNotification()
}
} else {
if(!this.wrongLetters.includes(letter)) {
this.wrongLetters.push(letter)
this.updateWrongLettersEl()
} else {
this.showNotification()
}
this.updateWrongLettersEl()
} else {
this.showNotification()
}
}
},
displayWord() {
this.wordEl =
this.selectedWord
}
},
displayWord() {
this.wordEl =
this.selectedWord
.split('')
.map(
letter => {
let toggleLetter = this.correctLetters.includes(letter) ? letter : '';
return '<span class="letter">' + toggleLetter +"</span>"
let toggleLetter = this.correctLetters.includes(letter) ? letter : ''
return '<span class="letter">' + toggleLetter + '</span>'
}
).join('');
).join('')
const innerWord = this.wordEl.replace(/<span class="letter">|<\/span>/g, '');
const innerWord = this.wordEl.replace(/<span class="letter">|<\/span>/g, '')
if(innerWord === this.selectedWord) {
this.finalMessage = 'Gagné! 😃';
this.popup = true
this.newGame()
}
},
updateWrongLettersEl() {
this.wrongLettersEl =
!this.wrongLetters ? '<p>Wrong</p>' : ''
+
this.wrongLetters.map(letter => `<span>${letter}</span>`);
// Display parts
this.figureParts.forEach((part, index) => {
const errors = this.wrongLetters.length;
if(index < errors) {
part.style.display = 'block'
} else {
part.style.display = 'none'
}
});
// Check if lost
if(this.wrongLetters.length === this.figureParts.length) {
this.finalMessage = 'Perdu. 😕';
this.popup = true
this.newGame()
}
},
newGame: function () {
if(innerWord === this.selectedWord) {
this.finalMessage = 'Gagné! 😃'
this.popup = true
this.correctLetters.splice(0);
this.wrongLetters.splice(0);
this.letterBox = ''
this.selectedWord = ''
this.wrongLettersEl = ''
},
showNotification(){
this.notification = true
setTimeout(() => {
this.notification = false
}, 2000)
this.newGame()
}
},
updateWrongLettersEl() {
this.wrongLettersEl =
!this.wrongLetters ? '<p>Wrong</p>' : ''
+
this.wrongLetters.map(letter => `<span>${letter}</span>`)
// Display parts
this.figureParts.forEach((part, index) => {
const errors = this.wrongLetters.length
if(index < errors) {
part.style.display = 'block'
} else {
part.style.display = 'none'
}
})
// Check if lost
if(this.wrongLetters.length === this.figureParts.length) {
this.finalMessage = 'Perdu. 😕'
this.popup = true
this.newGame()
}
},
newGame: function () {
this.popup = true
this.correctLetters.splice(0)
this.wrongLetters.splice(0)
this.letterBox = ''
this.selectedWord = ''
this.wrongLettersEl = ''
},
showNotification(){
this.notification = true
setTimeout(() => {
this.notification = false
}, 2000)
}
}
}
</script>

View File

@@ -6,13 +6,13 @@
</template>
<script>
export default {
name: "HangmanIndex",
props: {
link: {
type: String,
required: true
},
}
export default {
name: 'HangmanIndex',
props: {
link: {
type: String,
required: true
},
}
}
</script>