-
Notifications
You must be signed in to change notification settings - Fork 0
/
Replay.js
118 lines (117 loc) · 3.81 KB
/
Replay.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const timer = window.setInterval(move,2000);
var logid = sessionStorage.getItem(0);
var moves = localStorage.getItem(logid).split(",");
console.log(moves);
var movecount = moves.length;
var x = 0;
function move()
{
let details = moves[x].split(":");
if(details[2] == "position")
{
let final = details[4].replace("[",'');
final = final.replace("]",'');
let move = final.split(";");
let peice = document.getElementById(details[0] + details[1]);
var imgs = document.getElementsByTagName("img");
var img = null;
for(let i in imgs)
{
if(imgs[i].getAttribute("colour") == details[0] && imgs[i].getAttribute("name") == details[1])
{
img = imgs[i];
break;
}
}
peice.style.gridRow = parseInt(move[0]);
peice.style.gridColumn = parseInt(move[1]);
img.removeAttribute("row");
img.removeAttribute("column");
img.setAttribute("row", move[0]);
img.setAttribute("column", move[1]);
console.log(img);
}
if(details[2] == "rotation" && (details[1] == "ricochet_01" || details[1] == "ricochet_02"))
{
let peice = document.getElementById(details[0] + details[1]);
var imgs = document.getElementsByTagName("img");
var img = null;
for(let i in imgs)
{
if(imgs[i].getAttribute("colour") == details[0] && imgs[i].getAttribute("name") == details[1])
{
img = imgs[i];
break;
}
}
if(img.getAttribute("direction") == "clock")
{
img.removeAttribute("direction");
img.setAttribute("direction", "anticlock");
img.src = "Resources/Ricochet_rotated.png";
}
else if(img.getAttribute("direction") == "anticlock")
{
img.removeAttribute("direction");
img.setAttribute("direction", "clock");
img.src = "Resources/Ricochet.png";
}
}
if(details[2] == "rotation" && (details[1] == "semiricochet_01" || details[1] == "semiricochet_02"))
{
let final = details[3];
final = final.replace('[','');
final = final.replace(']','');
let move = final.split(";");
let peice = document.getElementById(details[0] + details[1]);
var imgs = document.getElementsByTagName("img");
var img = null;
for(let i in imgs)
{
if(imgs[i].getAttribute("colour") == details[0] && imgs[i].getAttribute("name") == details[1])
{
img = imgs[i];
break;
}
}
img.removeAttribute("direction");
img.setAttribute("direction", move[1]);
if(move[1] == "0")
{
img.src = "Resources/Semi Ricochet01.png";
}
else if(move[1] == "1")
{
img.src = "Resources/Semi Ricochet02.png";
}
else if(move[1] == "2")
{
img.src = "Resources/Semi Ricochet03.png";
}
else if(move[1] == "3")
{
img.src = "Resources/Semi Ricochet04.png";
}
}
if(details[2] == "destroy")
{
let peice = document.getElementById(details[0] + details[1]);
var grid = document.getElementsByClassName("grid");
grid[0].removeChild(peice);
}
x = x + 1;
if(x == movecount)
{
clearInterval(timer);
gameover();
}
}
function gameover()
{
var over = document.createElement("div");
over.setAttribute("class","gameover");
var text = document.createElement("h1");
text.innerHTML = "Game Over";
over.appendChild(text);
document.body.appendChild(over);
}