this.currentQuestion = 0;
this.currentLetter = 0;
this.positionLetters = [
{
cells: [
[6, 0],
[7, 0],
[8, 0],
],
keyboard: ['a', 'a', 'z', 'm', 'c', 'n', 'c', 'd'],
question: 'Not a Woman',
},
{
cells: [
[0, 1],
[0, 0],
],
keyboard: ['D', 'A', 'T', 'M', 'C', 'N', 'C', 'D'],
question: 'Father',
},
{
cells: [
[0, 0],
[0, 1],
[0, 2],
],
keyboard: ['D', 'O', 'N', 'M', 'O', 'W', 'C', 'Y'],
question: 'Not up',
},
{
cells: [
[1, 8]
],
keyboard: ['D', 'O', 'N', 'M', 'O', 'A', 'C', 'Y'],
question: 'Sun',
},
{
cells: [
[8, 0],
[8, 1],
[8, 2],
[8, 3],
],
keyboard: ['D', 'E', 'N', 'M', 'O', 'A', 'C', 'R'],
question: 'Oppsite of far',
},
];
this.startingField = [
[' ', ' ', 'd', '.', '.', 's', 'e', 'n', 'd'],
[' ', '.', 'e', 'a', 's', 't', '.', '.', ' '],
[' ', '.', 'a', '.', '.', 'i', 't', 's', 'y'],
['n', 'e', 'r', 'f', '.', 'n', '.', 't', '.'],
['.', 'a', '.', 'a', 'r', 'k', '.', 'u', '.'],
['.', 's', '.', 't', '.', 's', 'y', 'n', 'c'],
['m', 'e', 's', 'h', '.', '.', 'a', '.', 'a'],
[' ', '.', '.', 'e', 'v', 'e', 'r', '.', 'r'],
[' ', ' ', ' ', ' ', '.', '.', 'd', 'i', 'd'],
];
this.checkWord = [
['d', 'a', 0, 0, 0, 0, 0, 0, 0],
['o', 0, 0, 0, 0, 0, 0, 0, 'a'],
['w', 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
['a', 0, 0, 0, 0, 0, 0, 0, 0],
['n', 'e', 'a', 'r', 0, 0, 0, 0, 0],
];
this.gotoNextCell = () => {
const questionObj = this.positionLetters[this.currentQuestion];
console.log('questionObj = ', questionObj);
// Клетки текущего слова — questionObj.cells.
// Т.к. мы можем начинать и не с первой клетки, берем слайс нашего массива.
const slicedCells = questionObj.cells.slice(this.currentLetter);
const nextIndex = slicedCells
// Люблю я функциональный стиль :)
// Так посмотрим на буквы которые есть на поле в наших клетках.
.map(([i, j]) => this.startingField[i][j])
.findIndex((e) => e === ' ');
if (nextIndex >= 0) {
// Индекс следующей клетки.
this.currentLetter += nextIndex;
return true;
} else {
this.currentLetter = 0;
return false;
}
};