1

I'm trying to create grid (for example 5x5). After creating grid I want to click on an item and pass coordinates into my onClick(i,j) method. How can I do this using blessed and blessed-contrib?

This is my code. This is Gomoku game or Five in a row.

let blessed = require('blessed')
    , contrib = require('blessed-contrib')
    , program = blessed.program()

const Gomoku = require('gomoku-js')

let size = 5

let game = new Gomoku(size)

let order = true // 1=X, 0=O

let screen = blessed.screen()

let grid = new contrib.grid({rows: size, cols: size, screen: screen})

for (let i = 0; i < size; i++) {
    for (let j = 0; j < size; j++) {
        grid.set(i, j, 4, 4, blessed.box, {
            content: '',
            bold: 'bold'
        },)
    }
}

function setChess(i, j) {

    if (order === true) {
        grid.set(i, j, 4, 4, blessed.box, {
            content: 'X',
            bold: 'bold'
        },)
    } else {
        grid.set(i, j, 4, 4, blessed.box, {
            content: 'O',
            bold: 'bold'
        },)
        order = false
    }

    try {
        game.setChessOf(order, i, j)
        order = !order
    } catch (e) {
        console.log(e)
    }

}


screen.key(['escape', 'q', 'C-c'], function (ch, key) {
    return process.exit(0)
});

screen.render()

0 Answers0