Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Jak coś takiego zrobic
Forum PHP.pl > Forum > Przedszkole
wolacinio
witam
Jak zrobić skrypt taki sam jak na tej stronie

http://wykrywarka.pl/

tzn. ze wybieram liczby po czym daje losuj i losuje mi byle jakie liczby
jak mozna to prosze o link do skryptu a jak nie dostane to prosze teoretycznie jak napisac taki skrypt

Pozdrawiam
MateuszS
nic trudnego, podpowiem

Robisz x liczbe input buttonow (gdzie x to liczba tych kolek z numerkami ;]), dajesz im value="" onClick="this.value="numer" gdzie numer to numer tego kółeczka, potem przesyłasz POSTem formularz, losujesz funkcją rand 6 liczb z konkretnego przedziału i sprawdzasz w pętli czy przesłane (wybrane) się zgadzają z wylosowanymi. Trochę zabawy z pętlami i tablicami ;]
wolacinio
  1.  
  2. <?php
  3.  
  4.  
  5. $losuj = rand(0,49);
  6.  
  7. echo $losuj;
  8.  
  9. if($_GET['nr'] == $losuj){
  10.  
  11. echo '<h1>wygrana</h1>';
  12. }else{echo 'przegrana';}
  13.  
  14. ?>
  15.  



napisałem coś takiego ? ;D


nie zrozumiałem tego ''...losujesz funkcją rand 6 liczb z konkretnego przedziału...''
MateuszS
No zastosowałeś to co mówiłem,

troche zmienilem koncepcje, rozpracuj ten kod i dopisz sobie odpowiednie sprawdzanie w PHP mi sie chce spac juz,

  1. <script type="text/javascript">
  2. var booyakasha;
  3. var lp=0;
  4. var checkItOut=0;
  5. var canBeChecked=6;
  6. function add(value)
  7. {
  8. if(checkItOut==canBeChecked) {
  9. alert("Wiecej nie mozesz zaznaczyc");
  10. return false;
  11. } else {
  12. var hidd = document.getElementById("hidd").value;
  13. if(lp==0) {
  14. booyakasha = value;
  15. } else {
  16. booyakasha = booyakasha + "," + value;
  17. }
  18. lp++;
  19. hidd = booyakasha;
  20. checkItOut++;
  21. return true;
  22. }
  23.  
  24. }
  25.  
  26. </script>
  27.  
  28. <form method="POST" action="">
  29. <?
  30.  
  31. $ilosc = 49;
  32.  
  33. for($i=1; $i<=$ilosc; $i++) {
  34. if($i%8==0)
  35. echo "<br />";
  36. echo '<input type="button" name="but1" value="'.$i.'" onClick="if(add('.$i.')==true) this.style.background = \'lime\'" />';
  37. }
  38.  
  39. ?>
  40.  
  41. <input type="hidden" id="hidd" value="" name="wartosci" />
  42. </form>
wolacinio
no tak,to bym moze zrobił ale chodziło mi o sprawdzenia
bo jak za kazdym razem bede sprawdzał czy wybrana liczba jest równa wylosowanej i tu kodu bedzie ;/

