login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Korter schrijver

Offline Voldemort - 31/07/2005 16:21
Avatar van VoldemortPHP ver gevorderde
  1. <?php if($_POST['spreuken'] == "Expelliarmus" && ($fetch['duel_level'] == 1 || $fetch['duel_level'] == 2 || $fetch['duel_level'] == 3 || $fetch['duel_level'] == 4 || $fetch['duel_level'] == 5))
  2. {
  3. $afdoen_monster = rand(1,25);
  4. }
  5. elseif($_POST['spreuken'] == "Expelliarmus" && ($fetch['duel_level'] == 6 || $fetch['duel_level'] == 7 || $fetch['duel_level'] == 8 || $fetch['duel_level'] == 9 || $fetch['duel_level'] == 10))
  6. {
  7. $afdoen_monster = rand(25,50);
  8. }
  9. elseif($_POST['spreuken'] == "Expelliarmus" && ($fetch['duel_level'] == 11 || $fetch['duel_level'] == 12 || $fetch['duel_level'] == 13 || $fetch['duel_level'] == 14 || $fetch['duel_level'] == 15))
  10. {
  11. $afdoen_monster = rand(50,200);
  12. }
  13. elseif($_POST['spreuken'] == "Expelliarmus" && ($fetch['duel_level'] == 16 || $fetch['duel_level'] == 17 || $fetch['duel_level'] == 18 || $fetch['duel_level'] == 19 || $fetch['duel_level'] == 20))
  14. {
  15. $afdoen_monster = rand(200,500);
  16. }
  17. elseif($_POST['spreuken'] == "Expelliarmus" && ($fetch['duel_level'] == 21 || $fetch['duel_level'] == 22 || $fetch['duel_level'] == 23 || $fetch['duel_level'] == 24 || $fetch['duel_level'] == 25))
  18. {
  19. $afdoen_monster = rand(500,1000);
  20. }
  21. elseif($_POST['spreuken'] == "Expelliarmus" && ($fetch['duel_level'] == 26 || $fetch['duel_level'] == 27 || $fetch['duel_level'] == 28 || $fetch['duel_level'] == 29 || $fetch['duel_level'] == 20))
  22. {
  23. $afdoen_monster = rand(1000,5000);
  24. }
  25. elseif($_POST['spreuken'] == "Diffindo" && ($fetch['duel_level'] == 1 || $fetch['duel_level'] == 2 || $fetch['duel_level'] == 3 || $fetch['duel_level'] == 4 || $fetch['duel_level'] == 5))
  26. {
  27. $afdoen_monster = rand(10,35);
  28. }
  29. elseif($_POST['spreuken'] == "Diffindo" && ($fetch['duel_level'] == 6 || $fetch['duel_level'] == 7 || $fetch['duel_level'] == 8 || $fetch['duel_level'] == 9 || $fetch['duel_level'] == 10))
  30. {
  31. $afdoen_monster = rand(35,60);
  32. }
  33. elseif($_POST['spreuken'] == "Diffindo" && ($fetch['duel_level'] == 11 || $fetch['duel_level'] == 12 || $fetch['duel_level'] == 13 || $fetch['duel_level'] == 14 || $fetch['duel_level'] == 15))
  34. {
  35. $afdoen_monster = rand(60,250);
  36. }
  37. elseif($_POST['spreuken'] == "Diffindo" && ($fetch['duel_level'] == 16 || $fetch['duel_level'] == 17 || $fetch['duel_level'] == 18 || $fetch['duel_level'] == 19 || $fetch['duel_level'] == 20))
  38. {
  39. $afdoen_monster = rand(250,600);
  40. }
  41. elseif($_POST['spreuken'] == "Diffindo" && ($fetch['duel_level'] == 21 || $fetch['duel_level'] == 22 || $fetch['duel_level'] == 23 || $fetch['duel_level'] == 24 || $fetch['duel_level'] == 25))
  42. {
  43. $afdoen_monster = rand(600,1300);
  44. }
  45. elseif($_POST['spreuken'] == "Diffindo" && ($fetch['duel_level'] == 26 || $fetch['duel_level'] == 27 || $fetch['duel_level'] == 28 || $fetch['duel_level'] == 29 || $fetch['duel_level'] == 20))
  46. {
  47. $afdoen_monster = rand(1300,6000);
  48. }
  49. ?>


