update final result render
This commit is contained in:
parent
8fcb08ec84
commit
7342416cbc
29
index.js
29
index.js
|
@ -49,7 +49,7 @@ const sendMessage = async (room, text) => {
|
|||
});
|
||||
}
|
||||
|
||||
const renderMatrix = (game, onlySigns) => {
|
||||
const renderMatrix = (game, options) => {
|
||||
const chars = {
|
||||
0: ':large_blue_square:',
|
||||
1: ':large_blue_square:',
|
||||
|
@ -57,22 +57,31 @@ const renderMatrix = (game, onlySigns) => {
|
|||
3: ':large_red_square:',
|
||||
}
|
||||
|
||||
options = options ?? {}
|
||||
options.onlySigns = options.onlySigns ?? false
|
||||
options.hideNotPlayedLines = options.hideNotPlayedLines ?? false
|
||||
|
||||
let render = '<table>'
|
||||
|
||||
for (let row of game.matrix()) {
|
||||
const letters = (row.word ?? '.'.repeat(game.expectedWord.length)).split('')
|
||||
|
||||
if (options.hideNotPlayedLines && !row.word) {
|
||||
continue
|
||||
}
|
||||
|
||||
let signs = []
|
||||
|
||||
for (let index in row.result) {
|
||||
signs.push(chars[row.result[index]])
|
||||
}
|
||||
|
||||
const elements = onlySigns ? [signs] : [letters, signs]
|
||||
const elements = options.onlySigns ? {signs} : {letters, signs}
|
||||
|
||||
for (let element of elements) {
|
||||
for (let key in elements) {
|
||||
render += '<tr>'
|
||||
|
||||
for (let item of element) {
|
||||
for (let item of elements[key]) {
|
||||
render += `<td>${item}</td>`
|
||||
}
|
||||
|
||||
|
@ -168,9 +177,12 @@ commander
|
|||
}
|
||||
|
||||
if (currentGame.isWon()) {
|
||||
sendMessage(meta.room, 'Bravo ! Tu as découvert le mot !')
|
||||
await sendMessage(meta.room, 'Bravo ! Tu as découvert le mot !')
|
||||
|
||||
return await sendMessage(meta.room, renderMatrix(currentGame, true))
|
||||
return await sendMessage(meta.room, renderMatrix(currentGame, {
|
||||
onlySigns: true,
|
||||
hideNotPlayedLines: true,
|
||||
}))
|
||||
}
|
||||
|
||||
if (currentGame.isFinish()) {
|
||||
|
@ -180,6 +192,11 @@ commander
|
|||
meta.room,
|
||||
`Tes propositions sont épuisées… Le mot a deviner était \`${expectedWord}\``
|
||||
)
|
||||
|
||||
return await sendMessage(meta.room, renderMatrix(currentGame, {
|
||||
onlySigns: true,
|
||||
hideNotPlayedLines: true,
|
||||
}))
|
||||
}
|
||||
|
||||
await sendMessage(meta.room, renderMatrix(currentGame))
|
||||
|
|
Loading…
Reference in a new issue