-
Notifications
You must be signed in to change notification settings - Fork 3
/
a.html
61 lines (59 loc) · 1.96 KB
/
a.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>じゃんけん</title>
<script type="text/javascript">
var intervalId;
var computer;
function roll()
{
var img = {
1: 'stone.png', 2: 'cissor.png', 3: 'paper.png',
};
computer = Math.floor(Math.random() * 3) + 1;
var elem = document.getElementById('computer');
elem.innerHTML = '<img src="' + img[computer] + '"/>';
}
function pong(hand)
{
clearInterval(intervalId);
intervalId = null;
var elem = document.getElementById('status');
if (computer == hand) {
elem.innerHTML = 'あいこ';
} else if (computer == 1 && hand == 3
|| computer == 2 && hand == 1
|| computer == 3 && hand == 2) {
elem.innerHTML = 'あなたの勝ち!';
} else {
elem.innerHTML = 'あなたの負け';
}
elem.innerHTML += '(ここをクリックでもう一度)';
}
function start()
{
if (intervalId) {
return;
}
var elem = document.getElementById('status');
elem.innerHTML = 'じゃーんけん';
roll();
intervalId = setInterval(roll, 100);
}
window.onload = function()
{
start();
};
</script>
</head>
<body>
<div id="computer"></div>
<div id="status" onclick="start();"></div>
<div>
<img src="stone.png" onclick="pong(1)"/>
<img src="cissor.png" onclick="pong(2);"/>
<img src="paper.png" onclick="pong(3);"/>
</div>
</body>
</html>