home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 July / Chip_2003-07_cd1.bin / internet / lufiweb / myweb / programy / hry / logik / logik.js < prev    next >
Encoding:
Text File  |  2003-02-26  |  11.2 KB  |  594 lines

  1. //<SCRIPT Language="JavaScript">
  2.       ie4 = document.all?1:0
  3.         ns4 = document.layers?1:0
  4.         ns6 = document.getElementById&&!document.all?1:0
  5.   
  6. var barvy=new Array(
  7. '#ff0000',
  8. '#ff972f',
  9. '#ffff00',
  10. '#00ff00',
  11. '#13ffff',
  12. '#0000ff',
  13. '#c400c4',
  14. '#feb8d9'
  15. );
  16. var barvyns=new Array(
  17. '255,0,0',
  18. '255,151,47',
  19. '255,255,0',
  20. '0,255,0',
  21. '19,255,255',
  22. '0,0,255',
  23. '196,0,196',
  24. '254,184,217'
  25. );
  26.  
  27. var kod=new Array(
  28. 'cervena',
  29. 'oranzova',
  30. 'zluta',
  31. 'zelena',
  32. 'cyanova',
  33. 'modra',
  34. 'fialova',
  35. 'ruzova'
  36. )
  37. var barva_ctverce="#ffc891";
  38. var zasah="#ffff11"
  39. var pul_zasah="#4d4dff"
  40.  
  41. var barva_ctvercens="255,200,145";
  42. var zasahns="255,255,17"
  43. var pul_zasahns="212,212,255";
  44. var 
  45. ok=1;vzdat=0;
  46. pocet_zadanych=0;
  47. pocet_sloupcu=6;
  48. pocet_radku=15;
  49. pocet_barev=8;
  50. var pozastav=1;
  51.  
  52. sestava=new Array();
  53. random.m=714025;
  54. random.a=4096;
  55. random.c=150889;
  56. random.seed=(new Date()).getTime() % random.m;
  57. nazbar=new Array();
  58. nazbar[1]=0;
  59. nazbar[2]=1;
  60. nazbar[3]=2;
  61. nazbar[4]=3;
  62. nazbar[5]=4;
  63. nazbar[6]=5;
  64. nazbar[7]=6;
  65. nazbar[8]=7;
  66.  
  67. vb=new Array();
  68.  
  69. function Init()
  70. {
  71. if(ok)
  72. {pozastav=1;
  73. vb[1]='';
  74. vb[2]='';
  75. vb[3]='';
  76. vb[4]='';
  77. vb[5]='';
  78. vb[6]='';
  79. sestava[1]='';
  80. sestava[2]='';
  81. sestava[3]='';
  82. sestava[4]='';
  83. sestava[5]='';
  84. sestava[6]='';
  85. vpole=0;
  86. t=0;
  87. r=0;
  88. s=0;
  89. ok=0;
  90. asipka=1;
  91. ps=0;pb=0;
  92. VyberSestavu();
  93. RF();
  94. }
  95. pozastav=0;
  96. }
  97. function InitA()
  98. {if(!pozastav)
  99. {pozastav=1;
  100. if(vzdat)
  101. {for(i=1;i<pocet_sloupcu+1;i++) 
  102. for(j=1;j<pocet_radku+1;j++)
  103.     {
  104.     if(ns6==1)
  105.         {
  106.         document.getElementById('b'+DejPismeno(j)+i).style.background="black";
  107.         document.getElementById('v'+DejPismeno(j)+i).style.background="black";
  108.         }
  109.     else
  110.         {
  111.         document.all.item('b'+DejPismeno(j)+i).style.background="";
  112.         document.all.item('v'+DejPismeno(j)+i).style.background="";
  113.         }
  114.     if(i==1) 
  115.     if(ns6==1)
  116.         {
  117.         document.getElementById('s'+j).style.background="black";
  118.         }
  119.     else
  120.         {
  121.         document.all.item('s'+j).style.background="";
  122.         }
  123.     }
  124. for(i=1;i<pocet_sloupcu+1;i++) 
  125.  if(ns6==1)
  126.      {
  127.      document.getElementById('l'+i).style.background="black";
  128.      }
  129.  else
  130.      {
  131.      document.all.item('l'+i).style.background="";
  132.      }
  133. }
  134.  
  135. if(ns6==1)
  136. {
  137. document.getElementById('s1').style.background = "#ff0000";
  138. }
  139. else
  140. {
  141. document.all.item('s1').style.background = "#ff0000";
  142. }
  143.  
  144. vzdat=0;
  145. RF();
  146. asipka=pocet_radku;
  147. Storno();
  148. asipka=1;
  149. }
  150. pozastav=0;
  151. Aktiv('NH','',0);
  152. }
  153.  
  154. function random()
  155. {
  156. random.seed=(random.seed*random.a+random.c) % random.m;
  157. return random.seed/random.m;
  158. }
  159.  
  160.  
  161. function NovaBarva(cislo,i)
  162. {if(i!=1)
  163. for(j=1;j<i;j++)
  164.  {if(sestava[j]==nazbar[cislo]) return 0; }
  165. return 1; 
  166. }
  167.  
  168. function VyberSestavu()
  169. {
  170. for(i=1;i<pocet_sloupcu+1;i++)
  171.  {
  172.  do 
  173. cislo=Math.ceil(random()*pocet_barev); 
  174.  while(!NovaBarva(cislo,i));
  175.  sestava[i]=nazbar[cislo];
  176.   }
  177. //alert(sestava[1]+''+sestava[2]+''+sestava[3]+''+sestava[4]+''+sestava[5]+''+sestava[6]);
  178. }
  179.  
  180. function VyberPole(radek,sloupec)
  181. {if(!pozastav)
  182. {
  183. for(i=1;i<pocet_sloupcu+1;i++)
  184. {
  185. if(ns6==1)
  186.     {
  187.     strng=document.getElementById('b'+DejPismeno(radek)+i).style.background;
  188.     podminka=(strng.indexOf('255,255,255'))!=-1; 
  189.     }
  190. else
  191.     {
  192.     podminka=document.all.item('b'+DejPismeno(radek)+i).style.background=="#ffffff" ;
  193.     }
  194. if(podminka)
  195.     {
  196.     if(ns6==1)
  197.         {
  198.         document.getElementById('b'+DejPismeno(radek)+i).style.background = "black";
  199.         }
  200.     else
  201.         {
  202.         document.all.item('b'+DejPismeno(radek)+i).style.background = "";
  203.         }
  204.     }
  205. }    
  206. if(ns6==1)
  207.     {
  208.     document.getElementById('b'+DejPismeno(radek)+sloupec).style.background = "#ffffff";
  209.     }
  210. else
  211.     {
  212.     document.all.item('b'+DejPismeno(radek)+sloupec).style.background = "#ffffff";
  213.     } 
  214. vpole=1;
  215. r=radek;
  216. s=sloupec;
  217. }
  218. }
  219. function OdznacPole(radek,sloupec)
  220. {if(!pozastav)
  221. {
  222. if(ns6==1)
  223.   {
  224.     document.getElementById('b'+DejPismeno(radek)+sloupec).style.background = "black";
  225.     }
  226. else
  227.     {
  228.     document.all.item('b'+DejPismeno(radek)+sloupec).style.background = "";
  229.     } 
  230. vpole=0;
  231. r=0;
  232. s=0;
  233. }
  234. }
  235. function TestBarev(clik)
  236. {
  237. for (i=1;i<pocet_sloupcu+1;i++)
  238. if(s!=i)
  239. {
  240.     if(ns6==1)
  241.     {
  242.     b=document.getElementById('b'+DejPismeno(r)+i).style.background;
  243.     }
  244. else
  245.     {
  246.     b=document.all.item('b'+DejPismeno(r)+i).style.background;
  247.     }
  248. if(ns6==1)
  249. {
  250. a=barvyns[clik];
  251. podminka=(b.indexOf(a))!=-1; 
  252. }
  253. else
  254. {
  255. a=barvy[clik];
  256. podminka=(b==a);
  257. }
  258. if(podminka)  {return 0 ; }
  259. }
  260. return 1;
  261. }
  262.  
  263. function Zmena(j,i)
  264. {
  265. if(!pozastav)
  266. if(!ok)
  267. if(j<=asipka)
  268.     {
  269.   if(ns6==1)
  270.         {
  271.         strng=document.getElementById('o'+DejPismeno(j)+i).style.background;
  272.     //    alert(strng+' '+barva_ctvercens);
  273.         podminka=(strng.indexOf(barva_ctvercens))!=-1; 
  274.         }
  275.     else
  276.         {
  277.         podminka=document.all.item('o'+DejPismeno(j)+i).style.background==barva_ctverce;
  278.         }
  279.     if(podminka)
  280.     {
  281.     if(ns6==1)
  282.         {
  283.         document.getElementById('o'+DejPismeno(j)+i).style.background="black";
  284.         }
  285.     else
  286.         {
  287.         document.all.item('o'+DejPismeno(j)+i).style.background="";
  288.         }
  289.     } 
  290.     else 
  291.     {
  292.     if(ns6==1)
  293.     {
  294.     document.getElementById('o'+DejPismeno(j)+i).style.background=barva_ctverce;
  295.     }
  296.     else
  297.     {
  298.     document.all.item('o'+DejPismeno(j)+i).style.background=barva_ctverce;
  299.     }
  300.     }
  301. }    
  302. }
  303. function PoleT(radek,sloupec)
  304. {if(!pozastav)
  305. {if (!ok)
  306. if(asipka==radek)
  307. {//var s=new String();
  308.  
  309.  if(ns6==1)
  310.  {
  311.  s=document.getElementById('b'+DejPismeno(radek)+sloupec).style.background;
  312.  podminka=s.indexOf('255,255,255')!=-1;
  313.  }
  314.  else
  315.  {
  316.  s=document.all.item('b'+DejPismeno(radek)+sloupec).style.background;
  317.  podminka=(s=='#ffffff');
  318.  }
  319.  if(podminka) {OdznacPole(radek,sloupec); } else {VyberPole(radek,sloupec);t=1;}
  320. } else
  321. {if(radek<asipka) {Zmena(radek,sloupec)}}
  322. }
  323. }
  324. function Storno()
  325. {pozastav=1;
  326. if(!ok)
  327. for(j=1;j<asipka+1;j++)
  328. for(i=1;i<pocet_sloupcu+1;i++)
  329.     {
  330.     if(ns6==1)
  331.     {
  332.     document.getElementById('o'+DejPismeno(j)+i).style.background="black"
  333.     }
  334.     else
  335.     {
  336.     document.all.item('o'+DejPismeno(j)+i).style.background=""
  337.     }
  338.     }
  339. pozastav=0;
  340. }
  341.  
  342. Jmeno=navigator.appName;
  343. function Klik(clik)
  344. {if(!pozastav)
  345. if(!ok)
  346. if(vpole==1)
  347. {if(TestBarev(clik))
  348. {
  349. if(ns6==1)
  350.     {
  351.     document.getElementById('b'+DejPismeno(r)+s).style.background = barvy[clik];
  352.     }
  353. else
  354.     {
  355.     document.all.item('b'+DejPismeno(r)+s).style.background = barvy[clik];
  356.     } 
  357. vpole=0;
  358. vb[s]=clik;
  359. pocet_zadanych=PocZad();
  360.  
  361. }
  362. }
  363. }
  364.  
  365. function PocZad()
  366. {
  367. p=0;
  368. for (i=1;i<pocet_sloupcu+1;i++)
  369. {//var b=new String();
  370.  
  371. if(ns6==1)
  372.     {
  373.     b=document.getElementById('b'+DejPismeno(r)+i).style.background;
  374.     }
  375. else
  376.     {
  377.     b=document.all.item('b'+DejPismeno(r)+i).style.background;
  378.     }
  379. if(/*b.indexOf('bunka')==-1*/b!='')  {p++}
  380. }
  381. return p;
  382. }
  383.  
  384. function Text(ind)
  385. {
  386. {
  387. document.f1.t1.value=""+ind;
  388. document.f2.t2.value=""+ind;
  389. }
  390. }
  391. function RF()
  392. {
  393. document.f1.t1.value="Cφlem hry je sestavit sadu r∙zn²ch barev, kterß je skryta ve spodnφm °ßdku tabulky LOGIKA. K tomu Vßm slou₧φ nßpov∞da zßvislß na postavenφ VaÜich barevn²ch kamen∙. Pokud se trefφte v barv∞ i umφst∞nφ, objevφ se ÄLUT╔ koleΦko. Pokud trefφte pouze barvu, objevφ se MODR╔ koleΦko. Pozice koleΦek NEZ┴VIS═ na pozici barevn²ch kamen∙.V tabulce vlevo m∙₧ete vyznaΦovat pozice kamen∙ a tφm si ulehΦit prßci.";
  394. document.f2.t2.value="OVL┴D┴N═: Klikn∞te na n∞jakΘ polφΦko tabulky LOGIKA, na kterΘ ukazuje Üipka. Pak klikn∞te na barvu v jednΘ ze t°φ sad barevn²ch kamen∙. Pokud jste zaplnili celou °adu a chcete ji vyhodnotit, klikn∞te na  Φervenou Üipku. Pokud jste neodhalili sprßvnou kombinaci, pokraΦujte v dalÜφm °ßdku. Pokud se chcete vzdßt klikn∞te na nabφdku dole. Pokud chcete hrßt novou hru, nejprve se vzdejte a pak klikn∞te na nabφdku dole.";
  395. }
  396. function DejPismeno(cislo)
  397. {
  398. if (cislo==1) return 'B';
  399. if (cislo==2) return 'C';
  400. if (cislo==3) return 'D';
  401. if (cislo==4) return 'E';
  402. if (cislo==5) return 'F';
  403. if (cislo==6) return 'G';
  404. if (cislo==7) return 'H';
  405. if (cislo==8) return 'I';
  406. if (cislo==9) return 'J';
  407. if (cislo==10) return 'K';
  408. if (cislo==11) return 'L';
  409. if (cislo==12) return 'M';
  410. if (cislo==13) return 'N';
  411. if (cislo==14) return 'O';
  412. if (cislo==15) return 'P';
  413. }
  414. function Sipka()
  415. {
  416. if(ns6==1)
  417.     {
  418.     document.getElementById('s'+(asipka-1)).style.background = "black"; 
  419.     document.getElementById('s'+asipka).style.background = "#ff0000";
  420.     }
  421. else
  422.     {
  423.     document.all.item('s'+(asipka-1)).style.background = ""; 
  424.     document.all.item('s'+asipka).style.background = "#ff0000";
  425.     } 
  426. }
  427. function Sipkaa()
  428. {
  429. if(ns6==1)
  430.     {
  431.     document.getElementById('s'+(asipka-1)).style.background = "black";
  432.     }
  433. else
  434.     {
  435.     document.all.item('s'+(asipka-1)).style.background = "";
  436.     } 
  437. }
  438. function DejVysledek(cislo)
  439. {if(!pozastav)
  440. {pozastav=1;
  441. if(!ok)
  442. if(cislo==r)
  443. if(pocet_zadanych==pocet_sloupcu)
  444. {
  445. if(!DejKsichty())
  446.  {ZobrazKsichty();
  447. pocet_zadanych=0;
  448. if(++asipka==pocet_radku+1) {Odkryj(0);} else {Sipka();}
  449.  }else {ZobrazKsichty(); ++asipka; Sipkaa(); Odkryj(0);}
  450. TiskBlafu(ps,pb);
  451. }
  452. }
  453. pozastav=0;
  454. }
  455. function TiskBlafu(zl,mo)
  456. {
  457. //alert('Tisk blafu '+zl+':'+mo);
  458. if(zl==0){
  459. if(mo==4){Text('Zahraj si jinou hru. Tahle nenφ pro tebe.')}
  460. if(mo==5){Text('Dej si studen² obklad.')}
  461. if(mo==6){Text('To ujde.')}
  462. }
  463. if(zl==1){
  464. if(mo==3){Text('Jdi do klßÜtera.')}
  465. if(mo==4){Text('No, nic moc.')}
  466. if(mo==5){Text('To nenφ ÜpatnΘ!')}
  467. }
  468. if(zl==2){
  469. if(mo==2){Text('Dej si pauzu!')}
  470. if(mo==3){Text('P°idej!')}
  471. if(mo==4){Text('To u₧ je lepÜφ.')}
  472. }
  473. if(zl==3){
  474. if(mo==1){Text('Tohle umφm taky!')}
  475. if(mo==2){Text('StaΦφ jen zapnout mozek!')}
  476. if(mo==3){Text('Brilantnφ ·sudek vÜe vy°eÜφ.')}
  477. }
  478. if(zl==4){
  479. if(mo==0){Text('Zamysli se, lenochu.')}
  480. if(mo==1){Text('U₧ to skoro je!')}
  481. if(mo==2){Text('HM! Velmi dobrΘ.')}
  482. }
  483. if(zl==5){
  484. if(mo==0){Text('DOB╪E! JeÜt∞ trochu p°itlaΦ.')}
  485. }
  486. if(zl==6){Text('BRAVO! MßÜ m∙j obdiv!')}
  487. }
  488.  
  489. function ZobrazKsichty()
  490. {
  491. if(ps!=0)
  492. for(i=1;i<ps+1;i++) 
  493.     {
  494.     if(ns6==1)
  495.         {
  496.         document.getElementById('v'+DejPismeno(asipka)+i).style.background = zasah;
  497.         }
  498.     else
  499.         {
  500.         document.all.item('v'+DejPismeno(asipka)+i).style.background = zasah;
  501.         }
  502.     }
  503. if(pb!=0)
  504. for(i=1;i<pb+1;i++) 
  505.     {
  506. if(ns6==1)
  507.     {
  508.     document.getElementById('v'+DejPismeno(asipka)+(i+ps)).style.background = pul_zasah;
  509.     }
  510. else
  511.   {
  512.     document.all.item('v'+DejPismeno(asipka)+(i+ps)).style.background = pul_zasah;
  513.     }
  514.     }
  515.  
  516. }
  517. function DejKsichty()
  518. {ps=0;pb=0;
  519. for(i=1;i<pocet_sloupcu+1;i++)
  520.  {
  521.  if(sestava[i]==vb[i]) {ps++ ; vb[i]='@'; }
  522.   }
  523. if(ps!=6)
  524. for(i=1;i<pocet_sloupcu+1;i++)
  525.  {
  526.   if(JeVSestave(vb[i])) pb++;
  527.  }
  528. if(ps==6) {return 1} else {return 0};
  529.  
  530. }
  531. function JeVSestave(a)
  532. {
  533. for(j=1;j<pocet_sloupcu+1;j++)
  534.  {
  535.  if(sestava[j]==a) return 1;
  536.  }
  537. return 0;
  538. }
  539.  
  540. function Zakryj()
  541. {
  542. for(i=1;i<pocet_sloupcu+1;i++)
  543.     {
  544.     if(ns6==1)
  545.     {
  546.     document.getElementById('l'+i).style.background = "black";
  547.     }
  548.     else
  549.     {
  550.     document.all.item('l'+i).style.background = "";
  551.     }
  552.     } 
  553. }
  554. function Odkryj(w)
  555. {
  556. if(!ok)
  557. if(!vzdat)
  558. {
  559. Aktiv('VZ','',0);
  560. if(w) {Text('NEZOUFEJ a zkus to znovu!')}
  561. for(i=1;i<pocet_sloupcu+1;i++)
  562. {
  563. if(ns6==1)
  564.     {
  565.     document.getElementById('l'+i).style.background = barvy[sestava[i]];
  566.     }
  567. else
  568.     {
  569.     document.all.item('l'+i).style.background = barvy[sestava[i]];
  570.     }
  571. }
  572. ok=1;
  573. vzdat=1;
  574. }
  575. }
  576. function Aktiv(id,ba,pod)
  577. {
  578.  
  579. if(!pod) 
  580.     {
  581.     if(ns6==1)
  582.         {
  583.         if(ba!='')
  584.         document.getElementById(id).style.background=ba;
  585.         else
  586.         document.getElementById(id).style.background='black';
  587.         }
  588.     else
  589.         {
  590.         document.all.item(id).style.background=ba;
  591.         }
  592.     }
  593. }
  594.