Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.22 KB | None | 0 0
  1. var numeSalon = "";
  2. var limba;
  3. var nivelSelectat;
  4. var sumaInceput;
  5. var scorPropus;
  6. var highScore;
  7. var timp = 0;
  8. var x = 3;
  9. var locuri = new Array();
  10. var interval_om;
  11. var interval_timp;
  12. var apasat = false;
  13. var lastClicked;
  14. var nr_vieti;
  15. var viteza_aparitie;
  16. var caracter_apasat;
  17. var coord_x_mouse;
  18. var coord_y_mouse;
  19. var start;
  20. var contor_par = 0;
  21.  
  22. window.onmousemove = function(e)
  23. {
  24. coord_x_mouse = e.pageX;
  25. coord_y_mouse = e.pageY;
  26. }
  27.  
  28. for(var i=0; i<12; i++)
  29. {
  30. locuri.push(false);
  31. }
  32.  
  33. class loader
  34. {
  35. constructor()
  36. {
  37. this.imagini=new Object();
  38. this.sunete={};
  39. this.mesaje={};
  40. this.limba;
  41. }
  42.  
  43. getImagine(id){
  44. var L = this;
  45. if(L.imagini[id].aparitie == "multipla")
  46. {
  47. var aux = L.imagini[id];
  48. var im_nou = document.createElement("img");
  49. im_nou.src = L.imagini[id].src;
  50. im_nou.w = L.imagini[id].w;
  51. im_nou.h = L.imagini[id].h;
  52. im_nou.aparitie = L.imagini[id].aparitie;
  53. L.imagini[id] = im_nou;
  54. return aux;
  55. }
  56. else
  57. return L.imagini[id];
  58. }
  59.  
  60. getSunet(id)
  61. {
  62. var L = this;
  63. return L.sunete[id];
  64. }
  65.  
  66. getMesaj(id)
  67. {
  68. var L = this;
  69. return L.mesaje[id];
  70. }
  71.  
  72. getLimba()
  73. {
  74. return this.limba;
  75. }
  76.  
  77. /*getVitezaAparitie()
  78. {
  79. return this.viteza_aparitie;
  80. }*/
  81.  
  82. //getNrVieti()
  83. //{
  84. // return this.nr_vieti;
  85. //}
  86.  
  87. parseResources()
  88. {
  89. var L = this;
  90. $.ajax({
  91. url: "resurse.xml",
  92. type:"GET",
  93. dataType: "xml",
  94. success: function(xml)
  95. {
  96. var $xml = $(xml);
  97. var $imagini = $xml.find( "imagine" );
  98. $imagini.each(function(i){
  99. var cale=$(this).text();
  100. var id = $(this).attr("id");
  101. var w = $(this).attr("w");
  102. var h = $(this).attr("h");
  103. var aparitie = $(this).attr("aparitie");
  104. var imagine = document.createElement("img");
  105. imagine.src = cale;
  106. L.imagini[id]=imagine;
  107. L.imagini[id].aparitie = aparitie;
  108. L.imagini[id].w=w;
  109. L.imagini[id].h=h;
  110. });
  111.  
  112. var $sunete = $xml.find("sunet");
  113. $sunete.each(function(i){
  114. var sunet = document.createElement("audio");
  115. var cale = $(this).text();
  116. sunet.src = cale;
  117. var id = $(this).attr("id");
  118. L.sunete[id]=sunet;
  119. });
  120. x--;
  121. },
  122. error: function(err){
  123. alert(err);
  124. }
  125. });
  126.  
  127. $.ajax({
  128. url: "mesaje.xml",
  129. type: "GET",
  130. dataType: "xml",
  131. success: function(xml)
  132. {
  133. var $xml = $(xml);
  134. var $mesaje = $xml.find("mesaje[lang=\"" + L.getLimba() + "\"]");
  135. $mesaje.each(function(i)
  136. {
  137. var id = $(this).attr("id");
  138. L.mesaje[id] = $(this).text();
  139. });
  140. x--;
  141. },
  142. error: function(err){
  143. alert(err);
  144. }
  145. });
  146.  
  147. $.ajax
  148. ({
  149. url: "setari.xml",
  150. type: "GET",
  151. dataType: "xml",
  152. success: function(xml)
  153. {
  154. var vtz, nr_vt;
  155. var $xml = $(xml);
  156. var nivel = $xml.find("nivel" + nivelSelectat);
  157. nr_vieti = parseInt(nivel.attr("nr_vieti"));
  158. viteza_aparitie = parseInt(nivel.attr("viteza_aparitie"));
  159. x--;
  160. },
  161. error: function(err){
  162. alert(err);
  163. }
  164. });
  165. }
  166.  
  167. }
  168.  
  169. function updateClock() {
  170. var now = new Date(),
  171. months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'September', 'November', 'December'];
  172. time = now.getHours() + ':' + now.getMinutes() ,
  173.  
  174.  
  175. date = [now.getDate(),
  176. months[now.getMonth()],
  177. now.getFullYear()].join(' ');
  178.  
  179.  
  180. document.getElementById('time').innerHTML = [date, time].join(' / ');
  181. document.getElementById('time').style.position = "absolute";
  182. document.getElementById('time').style.top = "0";
  183.  
  184. setTimeout(updateClock, 1000);
  185. }
  186.  
  187. /*function updateTimp()
  188. {
  189. document.getElementById("div_timp").innerHTML = "Timp(Time): " + timp;
  190. timp++;
  191. interval_timp = setTimeout(updateTimp, 1000);
  192. }*/
  193.  
  194. window.setInterval((function()
  195. {
  196. return function()
  197. {
  198. if(document.getElementById("div_timp") != null)
  199. {
  200. document.getElementById("div_timp").innerHTML = "Timp(Time): " + (Math.floor((Date.now()-start)/1000) + 1);
  201. timp = (Math.floor((Date.now()-start)/1000) + 1)
  202. }
  203. };
  204. }()), 1000);
  205.  
  206. function rand(a,b)
  207. {
  208. return Math.floor(Math.random() * b) + a;
  209. }
  210.  
  211. class Joc
  212. {
  213. constructor()
  214. {
  215. }
  216.  
  217. init(L)
  218. {
  219. start = Date.now();
  220. document.getElementById("container_setari").style.display = "none";
  221. document.getElementById("container_joc").style.display = "block";
  222. var nume = document.createElement("h2");
  223. nume.id = "nume";
  224. nume.innerHTML = numeSalon;
  225. nume.style.marginLeft = "900px";
  226. document.body.insertBefore(nume, document.getElementById("container_joc"));
  227. var div_scor = document.createElement("div");
  228. div_scor.style.position = "absolute";
  229. div_scor.style.left = "10px";
  230. div_scor.style.top = "30px";
  231. div_scor.id = "div_scor";
  232. div_scor.innerHTML = "High Score(minutes): " + highScore;
  233. document.body.appendChild(div_scor);
  234. var div_suma = document.createElement("div");
  235. div_suma.style.position = "absolute";
  236. div_suma.style.left = "10px";
  237. div_suma.style.top = "60px";
  238. div_suma.id = "div_suma"
  239. div_suma.innerHTML = "Suma bani(Money): " + sumaInceput;
  240. document.body.appendChild(div_suma);
  241. updateClock();
  242. var div_timp = document.createElement("div");
  243. div_timp.style.position = "absolute";
  244. div_timp.style.left = "10px";
  245. div_timp.style.top = "90px";
  246. div_timp.id = "div_timp";
  247. document.body.appendChild(div_timp);
  248. //updateTimp();
  249. var div_scor_propus = document.createElement("div");
  250. div_scor_propus.style.position = "absolute";
  251. div_scor_propus.style.left = "10px";
  252. div_scor_propus.style.top = "120px";
  253. div_scor_propus.innerHTML = "Scor propus(Score to attain): " + scorPropus;
  254. div_scor_propus.id = "div_scor_propus";
  255. document.body.appendChild(div_scor_propus);
  256. var div_nr_vieti = document.createElement("div");
  257. div_nr_vieti.style.position = "absolute";
  258. div_nr_vieti.style.left = "10px";
  259. div_nr_vieti.style.top = "150px";
  260. div_nr_vieti.innerHTML = "Numar vieti(Health Points): " + nr_vieti;
  261. div_nr_vieti.id = "div_nr_vieti";
  262. document.body.appendChild(div_nr_vieti);
  263. interval_om = setInterval(function(){spawneaza_om(L);}, viteza_aparitie * 1000);
  264. window.onkeypress = function(e)
  265. {
  266. var cod = e.which;
  267. var caracter = String.fromCharCode(cod);
  268. if(!e.ctrlKey)
  269. {
  270. if(caracter == "r")
  271. {
  272. if(apasat == false)
  273. {
  274. if(sumaInceput >= 50)
  275. {
  276. caracter_apasat = "r"
  277. apasat = true;
  278. var camera;
  279. camera = document.createElement("div");
  280. camera.style.position = "absolute";
  281. camera.style.backgroundColor = "red";
  282. camera.style.width = "120px";
  283. camera.style.height = "120px";
  284. camera.className = "camera";
  285. camera.style.left = coord_x_mouse - 435 + "px";
  286. camera.style.top = coord_y_mouse - 110 + "px";
  287. document.getElementById("container_joc").appendChild(camera);
  288. document.getElementById("container_joc").onmousemove = function(e)
  289. {
  290. var aux = document.getElementsByClassName("camera");
  291. var index = aux.length;
  292. document.getElementsByClassName("camera")[index-1].style.left = e.pageX - 435 + "px";
  293. document.getElementsByClassName("camera")[index-1].style.top = e.pageY - 110 + "px";
  294. } ;
  295. }
  296. else
  297. alert("Suma insuficienta");
  298. }
  299. }
  300. if(caracter == "v")
  301. {
  302. if(apasat == false)
  303. {
  304. if(sumaInceput >= 50)
  305. {
  306. caracter_apasat = "v";
  307. apasat = true;
  308. var camera;
  309. camera = document.createElement("div");
  310. camera.style.position = "absolute";
  311. camera.style.backgroundColor = "green";
  312. camera.style.width = "120px";
  313. camera.style.height = "120px";
  314. camera.className = "camera";
  315. camera.style.left = coord_x_mouse - 435 + "px";
  316. camera.style.top = coord_y_mouse - 110 + "px";
  317. document.getElementById("container_joc").appendChild(camera);
  318. document.getElementById("container_joc").onmousemove = function(e)
  319. {
  320. var aux = document.getElementsByClassName("camera");
  321. var index = aux.length;
  322. document.getElementsByClassName("camera")[index-1].style.left = e.pageX - 435 + "px";
  323. document.getElementsByClassName("camera")[index-1].style.top = e.pageY - 110 + "px";
  324. } ;
  325. }
  326. else
  327. alert("Suma insuficienta");
  328. }
  329. }
  330. if(caracter == "a")
  331. {
  332. if(apasat == false)
  333. {
  334. if(sumaInceput >=50)
  335. {
  336. caracter_apasat = "a";
  337. apasat = true;
  338. var camera;
  339. camera = document.createElement("div");
  340. camera.style.position = "absolute";
  341. camera.style.backgroundColor = "blue";
  342. camera.style.width = "120px";
  343. camera.style.height = "120px";
  344. camera.className = "camera";
  345. camera.style.left = coord_x_mouse - 435 + "px";
  346. camera.style.top = coord_y_mouse - 110 + "px";
  347. document.getElementById("container_joc").appendChild(camera);
  348. document.getElementById("container_joc").onmousemove = function(e)
  349. {
  350. var aux = document.getElementsByClassName("camera");
  351. var index = aux.length;
  352. document.getElementsByClassName("camera")[index-1].style.left = e.pageX - 435 + "px";
  353. document.getElementsByClassName("camera")[index-1].style.top = e.pageY - 110 + "px";
  354. } ;
  355. }
  356. else
  357. alert("Suma insuficienta");
  358. }
  359. }
  360. }
  361. }
  362. window.onkeyup = function(e)
  363. {
  364. var cod = e.which;
  365. var caracter = String.fromCharCode(cod);
  366. if((caracter == "R" || caracter == "V" || caracter == "A") && (caracter.toLowerCase() == caracter_apasat))
  367. {
  368. var camere = document.getElementsByClassName("camera");
  369. var sw = true;
  370. for(var i=0; i<camere.length-1; i++)
  371. {
  372. var stil1 = getComputedStyle(camere[i]);
  373. var stil2 = getComputedStyle(camere[camere.length-1]);
  374. var coliziune = test_coliziune(parseInt(stil1.top),parseInt(stil1.left),parseInt(stil1.height),parseInt(stil1.width),
  375. parseInt(stil2.top),parseInt(stil2.left),parseInt(stil2.height),parseInt(stil2.width));
  376. if(coliziune)
  377. {
  378. alert("Coliziune");
  379. document.getElementById("container_joc").onmousemove = null;
  380. document.getElementById("container_joc").removeChild(camere[camere.length-1]);
  381. sw = false;
  382. break;
  383. }
  384. }
  385. if(sw == true)
  386. {
  387. var stil2 = getComputedStyle(camere[camere.length-1]);
  388. if(parseInt(stil2.left) < 0 || parseInt(stil2.top) < 0 || parseInt(stil2.left) > 880 || parseInt(stil2.top) > 480)
  389. {
  390. alert("Coliziune");
  391. document.getElementById("container_joc").onmousemove = null;
  392. document.getElementById("container_joc").removeChild(camere[camere.length-1]);
  393. sw = false;
  394. }
  395. }
  396. if(sw == true)
  397. {
  398. camere[camere.length-1].setAttribute("ocupat", "0");
  399. camere[camere.length-1].onclick = function()
  400. {
  401. if(lastClicked.className == "div_om" && this.getAttribute("ocupat") == "0" && lastClicked.getAttribute("in_miscare") == "0")
  402. {
  403. var sw=true;
  404. var contor = lastClicked.getElementsByClassName("culoare");
  405. var i;
  406. var j;
  407. for(i=0; i<contor.length; i++)
  408. {
  409. if(contor[i].style.backgroundColor == this.style.backgroundColor)
  410. {
  411. for(j=0; j<contor.length; j++)
  412. contor[j].style.display = "none";
  413. lastClicked.style.backgroundColor = "transparent";
  414. //locuri[parseInt(lastClicked.id)] = false;
  415. lastClicked.style.zIndex = "1";
  416. this.setAttribute("ocupat", "1");
  417. lastClicked.onclick = null;
  418. lastClicked.setAttribute("in_miscare", "1");
  419. var par = lastClicked.getElementsByTagName("div")[0];
  420. locuri[parseInt(lastClicked.id)] = false;
  421. var aux = lastClicked;
  422. miscare_om(aux, parseInt(lastClicked.style.top), parseInt(lastClicked.style.left), 1, 5, (parseInt(this.style.left) - parseInt(lastClicked.style.left) + 15) / 5 ,
  423. (parseInt(this.style.top) - parseInt(lastClicked.style.top) + 15) / 5, parseInt(this.style.left) + 15 , parseInt(this.style.top) + 15, this, par);
  424. sw=false;
  425. break;
  426. }
  427. }
  428. if(sw == true)
  429. {
  430. nr_vieti--;
  431. locuri[parseInt(lastClicked.id)] = false;
  432. document.getElementById("container_joc").removeChild(lastClicked);
  433. lastClicked = null;
  434. document.getElementById("div_nr_vieti").innerHTML = "Numar vieti(Health Points): " + nr_vieti;
  435. if(nr_vieti == 0)
  436. gameOver(L);
  437. }
  438. }
  439. else if(lastClicked.className == "div_om" && this.getAttribute("ocupat") == "1")
  440. alert("Ocupat");
  441.  
  442. }
  443. if(document.getElementById("container_joc").onmousemove == null)
  444. document.getElementById("container_joc").removeChild(camere[camere.length-1]);
  445.  
  446. document.getElementById("container_joc").onmousemove = null;
  447. sumaInceput -= 50;
  448. document.getElementById("div_suma").innerHTML = "Suma bani(Money): " + sumaInceput;
  449. }
  450. apasat = false;
  451. }
  452. }
  453. }
  454. }
  455.  
  456.  
  457. miscare_om = function(om , top_r, left_r, pas_c, nr_pasi, dleft, dtop, left_f, top_f, camera, par)
  458. {
  459. if (pas_c<nr_pasi)
  460. {
  461.  
  462. top_r+=dtop;
  463. left_r+=dleft;
  464.  
  465.  
  466. om.style.top=(Math.round(top_r))+"px";
  467. om.style.left=(Math.round(left_r))+"px";
  468.  
  469.  
  470. pas_c++;
  471.  
  472.  
  473. setTimeout(function () {miscare_om(om , top_r, left_r, pas_c, nr_pasi, dleft, dtop, left_f, top_f, camera, par);}, 400);
  474. }
  475. else
  476. {
  477. om.style.top=(top_f+"px");
  478. om.style.left=(left_f+"px");
  479. //var aux = document.getElementById("div_par" + om.id);
  480. if(camera.style.backgroundColor == "blue")
  481. par.animate([
  482.  
  483. { background: "#E0E0E0" },
  484. { background: 'blue' }
  485. ], {
  486.  
  487. duration: 3000,
  488. iterations: 1
  489. });
  490.  
  491. else if(camera.style.backgroundColor == "red")
  492. par.animate([
  493.  
  494. { background: "#E0E0E0" },
  495. { background: 'red' }
  496. ], {
  497.  
  498. duration: 3000,
  499. iterations: 1
  500. });
  501.  
  502. else
  503. par.animate([
  504.  
  505. { background: "#E0E0E0" },
  506. { background: 'green' }
  507. ], {
  508.  
  509. duration: 3000,
  510. iterations: 1
  511. });
  512. setTimeout(function()
  513. {
  514. if(lastClicked === om)
  515. {
  516. lastClicked = null;
  517. }
  518. camera.setAttribute("ocupat", "0");
  519. document.getElementById("container_joc").removeChild(om);
  520. sumaInceput += 20;
  521. document.getElementById("div_suma").innerHTML = "Suma bani(Money): " + sumaInceput;
  522. }, 3000)
  523. }
  524. }
  525.  
  526. function test_coliziune(top1,left1,h1,w1,top2,left2,h2,w2)
  527. {
  528. if(left1< left2+ w2 &&
  529. left1+ w1> left2 &&
  530. top1 < top2 + h2 &&
  531. top1 + h1 > top2) {
  532. return true;
  533. }
  534. }
  535.  
  536. spawneaza_om = function(L)
  537. {
  538. /*var imagine_om = L.getImagine("om");
  539. var aux = document.createElement("img");
  540. aux.src = imagine_om.src;
  541. aux.style.width = imagine_om.w+"px";
  542. aux.style.height = imagine_om.h+"px";
  543. aux.style.position = "absolute";
  544. var i;
  545. var sw = true;
  546. for(i=0; i<12; i++)
  547. if(locuri[i] == false)
  548. {
  549. if(i < 6)
  550. {
  551. aux.style.left = ((100 * i) + 90 * i) + 55 + "px";
  552. aux.style.top = "650px";
  553. document.getElementById("container_joc").appendChild(aux);
  554. locuri[i] = true;
  555. sw = false;
  556. break;
  557. }
  558. else
  559. {
  560. aux.style.left = ((100 * (i-6)) + 90 * (i-6)) + 55 + "px";
  561. aux.style.top = "750px";
  562. document.getElementById("container_joc").appendChild(aux);
  563. locuri[i] = true;
  564. sw = false;
  565. break;
  566. }
  567. }
  568. if(sw == true)
  569. {
  570. nr_vieti--;
  571. document.getElementById("div_nr_vieti").innerHTML = "Numar vieti(Health Points): " + nr_vieti;
  572. if(nr_vieti == 0)
  573. gameOver(L);
  574. }*/
  575. var ecran = document.getElementById("container_joc");
  576. var div_om = document.createElement("div");
  577. div_om.style.position = "absolute";
  578. div_om.className = "div_om";
  579. div_om.style.height = "90px";
  580. div_om.style.width = "90px";
  581. var imagine_om = L.getImagine("om");
  582. var aux = document.createElement("img");
  583. aux.src = imagine_om.src;
  584. aux.style.width = imagine_om.w+"px";
  585. aux.style.height = imagine_om.h+"px";
  586. //aux.style.position = "absolute";
  587. //imagine_om.style.position = "absolute";
  588. var i;
  589. var sw = true;
  590. for(i=0; i<12; i++)
  591. if(locuri[i] == false)
  592. {
  593. var div_par = document.createElement("div");
  594. div_par.style.position = "relative";
  595. div_par.style.width = "80px";
  596. div_par.style.height = "30px";
  597. div_par.style.left = "5px";
  598. div_par.style.top = "-100px";
  599. //div_par.className = "div_par" + i;
  600. div_par.style.backgroundColor = "#E0E0E0";
  601. div_om.appendChild(aux);
  602. div_om.id = i;
  603. div_om.style.backgroundColor = "transparent";
  604. div_om.appendChild(div_par);
  605. var nr_culori = rand(1, 3);
  606. if(nr_culori == 1)
  607. {
  608. var culoare1 = rand(1, 3);
  609. if(culoare1 == 1)
  610. {
  611. var div_culoare = document.createElement("div");
  612. div_culoare.style.width = "20px";
  613. div_culoare.style.height = "30px";
  614. div_culoare.style.marginLeft = "95px";
  615. div_culoare.style.top = "-120px";
  616. div_culoare.className = "culoare";
  617. div_culoare.style.backgroundColor = "red";
  618. div_culoare.style.position = "relative";
  619. div_om.appendChild(div_culoare);
  620. }
  621. else if(culoare1 == 2)
  622. {
  623. var div_culoare = document.createElement("div");
  624. div_culoare.style.width = "20px";
  625. div_culoare.style.height = "30px";
  626. div_culoare.style.marginLeft = "95px";
  627. div_culoare.style.top = "-120px";
  628. div_culoare.className = "culoare";
  629. div_culoare.style.backgroundColor = "green";
  630. div_culoare.style.position = "relative";
  631. div_om.appendChild(div_culoare);
  632. }
  633. else
  634. {
  635. var div_culoare = document.createElement("div");
  636. div_culoare.style.width = "20px";
  637. div_culoare.style.height = "30px";
  638. div_culoare.style.marginLeft = "95px";
  639. div_culoare.style.top = "-120px";
  640. div_culoare.className = "culoare";
  641. div_culoare.style.backgroundColor = "blue";
  642. div_culoare.style.position = "relative";
  643. div_om.appendChild(div_culoare);
  644. }
  645. }
  646. else if(nr_culori == 2)
  647. {
  648. var culoare1 = rand(1, 3);
  649. var culoare2 = rand(1, 3);
  650. while(culoare2 == culoare1)
  651. culoare2 = rand(1,3);
  652. if((culoare1 == 1 && culoare2 == 2) || (culoare1 == 2 && culoare2 == 1))
  653. {
  654. var div_culoare = document.createElement("div");
  655. div_culoare.style.width = "20px";
  656. div_culoare.style.height = "30px";
  657. div_culoare.style.marginLeft = "95px";
  658. div_culoare.style.top = "-120px";
  659. div_culoare.className = "culoare";
  660. div_culoare.style.position = "relative";
  661. div_culoare.style.backgroundColor = "red";
  662. div_om.appendChild(div_culoare);
  663.  
  664. div_culoare = document.createElement("div");
  665. div_culoare.style.width = "20px";
  666. div_culoare.style.height = "30px";
  667. div_culoare.style.marginLeft = "95px";
  668. div_culoare.style.top = "-120px";
  669. div_culoare.className = "culoare";
  670. div_culoare.style.position = "relative";
  671. div_culoare.style.backgroundColor = "green";
  672. div_om.appendChild(div_culoare);
  673. }
  674. else if((culoare1 == 1 && culoare2 == 3) || (culoare1 == 3 && culoare2 == 1))
  675. {
  676. var div_culoare = document.createElement("div");
  677. div_culoare.style.width = "20px";
  678. div_culoare.style.height = "30px";
  679. div_culoare.style.marginLeft = "95px";
  680. div_culoare.style.top = "-120px";
  681. div_culoare.className = "culoare";
  682. div_culoare.style.position = "relative";
  683. div_culoare.style.backgroundColor = "red";
  684. div_om.appendChild(div_culoare);
  685.  
  686. div_culoare = document.createElement("div");
  687. div_culoare.style.width = "20px";
  688. div_culoare.style.height = "30px";
  689. div_culoare.style.marginLeft = "95px";
  690. div_culoare.style.top = "-120px";
  691. div_culoare.className = "culoare";
  692. div_culoare.style.position = "relative";
  693. div_culoare.style.backgroundColor = "blue";
  694. div_om.appendChild(div_culoare);
  695. }
  696. else
  697. {
  698. var div_culoare = document.createElement("div");
  699. div_culoare.style.width = "20px";
  700. div_culoare.style.height = "30px";
  701. div_culoare.style.marginLeft = "95px";
  702. div_culoare.style.top = "-120px";
  703. div_culoare.className = "culoare";
  704. div_culoare.style.position = "relative";
  705. div_culoare.style.backgroundColor = "green";
  706. div_om.appendChild(div_culoare);
  707.  
  708. div_culoare = document.createElement("div");
  709. div_culoare.style.width = "20px";
  710. div_culoare.style.height = "30px";
  711. div_culoare.style.marginLeft = "95px";
  712. div_culoare.style.top = "-120px";
  713. div_culoare.className = "culoare";
  714. div_culoare.style.position = "relative";
  715. div_culoare.style.backgroundColor = "blue";
  716. div_om.appendChild(div_culoare);
  717. }
  718. }
  719. else
  720. {
  721. var div_culoare = document.createElement("div");
  722. div_culoare.style.width = "20px";
  723. div_culoare.style.height = "30px";
  724. div_culoare.style.marginLeft = "95px";
  725. div_culoare.style.top = "-120px";
  726. div_culoare.className = "culoare";
  727. div_culoare.style.position = "relative";
  728. div_culoare.style.backgroundColor = "red";
  729. div_om.appendChild(div_culoare);
  730.  
  731. var div_culoare = document.createElement("div");
  732. div_culoare.style.width = "20px";
  733. div_culoare.style.height = "30px";
  734. div_culoare.style.marginLeft = "95px";
  735. div_culoare.style.top = "-120px";
  736. div_culoare.className = "culoare";
  737. div_culoare.style.position = "relative";
  738. div_culoare.style.backgroundColor = "green";
  739. div_om.appendChild(div_culoare);
  740.  
  741. div_culoare = document.createElement("div");
  742. div_culoare.style.width = "20px";
  743. div_culoare.style.height = "30px";
  744. div_culoare.style.marginLeft = "95px";
  745. div_culoare.style.top = "-120px";
  746. div_culoare.className = "culoare";
  747. div_culoare.style.position = "relative";
  748. div_culoare.style.backgroundColor = "blue";
  749. div_om.appendChild(div_culoare);
  750. }
  751. div_om.onclick = function(e)
  752. {
  753. if(lastClicked == this)
  754. {
  755. lastClicked = null;
  756. this.style.backgroundColor = "transparent";
  757. }
  758. else
  759. {
  760. if(lastClicked != null)
  761. lastClicked.style.backgroundColor = "transparent";
  762. lastClicked = this;
  763. lastClicked.setAttribute("in_miscare", "0");
  764. this.style.backgroundColor = "yellow";
  765. }
  766. }
  767. if(i < 6)
  768. {
  769. div_om.style.left = ((100 * i) + 90 * i) + 55 + "px";
  770. div_om.style.top = "635px";
  771. document.getElementById("container_joc").appendChild(div_om);
  772. locuri[i] = true;
  773. sw = false;
  774. break;
  775. }
  776. else
  777. {
  778. div_om.style.left = ((100 * (i-6)) + 90 * (i-6)) + 55 + "px";
  779. div_om.style.top = "765px";
  780. document.getElementById("container_joc").appendChild(div_om);
  781. locuri[i] = true;
  782. sw = false;
  783. break;
  784. }
  785. }
  786. if(sw == true)
  787. {
  788. nr_vieti--;
  789. document.getElementById("div_nr_vieti").innerHTML = "Numar vieti(Health Points): " + nr_vieti;
  790. if(nr_vieti == 0)
  791. gameOver(L);
  792. }
  793. }
  794.  
  795. gameOver = function(L)
  796. {
  797. clearInterval(interval_om);
  798. clearTimeout(interval_timp);
  799. localStorage.setItem("highScore", Math.floor(timp/60));
  800. L.getSunet("game_over").play();
  801. alert("Ai pierdut.");
  802. location.reload();
  803. /*var mesaj_sfarsit = L.getMesaj("pierdut");
  804. mesaj_sfarsit.style.position = absolute;
  805. mesaj_sfarsit.style.left = "400px";
  806. mesaj_sfarsit.style.top = "500px";
  807. document.getElementById("container_joc").appendChild(mesaj_sfarsit);*/
  808. }
  809.  
  810. preluare_date = function()
  811. {
  812. var aux = document.getElementById("limba");
  813. limba = aux.options[aux.selectedIndex].value;
  814.  
  815. if(document.getElementById("r1").checked == true)
  816. nivelSelectat = document.getElementById("r1").value;
  817. else if(document.getElementById("r2").checked == true)
  818. nivelSelectat = document.getElementById("r1").value;
  819.  
  820. sumaInceput = parseInt(document.getElementById("suma_inceput").value);
  821.  
  822. var regexp = /^[0-9]+([,.][0-9]+)?$/g;
  823. if(document.getElementById("scor_propus").value == "" || regexp.test(document.getElementById("scor_propus").value) != true)
  824. {
  825. alert("Introdu scorul propus(doar cifre)");
  826. return ;
  827. }
  828.  
  829. if(document.getElementById("scor_propus").value == "")
  830. {
  831. alert("Introdu scorul propus");
  832. return ;
  833. }
  834. scorPropus = parseInt(document.getElementById("scor_propus").value);
  835.  
  836. numeSalon = document.getElementById("nume_salon").value;
  837. if(numeSalon.length == 0 || numeSalon.length >20)
  838. {
  839. alert("Introdu numele salonului(maxim 20 caractere)");
  840. return ;
  841. }
  842.  
  843. if(localStorage.getItem("highScore") === null)
  844. highScore = 0;
  845. else
  846. highScore = localStorage.getItem("highScore");
  847.  
  848. var L = new loader();
  849. L.parseResources();
  850.  
  851. var J = new Joc();
  852.  
  853. setTimeout(function()
  854. {
  855. if(x == 0)
  856. {
  857. J.init(L);
  858. }
  859. }, 100);
  860. }
  861.  
  862. window.onload = function()
  863. {
  864. document.getElementById("container_joc").style.display= "none";
  865. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement