发表于: 2017-05-05 12:47:05
4 976
今天完成的事情:
# 获取返回键id并返回
$("#back").click ->
window.history.back(-1)
# 法官日志
$("#log").click ->
window.location.href = "fourth.html"
# 游戏结束
$("#end").click ->
window.location.href = "seventh.html"
# 天数 通过跳转判定的 计算器
# 提取當前天數計數
num = JSON.parse(sessionStorage.getItem("num"))
$ ->
role = JSON.parse(sessionStorage.getItem("role"))
sura = 0
surb = 0
number = 0
while number < role.length
if role[number] is "殺手"
sura++
else if role[number] is "凡人"
surb++
JSON.stringify(sessionStorage.setItem("sura",sura))
JSON.stringify(sessionStorage.setItem("surb",surb))
number++
# 如果計數為空 讓其變為0
if num is null
num = parseInt("0")
num += 1
# 每两个num为一天
day = Math.floor(num/2+0.5)
JSON.stringify(sessionStorage.setItem("num",num))
# 測試用
# day = 5
create(day)
# 提取钥匙2
kagi = JSON.parse(sessionStorage.getItem("kagi"))
ken = $("box").eq(day - 1).children("p").eq(0)
# 如果点击过,让他变灰
if kagi is true
ken.attr("class","ded")
return false
# 複製盒子
create = (day) ->
# 變量 計數 初始化
box_first = 1
$(".today").html("第" + day + "天")
while box_first < day
$("#fifth > .container > .row")
.eq(0)
.clone(true)
.appendTo("#fifth > .container")
box_first++
change(day)
change = (day) ->
box_second = 0
while box_second < day
$(".days")
.eq(box_second)
.html("第" + (box_second+1) + "天")
sum = 0
list = JSON.parse(sessionStorage.getItem("list"))
if list is null
list = 0
while sum < list.length
if list[sum] is "killer"
who = "殺手"
else if list[sum] is "people"
who = "凡人"
if sum%2 is 0
time = "早上"
else
time = "晚上"
$("info").eq(sum).html("第" + Math.floor(sum/2+1) + "天" + time + who + "死了")
sum++
if box_second is day - 1
$("box")
.eq(box_second)
.children("p")
.attr("class","live")
$("box:not(:last)").hide()
box_second++
state(day)
else
$("box")
.eq(box_second)
.children("p")
.attr("class","ded")
box_second++
# 创建完后隐藏所有box
# $("box").hide()
# 点击strong标签弹出菜单 和 隐藏
$("strong").click ->
x = $("strong").index($(this))
hish = $("box").eq(x)
hish.css("display") is "none" && hish.show() || hish.hide();
# 四个小内容的状态
state = (day) ->
# 获取box下的p
btn_p = $("box")
.eq(day - 1)
.children("p")
# 当这些P被点击的时候
# 给y初始值
y = 0
btn_p.click ->
# 提取钥匙1
key = JSON.parse(sessionStorage.getItem("key"))
# 提取钥匙2
kagi = JSON.parse(sessionStorage.getItem("kagi"))
# 对应的索引值
p = btn_p.index($(this))
# 判断索引和钥匙的第一次为null的时候自动打开
if p is 0 and key is null
# 存储钥匙1和钥匙2下次备用
window.sessionStorage.setItem("key",false)
window.sessionStorage.setItem("kagi",true)
window.location.href = "sixth.html"
# 判断索引为1和钥匙2为真的时候打开
else if p is 1 and kagi is true
y = 2
change = btn_p.eq(p).attr("class","ded")
# 判断索引为2从上面拿到y时打开
else if p is 2 and y is 2
y = 3
change = btn_p.eq(p).attr("class","ded")
# 判断索引为3从上面拿到y时打开
else if p is 3 and y is 3
change = btn_p.eq(p).attr("class","ded")
# 重置两把钥匙为初始化并跳转页面
window.sessionStorage.setItem("key",null)
# 关掉开关二阀门
window.sessionStorage.setItem("kagi",false)
window.location.href = "sixth.html"
else
alert "not!"
# 返回上一頁
$("#back").click = ->
window.history.back(-1)
# 全局變量
list = []
# 提取数据
role = JSON.parse(sessionStorage.getItem("role"))
list = JSON.parse(sessionStorage.getItem("list"))
if list is null
list = []
length = role.length
# 返回頁面5時
$ ->
a = 0
b = 0
c = 0
while c < length
if role[c] is "殺手"
a++
else if role[c] is "凡人"
b++
c++
if a >= b or a is 0
window.location.href = "seventh.html"
num = JSON.parse(sessionStorage.getItem("num"))
if num%2 is 1
$(".anniu").html("殺手殺人")
else
$(".anniu").html("投票時間")
# 创建小盒子
x = 0
while x < length
$("#warp").append('<div> </div>')
if role[x] is "死亡"
$("#warp > div").eq(x).css("backgroundColor","#d0af4c").html("死亡")
x++
$("#warp > div").click ->
z = $("#warp > div").index($(this))
if role[z] is "殺手" and num%2 is 1
alert "殺手不能殺自己"
else if role[z] is "殺手"
role[z] = "死亡"
num += 1
JSON.stringify(sessionStorage.setItem("num",num))
role = JSON.stringify(role)
sessionStorage.setItem("role",role)
list.push("killer")
console.log list
list = JSON.stringify(list)
sessionStorage.setItem("list",list)
console.log list
window.location.href = "fifth.html"
else if role[z] is "凡人"
role[z] = "死亡"
num += 1
JSON.stringify(sessionStorage.setItem("num",num))
role = JSON.stringify(role)
sessionStorage.setItem("role",role)
list.push("people")
console.log list
list = JSON.stringify(list)
sessionStorage.setItem("list",list)
console.log list
window.location.href = "fifth.html"
# 获取返回键id并返回
$("#back").click ->
window.history.back(-1)
# 重新開始
$("#start").click ->
window.location.href = "index.html"
sessionStorage.removeItem("kagi")
sessionStorage.removeItem("key")
sessionStorage.removeItem("killer_say")
sessionStorage.removeItem("list")
sessionStorage.removeItem("num")
sessionStorage.removeItem("people_say")
sessionStorage.removeItem("role")
sessionStorage.removeItem("sura")
sessionStorage.removeItem("surb")
$ ->
killer_say = JSON.parse(sessionStorage.getItem("killer_say"))
people_say = JSON.parse(sessionStorage.getItem("people_say"))
$("output").eq(0).html("殺手說:" + killer_say)
$("output").eq(1).html("凡人說:" + people_say)
list = JSON.parse(sessionStorage.getItem("list"))
quic = 0
while quic < list.length
if list[quic] is "killer"
who = "殺手"
else if list[quic] is "people"
who = "凡人"
if quic%2 is 0
time = "早上"
else
time = "晚上"
$("footer").append('<div></div>')
$("footer > div").eq(quic).html("第" + Math.floor(quic/2+1) + "天" + time + who + "死了")
quic++
sura = JSON.parse(sessionStorage.getItem("sura"))
surb = JSON.parse(sessionStorage.getItem("surb"))
$("output").eq(2).html("殺手剩余:" + sura)
$("output").eq(3).html("凡人剩余:" + surb)
if sura is surb
$("#over").html("平局")
else if sura > surb
$("#over").html("杀手胜")
else
$("#over").html("凡人的胜利")
明天计划的事情:
用jQuery写任务5
遇到的问题:
无
收获:
无
评论