connect4-discord
Version:
<h3><a href="https://krypton.sergioesquina.repl.co/npm/discord-c4">Discord-C4</a>, crea un tablero, y checkea una partida de Conecta 4
33 lines (30 loc) • 1.5 kB
JavaScript
class Board {
constructor(Discord){
if(!Discord) throw new TypeError("Please, provide Discord")
if(!size) throw new TypeError("Please, provide the size")
if(Discord.version < "13") throw new Error("Only version ^13 is supported")
const { MessageButton: mb, MessageActionRow: mar } = Discord
this.Discord = Discord
this.size = 5
this.board = new Array(this.size).fill(new Array(this.size))
this.rows = []
let i = 0, i2 = 0
for(i; i < this.size*this.size; i++){
this.rows.push(new mb().setLabel("?").setStyle("SECONDARY").setCustomId(`button-${i}`))
}
if(this.size == 5){
this.board[0] = [this.rows[0], this.rows[1], this.rows[2], this.rows[3], this.rows[4]]
this.board[1] = [this.rows[5], this.rows[6], this.rows[7], this.rows[8], this.rows[9]]
this.board[2] = [this.rows[10], this.rows[11], this.rows[12], this.rows[13], this.rows[14]]
this.board[3] = [this.rows[15], this.rows[16], this.rows[17], this.rows[18], this.rows[19]]
this.board[4] = [this.rows[20], this.rows[21], this.rows[22], this.rows[23], this.rows[24]]
}else {
this.board[0] = [this.rows[0], this.rows[1], this.rows[2], this.rows[3]]
this.board[1] = [this.rows[4], this.rows[5], this.rows[6], this.rows[7]]
this.board[2] = [this.rows[8], this.rows[9], this.rows[10], this.rows[11]]
this.board[3] = [this.rows[12], this.rows[13], this.rows[14], this.rows[15]]
}
return this
}
}
module.exports = Board