const init = () => {
const playground = document.querySelector(".background");
setScore(0);
for (let i = 0; i < rows; i++) {
createLine(playground);
}
generateNewBlock(playground);
};
const generateNewBlock = (background: any) => {
clearInterval(autoDrop);
autoDrop = setInterval(() => {
moveBlock("top", 1, background);
}, speed);
const randomIndex = Math.floor(Math.random() * blockArray.length);
movingItem.type = blockArray[randomIndex][0];
movingItem.top = 0;
movingItem.left = 3;
movingItem.direction = 0;
tempMovingItem = { ...movingItem };
renderBlocks(background);
};
-------->
let nexRandomIndex
const [test, setTest] = useState(0) as any;
...........
const init = () => {
const playground = document.querySelector(".background");
setScore(0);
for (let i = 0; i < rows; i++) {
createLine(playground);
}
const firstRandom = Math.floor(Math.random() * blockArray.length);
generateNewBlock(playground, firstRandom);
};
const generateNewBlock = (background: any, firstRandom?: number) => {
clearInterval(autoDrop);
autoDrop = setInterval(() => {
moveBlock("top", 1, background);
}, speed);
const randomIndex = firstRandom ? firstRandom : nexRrandomIndex;
movingItem.type = blockArray[randomIndex][0];
movingItem.top = 0;
movingItem.left = 3;
movingItem.direction = 0;
tempMovingItem = { ...movingItem };
renderBlocks(background);
nextRandomIndex = Math.floor(Math.random() * blockArray.length);
setTest(nextRandomIndex);
};
..........
return
<NextBlock src={`/img/tetris/${blockArray[test][0]}.PNG`} />