Kan ik die code niet korter schrijven, want ik heb zo nog 10 spreuken. En dat is dan zo onoverzichtelijk. Kan dit korter geschreven worden? Met een lus ofzo?

4 antwoorden

Gesponsorde links
Offline haytjes - 31/07/2005 16:25 (laatste wijziging 31/07/2005 16:44)
Avatar van haytjes Gouden medailleGouden medaille

JS gevorderde
if($_POST['spreuken'] == "Expelliarmus" && ($fetch['duel_level'] == 1 || $fetch['duel_level'] == 2 || $fetch['duel_level'] == 3 || $fetch['duel_level'] == 4 || $fetch['duel_level'] == 5))
kan verandert worden naar:

if($_POST['spreuken'] == "Expelliarmus" && $fetch['duel_level'] >= 1 && $fetch['duel_level'] <= 5)

[edit]
en dit is nog overzichterlijk
  1. <?
  2. if($_POST['spreuken'] == "Expelliarmus")
  3. {
  4. if($fetch['duel_level'] >= 1 && $fetch['duel_level'] <= 5)
  5. $afdoen_monster = rand(1,25);
  6. elseif($fetch['duel_level'] >= 6 && $fetch['duel_level'] <= 10)
  7. $afdoen_monster = rand(25,50);
  8. elseif($fetch['duel_level'] >= 11 && $fetch['duel_level'] <= 15)
  9. $afdoen_monster = rand(50,200);
  10. elseif($fetch['duel_level'] >= 16 && $fetch['duel_level'] <= 20)
  11. $afdoen_monster = rand(200,500);
  12. ...
  13. }
  14. elseif($_POST['spreuken'] == "Diffindo")
  15. {
  16. ...
  17. }
  18. ?>


[edit]
maar ik denk dat het dit is wat je wilt: ('k hoop dat het werkt want ik heb het niet gecheckt)

  1. <?
  2. $spreuken["Expelliarmus"][] = 0;
  3. $spreuken["Expelliarmus"][] = 25;
  4. $spreuken["Expelliarmus"][] = 50;
  5. $spreuken["Expelliarmus"][] = 100;
  6. $spreuken["Expelliarmus"][] = 200;
  7.  
  8. $afdoen_monster = rand($spreuken[$_POST['spreuken']][floor($fetch['duel_level']/5)],$spreuken[$_POST['spreuken']][(floor($fetch['duel_level']/5))]+1)
  9.  
  10. ?>
Offline Voldemort - 31/07/2005 20:25
Avatar van Voldemort PHP ver gevorderde Ik gebruik die:

  1. <?
  2. if($_POST['spreuken'] == "Expelliarmus")
  3. {
  4. if($fetch['duel_level'] >= 1 && $fetch['duel_level'] <= 5)
  5. $afdoen_monster = rand(1,25);
  6. elseif($fetch['duel_level'] >= 6 && $fetch['duel_level'] <= 10)
  7. $afdoen_monster = rand(25,50);
  8. elseif($fetch['duel_level'] >= 11 && $fetch['duel_level'] <= 15)
  9. $afdoen_monster = rand(50,200);
  10. elseif($fetch['duel_level'] >= 16 && $fetch['duel_level'] <= 20)
  11. $afdoen_monster = rand(200,500);
  12. ...
  13. }
  14. elseif($_POST['spreuken'] == "Diffindo")
  15. {
  16. ...
  17. }
  18. ?>


Die is korter en veel handiger.

Van je onderste met die floor snap ik niks. Ik weet niet wat floor doet en wat de code doet. 
Offline vinTage - 31/07/2005 20:28 (laatste wijziging 31/07/2005 20:29)
Avatar van vinTage Nieuw lid volgens mij doet floor, een getal naar beneden afronden naar een heel getal

edit yep
Offline Voldemort - 31/07/2005 20:35 (laatste wijziging 31/07/2005 20:36)
Avatar van Voldemort PHP ver gevorderde Dan snap ik die code nog niet .
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.22s