add seed mechanism
This commit is contained in:
parent
1641fb6f30
commit
20609ef414
107864
assets/all_words.js
107864
assets/all_words.js
File diff suppressed because it is too large
Load diff
89497
assets/words.js
89497
assets/words.js
File diff suppressed because it is too large
Load diff
46
index.js
46
index.js
|
@ -39,7 +39,7 @@ const token = authClient.accessToken
|
|||
const client = new MatrixClient(url, token, storage, cryptoProvider)
|
||||
|
||||
const games = []
|
||||
const randomWord = uniqueRandomArray(words);
|
||||
const randomSeeds = uniqueRandomArray(words.seeds);
|
||||
|
||||
const sendMessage = async (room, text) => {
|
||||
client.sendMessage(room, {
|
||||
|
@ -97,11 +97,29 @@ const renderMatrix = (game, options) => {
|
|||
return markdown
|
||||
}
|
||||
|
||||
const startGame = async (meta) => {
|
||||
const word = randomWord()
|
||||
games[meta.room] = new Game(word, allWords)
|
||||
const startGame = async (meta, seed) => {
|
||||
let data
|
||||
|
||||
await sendMessage(meta.room, 'Le mot commence par la lettre `' + word.substr(0, 1) + '`')
|
||||
if (seed) {
|
||||
const index = words.seeds.indexOf(seed)
|
||||
|
||||
if (index === -1) {
|
||||
return await sendMessage(meta.room, 'Désolé mais cette seed n\'existe pas.')
|
||||
}
|
||||
|
||||
data = words.datas[index]
|
||||
} else {
|
||||
seed = randomSeeds()
|
||||
data = words.datas[words.seeds.indexOf(seed)]
|
||||
}
|
||||
|
||||
games[meta.room] = new Game(data.word, allWords)
|
||||
|
||||
const word = data.word
|
||||
const firstLetter = word.substr(0, 1)
|
||||
const size = word.length
|
||||
|
||||
await sendMessage(meta.room, `Le mot commence par la lettre \`${firstLetter}\` et contient ${size} lettres. Vous pouvez partager cette grille avec sa seed : \`${seed}\``)
|
||||
await sendMessage(meta.room, renderMatrix(games[meta.room]))
|
||||
|
||||
console.log(`${meta.sender} on room ${meta.room} starts the game (${word})`)
|
||||
|
@ -123,9 +141,9 @@ commander
|
|||
})
|
||||
|
||||
commander
|
||||
.command('start')
|
||||
.description('`start` : démarrer une partie')
|
||||
.action(async (meta) => {
|
||||
.command('start [seed]')
|
||||
.description('`start` ou `start seed` : démarrer une partie avec éventuellement la seed d\'une grille')
|
||||
.action(async (meta, seed) => {
|
||||
if (games.hasOwnProperty(meta.room)) {
|
||||
const currentGame = games[meta.room]
|
||||
|
||||
|
@ -137,17 +155,19 @@ commander
|
|||
]) {
|
||||
await sendMessage(meta.room, item)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
startGame(meta)
|
||||
startGame(meta, seed)
|
||||
})
|
||||
|
||||
commander
|
||||
.command('restart')
|
||||
.description('`restart` : démarrer une nouvelle partie')
|
||||
.action(async (meta) => {
|
||||
startGame(meta)
|
||||
.command('restart [seed]')
|
||||
.description('`restart` ou `restart seed` : démarrer une nouvelle partie avec éventuellement la seed d\'une grille')
|
||||
.action(async (meta, seed) => {
|
||||
startGame(meta, seed)
|
||||
})
|
||||
|
||||
commander
|
||||
|
|
Loading…
Reference in a new issue