Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/03/2010, 16:08
Avatar de HiToGoRoShi
HiToGoRoShi
 
Fecha de Ingreso: abril-2008
Mensajes: 849
Antigüedad: 16 años
Puntos: 31
Criticas para programar mejor

Que tal amigos, estaba aburrido y quise poner a prueba mi conocimiento tratando de hacer esas peleas de los juegos que hay en php, debe haber visto tipo BITEFIGHT, MAFIAS entre otros...

Bueno me gustaria que me den consejos y tips para programar mejor, que cosas no debo hacer, que debo hacer que le falat para que la programacion sea impecable y mas perfecta...

Código PHP:
Ver original
  1. <?php
  2. $tipo = "submit";
  3.  
  4. $vidaA = 100;
  5. $vidaB = 100;
  6.  
  7. $hpA = 500;
  8. $hpB = 500;
  9.  
  10. $hpcolorA = "#66FF00";
  11. $hpcolorB = "#66FF00";
  12.  
  13. $heroA = "Lord of Avernus";
  14. $heroB = "Warchief";
  15.  
  16. //Skils NOMBRES y ATAQUE
  17. $skillA = "Death Coil";
  18. $skillB = "Return";
  19.  
  20. $skillAdmg = rand(65,75);
  21. $skillBdmg = 30;
  22.  
  23. //Atake
  24. $atkA = rand(45,60);
  25. $atkB = rand(55,65);
  26.  
  27. if($_POST['action'] == "true") {
  28.  
  29. //ATAQUE MAGICO
  30. $da&#241;o = $atkB-($atkB*0.10);
  31.    if ($_POST['atacar'] == "Skill") {
  32.         //Atake Abaddon
  33.         $msj= "+<b><font color=green>".$heroA."</font></b> uso <font color=brown><i>".$skillA."</i></font> en <b><font color=blue>".$heroB."</font></b> causando <b><font color=red>".$skillAdmg. "</font></b> daño magico<br>";
  34.         //Atake Centauro
  35.         $rpta = "-<b><font color=blue>".$heroB."</font></b> respondio al ataque de <b><font color=green>".$heroA."</font></b> causando <b><font color=red>".$da&#241;o. "</font></b> daño fisico<br>";
  36.         //Calcular daño causado
  37.         $hpBtmp = $skillAdmg;
  38.         $hpAtmp = $da&#241;o;
  39.    }
  40. //Ataque FISICO
  41.     else {
  42.         $da&#241;o = $atkA-($atkA*0.08);
  43.         $da&#241;o2 = $atkB-($atkB*0.10);
  44.          
  45.         $skill = rand(0,100);
  46.         if ($skill <= 30) {
  47.             $da&#241;oRE = $atkA-($atkA*0.20);
  48.             $return= "--<b><font color=blue>".$heroB."</font></b> uso <font color=brown><i>".$skillB."</i></font> contra <b><font color=green>".$heroA."</font></b> devolviendo <b><font color=red>".$skillBdmg. "</font></b> de daño fisico y reduciendo el ataque en <font color=brown><b>".$da&#241;oRE."</b></font><br>";
  49.            $hpBtmp = $da&#241;oRE;
  50.             $hpAtmp = ($da&#241;o2+$skillBdmg);
  51.        }else {
  52.             $hpBtmp = $da&#241;o;
  53.             $hpAtmp = $da&#241;o2;
  54.        }
  55.         //Ataque Abaddon
  56.         $msj= "+<b><font color=green>".$heroA."</font></b> ataco a <b><font color=blue>".$heroB."</font></b> causando <b><font color=red>".$da&#241;o. "</font></b> daño fisico<br>".$return;
  57.         //Ataque Centauro
  58.         $rpta = "-<b><font color=blue>".$heroB."</font></b> respondio al ataque de <b><font color=green>".$heroA."</font></b> causando <b><font color=red>".$da&#241;o2. "</font></b> daño fisico<br>";
  59.  
  60.     }
  61.    
  62. //Calculando el % de la vida y la cantidad
  63.  
  64.     $hpA = (int)(($hpA - $hpAtmp));
  65.     $_SESSION['hpAresult'] = $_SESSION['hpAresult']+(500-$hpA);
  66.        
  67.     $hpB = (int)(($hpB - $hpBtmp));
  68.     $_SESSION['hpBresult'] = $_SESSION['hpBresult']+(500-$hpB);
  69.    
  70.     $vidaA = (int)($vidaA-($vidaA-(100*($hpA/500))));
  71.     $_SESSION['vidaAresult'] = $_SESSION['vidaAresult']+(100-$vidaA);
  72.    
  73.     $vidaB = (int)($vidaB-($vidaB-(100*($hpB/500))));
  74.     $_SESSION['vidaBresult'] = $_SESSION['vidaBresult']+(100-$vidaB);
  75.    
  76. //Colorear VIDAS
  77.     if ($_SESSION['vidaAresult'] >= 50) {
  78.         $hpcolorA = "#FF3300";
  79.     }
  80.     if ($_SESSION['vidaBresult'] >= 50) {
  81.         $hpcolorB = "#FF3300";
  82.     }
  83.    
  84. //Destruir la Session carajo
  85. if ($_SESSION['hpAresult'] > 500 or $_SESSION['hpBresult'] > 500 ){
  86.     $tipo = "hidden";
  87.     $combate = "true";
  88. }
  89.  
  90. if ($_SESSION['hpAresult'] < $_SESSION['hpBresult'] ){
  91.     $ganador = $heroA;
  92. }else{
  93. $ganador = $heroB; 
  94. }
  95.  
  96. print $_SESSION['hpAresult']." ".$_SESSION['hpBresult'];
  97. }
  98. ?>
  99. <form id="form1" name="form1" method="post" action="dota.php">
  100.     <table width="100%">
  101.         <tr>
  102.             <td width="50%"><fieldset>
  103.                     <legend style="font-weight: bold; font-family: Verdana, Geneva, sans-serif; font-size: 24px;">Abaddon</legend>
  104.                     <table width="100%">
  105. <tr>
  106.                             <td width="12%"><span style="font-size: 36px; font-weight: bold;"><img src="abaddon.gif" alt="" width="64" height="64"></span></td>
  107.                             <td width="76%" align="center" bgcolor="#333333" style="font-size: 36px; color: #FFF;"><?php print $heroA; ?></td>
  108.                             <td width="12%" align="center" bgcolor="#333333"><img src="skill1.gif" alt="" width="64" height="64"></td>
  109.                         </tr>
  110.                         <tr>
  111.                             <td colspan="3"><table width="100%">
  112.                                     <tr>
  113.                                         <td><span style="font-size: 14px; font-weight: bold; font-family: Verdana, Geneva, sans-serif;">Damage:</span></td>
  114.                                         <td colspan="3"><span style="font-size: 14px; font-family: Verdana, Geneva, sans-serif;"> 45 - 60 </span></td>
  115.                                     </tr>
  116.                                     <tr>
  117.                                         <td width="13%" style="font-weight: bold; font-family: Verdana, Geneva, sans-serif; font-size: 14px;">Armor:</td>
  118.                                         <td colspan="3">10</td>
  119.                                     </tr>
  120.                                     <tr>
  121.                                         <td><span style="font-size: 12px; font-weight: bold; font-family: Verdana, Geneva, sans-serif;">VIDA:</span></td>
  122.                                       <td width="67%" bgcolor="#333333"><table width="%<?php print 100-$_SESSION['vidaAresult']; ?>">
  123.                                                 <tr>
  124.                                                     <td bgcolor="<?php print $hpcolorA ;?>">&nbsp;</td>
  125.                                                 </tr>
  126.                                             </table></td>
  127.                                         <td width="20%" colspan="2" align="center"><span style="font-size: 18px; font-family: Verdana, Geneva, sans-serif;"> [<span style="font-weight: bold">500 </span>- <?php print 500-$_SESSION['hpAresult'];?>]</span></td>
  128.                                     </tr>
  129.                                 </table></td>
  130.                         </tr>
  131.                         <tr>
  132.                             <td></td>
  133.                         </tr>
  134.                     </table>
  135.                 </fieldset></td>
  136.             <td width="50%"><fieldset>
  137.                     <legend style="font-family: Verdana, Geneva, sans-serif; font-weight: bold; font-size: 24px;">Centauro</legend>
  138.                     <table width="100%">
  139.                       <tr>
  140.                             <td width="12%"><span style="font-size: 36px; font-weight: bold;"><img src="centauro.gif" alt="" width="64" height="64"></span></td>
  141.                             <td width="76%" align="center" bgcolor="#333333" style="font-size: 36px; color: #FFF;"><?php print $heroB; ?></td>
  142.                             <td width="12%" align="center" bgcolor="#333333"><img src="skill1a.gif" alt="" width="64" height="64"></td>
  143.                         </tr>
  144.                         <tr>
  145.                             <td colspan="3"><table width="100%">
  146.                                     <tr>
  147.                                         <td><span style="font-size: 14px; font-weight: bold; font-family: Verdana, Geneva, sans-serif;">Damage:</span></td>
  148.                                         <td colspan="3"><span style="font-size: 14px; font-family: Verdana, Geneva, sans-serif;"> 55 - 65 </span></td>
  149.                                     </tr>
  150.                                     <tr>
  151.                                         <td width="13%" style="font-weight: bold; font-family: Verdana, Geneva, sans-serif; font-size: 14px;">Armor:</td>
  152.                                         <td colspan="3">8</td>
  153.                                     </tr>
  154.                                     <tr>
  155.                                         <td><span style="font-size: 12px; font-weight: bold; font-family: Verdana, Geneva, sans-serif;">VIDA:</span></td>
  156.                                         <td width="67%" bgcolor="#333333"><table width="%<?php print 100-$_SESSION['vidaBresult']; ?>>">
  157.                                                 <tr>
  158.                                                     <td bgcolor="<?php print $hpcolorB ;?>">&nbsp;</td>
  159.                                                 </tr>
  160.                                             </table></td>
  161.                                         <td width="20%" colspan="2" align="center"><span style="font-size: 18px; font-family: Verdana, Geneva, sans-serif;"> [<span style="font-weight: bold">500 </span>- <?php print 500-$_SESSION['hpBresult'];?>]</span></td>
  162.                                     </tr>
  163.                                 </table></td>
  164.                         </tr>
  165.                         <tr>
  166.                             <td></td>
  167.                         </tr>
  168.                     </table>
  169.                 </fieldset></td>
  170.         </tr>
  171.         <tr>
  172.             <td colspan="2"><input type="<?php print $tipo; ?>" name="atacar" id="atacar" value="Atacar">
  173.                 <input type="<?php print $tipo; ?>" name="atacar" id="atacar" value="Skill" />
  174.                 <input name="action" type="hidden" id="action" value="true"></td></tr>
  175.     </table>
  176. </form>
  177. <?php
  178. if ($_POST['action'] == "true") {
  179.     ?>
  180. <fieldset><legend>Resultado</legend>
  181.     <table width="100%" bgcolor="#E8E8E8"><tr><td>
  182.     <?php print $msj.$rpta; ?>
  183.     </td></tr></table>
  184. </fieldset>
  185.  
  186.     <?php
  187. }
  188.  
  189. ?>
  190.  
  191. <?php
  192. if ($combate == true){
  193. ?>
  194. <fieldset><legend>Resumen:</legend>
  195.  
  196.     <table width="100%"><tr><td align="center" bgcolor="#333333"><span style="font-size: 36px; color: #FFF;"><?php print $ganador; ?> ha resultado ser el ganador</span></td></tr>
  197.  
  198.     </table>
  199. </fieldset>
  200. <?php
  201. }
  202. ?>

El ejemplo en linea: http://peruguitar.net/DOTA/dota.php


EXTRAS:

El centauro tiene un 20% de chance de utilizar su habilidad return el cual devuelve 30 de daño
Las armaduras defienden a los hereos del ataque fisico (no magico) , es decir ARMOR 10, un 10% de proteccion del ataque TOTAL causado