import { playSound, SoundType } from './../../../module/ctrls/soundCtrl';
export const noBlockLeft = (x, y, yl, beforeArr) => {
    if (y > yl + 1) {
        for (let t = yl - 1; t < y; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    if (y < yl + 1) {
        for (let t = y - 1; t < yl; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    return true
}

export const noBlockRight = (x, y, yr, beforeArr) => {
    if (yr > y + 1) {
        for (let t = y - 1; t < yr; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    if (yr < y + 1) {
        for (let t = yr - 1; t < y; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    return true
}

export const noBlockTop = (x, xt, y, beforeArr) => {
    if (x > xt + 1) {
        for (let t = xt - 1; t < x; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    if (x < xt + 1) {
        for (let t = x - 1; t < xt; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    return true
}

export const noBlockBottom = (x, xb, y, beforeArr) => {
    if (xb > x + 1) {
        for (let t = x - 1; t < xb; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    if (xb < x + 1) {
        for (let t = x - 1; t < xb; t++) {
            if (beforeArr[x][y] !== 0) {
                return false
            }
        }
    }
    return true
}

export const checkMusic = (type, isPlay) => {
    if (!isPlay) {
        return
    }

    switch (type) {
        case "move":
            playSound(SoundType.move)
            break
        case "createEle":
            playSound(SoundType.createEle)
            break
        case "createEles":
            playSound(SoundType.createEles)
            break
        case "exchange":
            playSound(SoundType.exchange)
            break
        case "bomb":
            playSound(SoundType.bomb)
            break
        case "gameOver":
            playSound(SoundType.gameOver)
            break
    }
}