MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / randomMove

Function randomMove

assets/js/ludo.js:214–298  ·  view source on GitHub ↗
(Color, paw)

Source from the content-addressed store, hash-verified

212 }
213}
214function randomMove(Color, paw) {
215 var text = document.getElementById('player');
216 NumOfPaw = paw;
217 currcolor = Color;
218 currpawn = currcolor + "pawn" + NumOfPaw;
219 currPos = positions[currpawn];
220 if (num + currPos > 44) {
221 Stuck();
222 }
223 else {
224 if (clicked) {
225 var position = currPos;
226 if (text.innerText == currcolor) {
227 if (onboard[currpawn] === 1 || num === 6) {
228 if (onboard[currpawn] === 0) {
229 var doc = document.getElementById(currpawn);
230 var curr = Number(doc.style.left.replace(/[a-z]/g, ''));
231 switch (Color) {
232 case "red":
233 doc.style.left = 318 + 'px';
234 doc.style.top = 28 + "px";
235 break;
236
237 case "yellow":
238 doc.style.left = 219 + 'px';
239 doc.style.top = 523 + "px";
240 break;
241
242 case "blue":
243 doc.style.left = 516 + 'px';
244 doc.style.top = 325 + "px";
245 break;
246
247 case "green":
248 doc.style.left = 21 + 'px';
249 doc.style.top = 226 + "px";
250 break;
251 }
252 onboard[currpawn] = 1;
253 }
254 else {
255 switch (Color) {
256 case "red":
257 for (i = currPos; i < position + num; i++) {
258 stepsRed[i]();
259 }
260 break;
261
262 case "yellow":
263 for (i = currPos; i < position + num; i++) {
264 stepsYellow[i]();
265 }
266 break;
267
268 case "blue":
269 for (i = currPos; i < position + num; i++) {
270 stepsBlue[i]();
271 }

Callers

nothing calls this directly

Calls 5

StuckFunction · 0.85
HaveHoverFunction · 0.85
ResetPawnFunction · 0.85
CheckForWinnerFunction · 0.85
changePlayerFunction · 0.85

Tested by

no test coverage detected