发表于: 2019-12-11 23:13:14

1 968


今日完成的工作

今天完成的东西是对我们任务四天数循环的过程,其中涉及到的点会比较的复杂一些。首先的话我们页面的显示只能够先点击杀手杀人按钮所以使用上下文的获取节点方式循环执行点击事件。

for (let i = 0i < 9i++) {
    dropdown[i].getElementsByClassName("sr")[1].onclick = function () {
        alert('不能这样玩游戏')
    }
    dropdown[i].getElementsByClassName("sr")[2].onclick = function () {
        alert('不能这样玩游戏')
    }
    dropdown[i].getElementsByClassName("sr")[3].onclick = function () {
        alert('不能这样玩游戏')
    }
}

第二个方面是我们死亡人物的状态显示使用的是数组长度的方式,确定哪几块会显示

for (let i = 1i < 18i++) {
    if (everyday.length == i) {
        for (a = 0a < ia++) {
            show[a].style = "display:block"
            which[a].innerHTML = everyday[a]
            smsf[a].innerHTML = sf[everyday[a] - 1]
        }
    }
}

第三个方面是我们这个点击顺序的问题所在。也是通过循环九天的方式让每一天内的逻辑关系通顺运行,方法是我么在每次点击上层按钮时往里面存一个值,在存完值后判断是否等于这个值,因为会页面跳转的关系,所以重新加载时可以有这个顺序产生的效果,然后根据上下文的获取节点关系我们可以做出这个九天的循环。

//点击顺序判断第一天循环9天的这个顺序  需要循环9个状态
 for(let a=0;a<9;a++){
dropdown[a].getElementsByClassName("sr")[0].onclick=function(){
        localStorage.setItem("tschoose"1)
        //    给前一页显示投票按钮的量
        localStorage.removeItem("bj")
        // 移除后显示投票按钮
        localStorage.removeItem("rrr")
        //移除后我们点击能出现小刀下标
        localStorage.setItem("djsx"a)
        window.location.href = "task7b.html"
    }   
if (localStorage.getItem("djsx") == a) {
    dropdown[a].getElementsByClassName("sr")[1].onclick = function () {
        alert("亡灵发言")
        dropdown[a].getElementsByClassName("sr")[1].style.backgroundColor = "red"
        if (dropdown[a].getElementsByClassName("sr")[1].style.backgroundColor =="red") {
            dropdown[a].getElementsByClassName("sr")[1].onclick = function () {
                alert("不能这样玩游戏")
            }
        }
        localStorage.setItem("djsx"a+0.5)
        if (localStorage.getItem("djsx") == a+0.5) {
            dropdown[a].getElementsByClassName("sr")[2].onclick = function () {
                alert("玩家发言")
                dropdown[a].getElementsByClassName("sr")[2].style.backgroundColor = "red"
                if (dropdown[a].getElementsByClassName("sr")[2].style.backgroundColor == "red") {
                   dropdown[a].getElementsByClassName("sr")[2].onclick = function () {
                        alert("不能这样玩游戏")
                    }
                }
                dropdown[a].getElementsByClassName("sr")[3].onclick = function () {
                    window.location.href = "task7b.html"
                    
                }
            }
        }
    }
    dropdown[a].getElementsByClassName("sr")[2].onclick = function () {
        alert('不能这样玩游戏')
    }
    dropdown[a].getElementsByClassName("sr")[3].onclick = function () {
        alert("不能这样玩游戏")
    }
}
}

之后时判断颜色,若是它为红色那么我们点击时出现不能这样玩游戏的效果

//颜色变换 能循环状态
for(let i=0;i<35;i++){
    if(btn[i].style.backgroundColor=="red")
    {
        btn[i].onclick=function(){
            alert("不能这样玩游戏")
        } 
    }
}

之后时根据数组长度基数偶数的关系每次跳转回来给它附上我们要的红色

//数组长度为基数偶数时变红出现
for (let i = 0i < 18i++) {
    if (everyday.length == i + 1) {
        if(everyday.length % 2 == 0){
            for (a = 0a < (i+1)/2a++) {
                dropdown[a].getElementsByClassName("sr")[0].style.backgroundColor = "red"
                dropdown[a].getElementsByClassName("sr")[1].style.backgroundColor = "red"
                dropdown[a].getElementsByClassName("sr")[2].style.backgroundColor = "red"
                dropdown[a].getElementsByClassName("sr")[3].style.backgroundColor = "red"
            }
        }
        else{
            for(b = 0b < (i+1)/2-1b++){
                dropdown[b].getElementsByClassName("sr")[0].style.backgroundColor = "red"
                dropdown[b].getElementsByClassName("sr")[1].style.backgroundColor = "red"
                dropdown[b].getElementsByClassName("sr")[2].style.backgroundColor = "red"
                dropdown[b].getElementsByClassName("sr")[3].style.backgroundColor = "red"
                dropdown[b+1].getElementsByClassName("sr")[0].style.backgroundColor = "red"

            }
           
        }
    }
}

之后是我们白天投票投完之后的下一天显示的问题

//数组长度为偶数显示它的下一天 循环状态
var po=everyday.length/2;
if(everyday.length%2==0&&everyday.length!=0){
    for(let a=0;a<po+1;a++){
       dropdown[a].style="display:block"
    }
     dropcontent[po].style="display:block"
}else
{for(let a=0;a<po;a++){
    dropdown[a].style="display:block"
 }}

明天要完成的工作

明天要把两个按钮的点击事件完成,并且做出游戏结果的判断


返回列表 返回列表
评论

    分享到