-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnonet.html
75 lines (69 loc) · 2.33 KB
/
nonet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>狼吃羊</title>
<link rel="stylesheet" type="text/css" href="css/nonet.css">
<script type="text/javascript">
var cssEl = document.createElement('style');
document.documentElement.firstElementChild.appendChild(cssEl);
function setPxPerRem(){
var dpr = 1;
//把viewport分成10份的rem,html标签的font-size设置为1rem的大小;
var pxPerRem = document.documentElement.clientWidth * dpr / 10;
cssEl.innerHTML = 'html{font-size:' + pxPerRem + 'px!important;}';
}
setPxPerRem();
</script>
<script type="text/javascript" src="board.js"></script>
<script type="text/javascript" src="position.js"></script>
</head>
<body>
<div style="text-align:center;white-space:nowrap">
<div id="container"></div>
<div id="sheepText" style="position: absolute; top: 49px; left: 20px;font-size:25px; color: sienna" align="left">欢迎来到狼吃羊 </div>
</div>
<div id="startGame">开始游戏</div>
<div id="setting">设置</div>
<script >
"use strict";
var board = new Board(container, sheepText,"images/"); // 创建棋盘
var sheeps=23
var lesshheeps=12
var start=false
function startGameA() {
startGame.innerText="重新开始"
if(start){
board.endGame()
}
board.startGame(sheeps,lesshheeps)
start=true
}
function prom()
{
var s=parseInt(prompt("请输入初始羊的数目:","23"));//将输入的内容赋给变量 name ,
//这里需要注意的是,prompt有两个参数,前面是提示的话,后面是当对话框出来后,
if(s)//如果返回的有内容
{
if(isNaN(s)){
alert("请输入合法数字")
return
}
if(s<8){
alert("请输入最少8只羊")
return
}
sheeps=s
startGameA()
}
}
document.getElementById("startGame").onclick = function () {
startGameA()
};
document.getElementById("setting").onclick = function () {
//弹出一个输入框,输入一段文字,可以提交
prom()
};
</script>
</body>
</html>