zaprojektuj jeszcze raz to sprawdzenie liczby tylko tak prosto ;D i daje ci spokoj
Klycior
Może się przyda:

  1. <?php
  2.  
  3. if(!isSet($_POST['i'][0]) || !isSet($_POST['i'][1]) || !isSet($_POST['i'][2]) || !isSet($_POST['i'][3]) ||
  4. !isSet($_POST['i'][4]) || !isSet($_POST['i'][5]) || isSet($_POST['i'][6]) || isSet($_POST['i'][7])
  5. || isSet($_POST['i'][7]) || isSet($_POST['i'][8]) || isSet($_POST['i'][9]) || isSet($_POST['i'][10])
  6. || isSet($_POST['i'][11]) || isSet($_POST['i'][12]) || isSet($_POST['i'][13]) || isSet($_POST['i'][14])
  7. || isSet($_POST['i'][15]) || isSet($_POST['i'][16]) || isSet($_POST['i'][17]) || isSet($_POST['i'][18])
  8. || isSet($_POST['i'][19]) || isSet($_POST['i'][20]) || isSet($_POST['i'][21]) || isSet($_POST['i'][22])
  9. || isSet($_POST['i'][23]) || isSet($_POST['i'][24]) || isSet($_POST['i'][25]) || isSet($_POST['i'][26])
  10. || isSet($_POST['i'][27]) || isSet($_POST['i'][28]) || isSet($_POST['i'][29]) || isSet($_POST['i'][30])
  11. || isSet($_POST['i'][31]) || isSet($_POST['i'][32]) || isSet($_POST['i'][33]) || isSet($_POST['i'][34])
  12. || isSet($_POST['i'][35]) || isSet($_POST['i'][36]) || isSet($_POST['i'][37]) || isSet($_POST['i'][38])
  13. || isSet($_POST['i'][39]) || isSet($_POST['i'][40]) || isSet($_POST['i'][41]) || isSet($_POST['i'][42])
  14. || isSet($_POST['i'][43]) || isSet($_POST['i'][44]) || isSet($_POST['i'][45]) || isSet($_POST['i'][46])
  15. || isSet($_POST['i'][47]) || isSet($_POST['i'][48])){
  16. $komunikat2 = "Nie znasz zasad! Aby wziąść udział w losowaniu musisz wytypować 6 liczb!<br /><a href='java script:history.go(-1)'>powrót</a>";
  17. }
  18. else {
  19. $g[1] = rand(1,49);
  20. $g[2] = rand(1,49);
  21. $g[3] = rand(1,49);
  22. $g[4] = rand(1,49);
  23. $g[5] = rand(1,49);
  24. $g[6] = rand(1,49);
  25. if($g[1] == $g[2] || $g[1] == $g[3] || $g[1] == $g[4] || $g[1] == $g[5] || $g[1] == $g[6] ||
  26. $g[2] == $g[1] || $g[2] == $g[3] || $g[2] == $g[4] || $g[2] == $g[5] || $g[2] == $g[6] ||
  27. $g[3] == $g[1] || $g[3] == $g[2] || $g[3] == $g[4] || $g[3] == $g[5] || $g[3] == $g[6] ||
  28. $g[4] == $g[1] || $g[4] == $g[2] || $g[4] == $g[3] || $g[4] == $g[5] || $g[4] == $g[6] ||
  29. $g[5] == $g[1] || $g[5] == $g[2] || $g[5] == $g[3] || $g[5] == $g[4] || $g[5] == $g[6] ||
  30. $g[6] == $g[1] || $g[6] == $g[2] || $g[6] == $g[3] || $g[6] == $g[4] || $g[6] == $g[5]){
  31. while($g[1] == $g[2] || $g[1] == $g[3] || $g[1] == $g[4] || $g[1] == $g[5] || $g[1] == $g[6] ||
  32. $g[2] == $g[1] || $g[2] == $g[3] || $g[2] == $g[4] || $g[2] == $g[5] || $g[2] == $g[6] ||
  33. $g[3] == $g[1] || $g[3] == $g[2] || $g[3] == $g[4] || $g[3] == $g[5] || $g[3] == $g[6] ||
  34. $g[4] == $g[1] || $g[4] == $g[2] || $g[4] == $g[3] || $g[4] == $g[5] || $g[4] == $g[6] ||
  35. $g[5] == $g[1] || $g[5] == $g[2] || $g[5] == $g[3] || $g[5] == $g[4] || $g[5] == $g[6] ||
  36. $g[6] == $g[1] || $g[6] == $g[2] || $g[6] == $g[3] || $g[6] == $g[4] || $g[6] == $g[5]){
  37. $g[1] = rand(1,49);
  38. $g[2] = rand(1,49);
  39. $g[3] = rand(1,49);
  40. $g[4] = rand(1,49);
  41. $g[5] = rand(1,49);
  42. $g[6] = rand(1,49);
  43. }
  44. }
  45.  
  46. $u[1] = (int)round($_POST['i'][0], 0);
  47. $u[2] = (int)round($_POST['i'][1], 0);
  48. $u[3] = (int)round($_POST['i'][2], 0);
  49. $u[4] = (int)round($_POST['i'][3], 0);
  50. $u[5] = (int)round($_POST['i'][4], 0);
  51. $u[6] = (int)round($_POST['i'][5], 0);
  52.  
  53. $trafione = 0;
  54. for($k=1; $k <= 6; $k++){
  55. for($j=1; $j <= 6; $j++){
  56. if($g[$k] == $u[$j]){
  57. $trafione++;
  58. }
  59. }
  60. }
  61. if($trafione == 6){
  62. $wygrana = $kumulacja[0];
  63. $kasa = $wygrana + $kierowca['kasa'];
  64. $komunikat = "Gratulacje. Trafiłeś wszystkie liczby! Otrzymujesz nagrodę główną w wysokości ".$wygrana." zł !";
  65. }
  66. else if($trafione == 5){
  67. $wygrana = $kumulacja[0] * 0.1;
  68. $wygrana = round($wygrana, '0');
  69. $kasa = $wygrana + $kierowca['kasa'];
  70. $komunikat = "Było naprawdę blisko. Trafiłeś pięć liczb. Wygrywasz ".$wygrana." zł";
  71. else if($trafione == 4){
  72. $wygrana = $kumulacja[0] * 0.02;
  73. $wygrana = round($wygrana, '0');
  74. $kasa = $wygrana + $kierowca['kasa'];
  75. $komunikat = "Jeszcze troche brakuje. Trafiłeś cztery liczby i wygrywasz ".$wygrana." zł";
  76. }
  77. else if($trafione == 3){
  78. $wygrana = $kumulacja[0] * 0.0001;
  79. $wygrana = round($wygrana, '0');
  80. $kasa = $wygrana + $kierowca['kasa'];
  81. $komunikat = "Trafiłeś trzy liczby i wygrywasz ".$wygrana." zł";
  82. }
  83. else if($trafione == 2){
  84. $komunikat = "Trafiłeś dwie liczby. Spróbuj ponownie";
  85. }
  86. else if($trafione == 1){
  87. $komunikat = "Trafiłeś jedną liczbę. Spróbuj ponownie";
  88. }
  89. else if($trafione == 0){
  90. $komunikat = "Nic nie trafiłeś. Spróbuj ponownie";
  91. }
  92. }
  93. }
  94. }
  95.  
  96. if(isSet($komunikat)){
  97. echo "Wylosowane liczby to: ".$g[1]." ".$g[2]." ".$g[3]." ".$g[4]." ".$g[5]." ".$g[6]."<br />
  98. Twoje liczby to: ".$u[1]." ".$u[2]." ".$u[3]." ".$u[4]." ".$u[5]." ".$u[6]."<br /><br />";
  99. echo $komunikat;
  100. }
  101. else if(isSet($komunikat2)){
  102. echo $komunikat2;
  103. }
  104. else{
  105. ?>
  106. <form name="lotekk" action="lotek.php" method="post">
  107. <table>
  108. <tr>
  109. <td><input type="checkbox" name="i[]" value="1" />1</td>
  110. <td><input type="checkbox" name="i[]" value="2" />2</td>
  111. <td><input type="checkbox" name="i[]" value="3" />3</td>
  112. <td><input type="checkbox" name="i[]" value="4" />4</td>
  113. <td><input type="checkbox" name="i[]" value="5" />5</td>
  114. <td><input type="checkbox" name="i[]" value="6" />6</td>
  115. <td><input type="checkbox" name="i[]" value="7" />7</td>
  116. <td><input type="checkbox" name="i[]" value="8" />8</td>
  117. <td><input type="checkbox" name="i[]" value="9" />9</td>
  118. <td><input type="checkbox" name="i[]" value="10" />10</td>
  119. </tr>
  120. <tr>
  121. <td><input type="checkbox" name="i[]" value="11" />11</td>
  122. <td><input type="checkbox" name="i[]" value="12" />12</td>
  123. <td><input type="checkbox" name="i[]" value="13" />13</td>
  124. <td><input type="checkbox" name="i[]" value="14" />14</td>
  125. <td><input type="checkbox" name="i[]" value="15" />15</td>
  126. <td><input type="checkbox" name="i[]" value="16" />16</td>
  127. <td><input type="checkbox" name="i[]" value="17" />17</td>
  128. <td><input type="checkbox" name="i[]" value="18" />18</td>
  129. <td><input type="checkbox" name="i[]" value="19" />19</td>
  130. <td><input type="checkbox" name="i[]" value="20" />20</td>
  131. </tr>
  132. <tr>
  133. <td><input type="checkbox" name="i[]" value="21" />21</td>
  134. <td><input type="checkbox" name="i[]" value="22" />22</td>
  135. <td><input type="checkbox" name="i[]" value="23" />23</td>
  136. <td><input type="checkbox" name="i[]" value="24" />24</td>
  137. <td><input type="checkbox" name="i[]" value="25" />25</td>
  138. <td><input type="checkbox" name="i[]" value="26" />26</td>
  139. <td><input type="checkbox" name="i[]" value="27" />27</td>
  140. <td><input type="checkbox" name="i[]" value="28" />28</td>
  141. <td><input type="checkbox" name="i[]" value="29" />29</td>
  142. <td><input type="checkbox" name="i[]" value="30" />30</td>
  143. </tr>
  144. <tr>
  145. <td><input type="checkbox" name="i[]" value="31" />31</td>
  146. <td><input type="checkbox" name="i[]" value="32" />32</td>
  147. <td><input type="checkbox" name="i[]" value="33" />33</td>
  148. <td><input type="checkbox" name="i[]" value="34" />34</td>
  149. <td><input type="checkbox" name="i[]" value="35" />35</td>
  150. <td><input type="checkbox" name="i[]" value="36" />36</td>
  151. <td><input type="checkbox" name="i[]" value="37" />37</td>
  152. <td><input type="checkbox" name="i[]" value="38" />38</td>
  153. <td><input type="checkbox" name="i[]" value="39" />39</td>
  154. <td><input type="checkbox" name="i[]" value="40" />40</td>
  155. </tr>
  156. <tr>
  157. <td><input type="checkbox" name="i[]" value="41" />41</td>
  158. <td><input type="checkbox" name="i[]" value="42" />42</td>
  159. <td><input type="checkbox" name="i[]" value="43" />43</td>
  160. <td><input type="checkbox" name="i[]" value="44" />44</td>
  161. <td><input type="checkbox" name="i[]" value="45" />45</td>
  162. <td><input type="checkbox" name="i[]" value="46" />46</td>
  163. <td><input type="checkbox" name="i[]" value="47" />47</td>
  164. <td><input type="checkbox" name="i[]" value="48" />48</td>
  165. <td><input type="checkbox" name="i[]" value="49" />49</td>
  166. <td> </td>
  167. </tr>
  168. <tr>
  169. <td colspan="10" align="right" /><input type="submit" name="start" value="rozpocznij losowanie" /></td>
  170. </tr>
  171. </table>
  172. </form>
  173. <?php
  174. }
  175. ?>


wolacinio
sa błedy reperuje je ale nic ;/

dobra poradziłem sobie ;] posklejałem,pogłówkować
dzieki wielkie
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.