Autor Zpráva
FAKTOR2
Profil
V súbore index.php je tento kod. Ked includujem funkce.php (v ktorom sú aj javascriptové funkcie ) na konci tak všetko funguje. Ked to dám na začiatok kam by som to potreboval tak to prestáva fungovať. Za každú radu budem vďačný.


<html>
    <head>
        <link rel="stylesheet" href="bootstrap.css">
        <link rel="stylesheet" href="style.css">
        <style type="text/css"></style>
           
    </head>
    <body style="color: #F89406; background-color: #000000">
<center><div class="maincontainer">
            <div class="panel">
                <div class="entity player"><img src="Waro.jpg" width="300" height="200" class="img" 

border="0"/></a></div>


<h2><span class="playerName">Player</span></h2>  
                    <div class="progress">
                        <div class="bar" id="playerHealthLevel"></div>
                    </div>
          
              <div class="progress">
                        <div class="mana" id="playerManaLevel"></div>
                    </div>
      
                    <input id="playerAttack" type="button" value="Attack" onclick="playerAttacks();" />
                    <input id="potion" type="button" value="Heal" onclick="potion();" />
          <input id="potion" type="button" value="Kuzlo" onclick="kuzlo();" />
          <input id="potion" type="button" value="Zvíš obranu" onclick="obrana1();" />
                </div><br><br><br><br><br><br>
                <div class="panel">
                    <div class="entity enemy"> </div>
                    <h2>Enemy</h2> 
                    <div class="progress">
                    <div class="bar" id="enemyHealthLevel"></div>
                </div></center>
                

            </div>          
            <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
            <?php 
 
include "funkce.php";
  ?> 
        </div>
    </body>
</html>
Marschmallow
Profil
FAKTOR2:
Jaký je obsah souboru funkce.php?
Tori
Profil
Include jquery může být i v <head>. funkce.php zřejmě pracují s DOMem, takže se musejí spouštět až v době, kdy je DOM načtený. Buď volejte funkci až v patičce stránky, anebo musíte v JS zajistit, aby se spustila až po načtení DOMu. viz: použití document.ready s jquery,
FAKTOR2
Profil
Obsah funkce.php :

<?php
require_once "../../maincore.php";
require_once "../../config.php";
include "../functions.php";
$id = $userdata["user_id"];
$nick = dbarray(mysql_query("SELECT * FROM fusion_users WHERE user_id='$id'"));
$meno = "".$nick["user_name"]."";
$player = dbarray(mysql_query("SELECT * FROM player WHERE nick='$meno'"));
$sila = "".$player["sila"]."";
$obrana = "".$player["obrana"]."";
$life = "".$player["life"]."";
$mana = "".$player["mana"]."";
$armor = "".$player["armor"]."";
$helma = "".$player["helma"]."";
$stit = "".$player["stit"]."";
$amulet = "".$player["amulet"]."";
$zbran = "".$player["zbran"]."";
$level = "".$player["level"]."";
$exp = "".$player["exp"]."";
$kredit = "".$player["kredit"]."";
$spe1 = "".$player["spell1"]."";
$spe2 = "".$player["spell2"]."";
$spe3 = "".$player["spell3"]."";
$power = floor($sila/5);

$brnenie1 = dbarray(mysql_query("SELECT * FROM armor_lahke WHERE id='$armor'"));
$ikona1 = "".$brnenie1["ikona"]."";
$nazov1 = "".$brnenie1["nazov"]."";
$naz1 = "".$brnenie1["nazivot"]."";
$nam1 = "".$brnenie1["namanu"]."";
$nao1 = "".$brnenie1["naobranu"]."";
 


$brnenie2 = dbarray(mysql_query("SELECT * FROM armor_lahke WHERE id='$helma'"));
$ikona2 = "".$brnenie2["ikona"]."";
$nazov2 = "".$brnenie2["nazov"]."";
$naz2 = "".$brnenie2["nazivot"]."";
$nam2 = "".$brnenie2["namanu"]."";
$nao2 = "".$brnenie2["naobranu"]."";



$brnenie3 = dbarray(mysql_query("SELECT * FROM armor_lahke WHERE id='$stit'"));
$ikona3 = "".$brnenie3["ikona"]."";
$nazov3 = "".$brnenie3["nazov"]."";
$naz3 = "".$brnenie3["nazivot"]."";
$nam3 = "".$brnenie3["namanu"]."";
$nao3 = "".$brnenie3["naobranu"]."";



$zb = dbarray(mysql_query("SELECT * FROM zbrane_lahke WHERE id='$zbran'"));
$ikona4 = "".$zb["ikona"]."";
$nazov4 = "".$zb["nazov"]."";
$naz4 = "".$zb["nazivot"]."";
$nam4 = "".$zb["namanu"]."";
$nao4 = "".$zb["naobranu"]."";
$min4 = "".$zb["silamin"]."";
$max4 = "".$zb["silamax"]."";


if ($player['amulet'] > 0) {
$amu = dbarray(mysql_query("SELECT * FROM amulety WHERE id='$amulet'"));
$ikona5 = "".$amu["ikona"]."";
$nazov5 = "".$amu["nazov"]."";
$naz5 = "".$amu["nazivot"]."";
$nam5 = "".$amu["namanu"]."";
$nao5 = "".$amu["naobranu"]."";
$sila5 = "".$amu["nasilu"]."";
}else{ }

if ($player['spell1'] > 0) {
$kuz = dbarray(mysql_query("SELECT * FROM spell WHERE id='$spe1'"));
$ikona6 = "".$kuz["ikona"]."";
$nazov6 = "".$kuz["nazov"]."";
$naz6 = "".$kuz["nazivot"]."";
$mana6 = "".$kuz["mana"]."";
$nao6 = "".$kuz["naobranu"]."";
$min6 = "".$kuz["silamin"]."";
$max6 = "".$kuz["silamax"]."";
$m6 = 0- $mana6;
}else{ }

if ($player['spell2'] > 0) {
$kuz2 = dbarray(mysql_query("SELECT * FROM spell WHERE id='$spe2'"));
$ikona7 = "".$kuz2["ikona"]."";
$nazov7 = "".$kuz2["nazov"]."";
$naz7 = "".$kuz2["nazivot"]."";
$mana7 = "".$kuz2["mana"]."";
$nao7 = "".$kuz2["naobranu"]."";
$min7 = "".$kuz2["silamin"]."";
$max7 = "".$kuz2["silamax"]."";
$m7 = 0- $mana7;
}else{ }

if ($player['spell3'] > 0) {
$kuz3 = dbarray(mysql_query("SELECT * FROM spell WHERE id='$spe3'"));
$ikona8 = "".$kuz3["ikona"]."";
$nazov8 = "".$kuz3["nazov"]."";
$naz8 = "".$kuz3["nazivot"]."";
$mana8 = "".$kuz3["mana"]."";
$nao8 = "".$kuz3["naobranu"]."";
$min8 = "".$kuz3["silamin"]."";
$max8 = "".$kuz3["silamax"]."";
$m8 = 0- $mana8;
}else{ }

$power2 = $sila5 + $power;
$minimal = $min4 + $power2;
$maximal = $max4 + $power2;
$odol = $nao1 + $nao2 + $nao3 + $nao4 + $nao5 + $obrana;
$ziv = $naz1 + $naz2 + $naz3 + $naz4 + $naz5 + $life;
$man = $nam1 + $nam2 + $nam3 + $nam4 + $nam5 + $mana;

?>

<script type="text/javascript">
var playerName = "Player";

var entityPrototype = {
  name:'Unknown',
  HP:<?php echo(json_encode($ziv)); ?>,
  Atk:0,
  Def:0,
  Lck:0,
  Mana:<?php echo(json_encode($man)); ?>,
};

function Entity () {
}

function rn(min,max)
{
    return Math.floor(Math.random()*(max-min+1)+min);
}

Entity.prototype = entityPrototype;

player = new Entity();
player.name = playerName;
player.Atk = function () { return rn(<?php echo(json_encode($minimal)); ?>,<?php echo(json_encode($maximal)); ?>); };
player.Def = function () { return rn(0,<?php echo(json_encode($odol)); ?>); };
player.h = player.HP/10;
player.m = player.Mana/10;
player.z1 = <?php echo(json_encode($naz6)); ?>;
player.ma1 = <?php echo(json_encode($m6)); ?>;
player.o1 = <?php echo(json_encode($nao6)); ?>;
player.sila1 = function () { return rn(<?php echo(json_encode($min6)); ?>,<?php echo(json_encode($max6)); ?>); };
player.z2 = <?php echo(json_encode($naz7)); ?>;
player.ma2 = <?php echo(json_encode($m7)); ?>;
player.o2 = <?php echo(json_encode($nao7)); ?>;
player.sila2 = function () { return rn(<?php echo(json_encode($min7)); ?>,<?php echo(json_encode($max7)); ?>); };
player.z3 = <?php echo(json_encode($naz8)); ?>;
player.ma3 = <?php echo(json_encode($m8)); ?>;
player.o3 = <?php echo(json_encode($nao8)); ?>;
player.sila3 = function () { return rn(<?php echo(json_encode($min8)); ?>,<?php echo(json_encode($max8)); ?>); };


enemy = new Entity();
enemy.name = 'enemy';
enemy.Atk = function () { return rn(0,4); };;
enemy.Def = function () { return rn(0,2); };
enemy.HP = 18;
enemy.h = enemy.HP/10;


var hi = function() {
  var healthLevelBar = document.getElementById('playerHealthLevel');
  healthLevelBar.style.width = player.HP*10/player.h + "%";
  healthLevelBar = document.getElementById('playerHealthLevel').innerHTML = Math.round(player.HP*10/player.h) + "%";
  
  
 var healthLevelBar2 = document.getElementById('playerManaLevel');
  healthLevelBar2.style.width = player.Mana*10/player.m + "%";
  healthLevelBar2 = document.getElementById('playerManaLevel').innerHTML = player.Mana;
  
 var healthLevelBar1 = document.getElementById('enemyHealthLevel');
  healthLevelBar1.style.width = enemy.HP*10/enemy.h + "%"; 
  healthLevelBar1 = document.getElementById('enemyHealthLevel').innerHTML = Math.round(enemy.HP*10/enemy.h) + "%"; 
}
hi();

// PLAYER CONTROLLS


// ATTACKING
var playerAttack = function(){
  var atkSum = player.Atk() - enemy.Def();
  if (atkSum>0){ 
  remainingHP = enemy.HP - atkSum;}else{remainingHP = enemy.HP; alert("Netrafil si ho."); } 
  enemy.HP = remainingHP;

 var atkSuma = enemy.Atk() - player.Def();
  if (atkSuma>0){
  remainingHP = player.HP - atkSuma;}else{remainingHP = player.HP; alert("Blokuješ jeho útok."); }
  player.HP = remainingHP;
  if (player.HP<1){
    alert("Si mrtvy");
    hi();
  }  

 if (enemy.HP<1){
    alert("Nepriatel skapal!");
  }  
  hi(); 
};

var playerAttacks = function(){
 
   playerAttack();
    hi();
  



  
};

// HEALING
var potion = function () {
  var healed = player.HP + player.z1;
  var ubermanu = player.Mana - player.ma1;
  
 if (player.HP>15) {
    return alert("Tvoj život je plný.");
    hi();
  } else {
  if (ubermanu<0) {
    return alert("Nemáš dostatok many.");
    hi();}else{
    player.HP = healed;
    player.Mana = ubermanu;
    hi();
    return console.log("Your healed a little bit " + player.HP);
  }}
  hi();
  alert('Enemy Tail Whips you!');
  enemyAttacks();
  hi();
};

// HEALING2
var potion2 = function () {
  var healed = player.HP + player.z2;
  var ubermanu = player.Mana - player.ma2;
  
 if (player.HP>15) {
    return alert("Tvoj život je plný.");
    hi();
  } else {
  if (ubermanu<0) {
    return alert("Nemáš dostatok many.");
    hi();}else{
    player.HP = healed;
    player.Mana = ubermanu;
    hi();
    return console.log("Your healed a little bit " + player.HP);
  }}
  hi();
  alert('Enemy Tail Whips you!');
  enemyAttacks();
  hi();
};

// HEALING3
var potion3 = function () {
  var healed = player.HP + player.z3;
  var ubermanu = player.Mana - player.ma3;
  
 if (player.HP>15) {
    return alert("Tvoj život je plný.");
    hi();
  } else {
  if (ubermanu<0) {
    return alert("Nemáš dostatok many.");
    hi();}else{
    player.HP = healed;
    player.Mana = ubermanu;
    hi();
    return console.log("Your healed a little bit " + player.HP);
  }}
  hi();
  alert('Enemy Tail Whips you!');
  enemyAttacks();
  hi();
};


// KUZLO
var kuzlo = function(){
  var atkSum = player.sila1() - enemy.Def();
  var ubermanu = player.Mana - player.ma1;
  if (ubermanu>-1) {
  if (atkSum>0){ 
  remainingHP = enemy.HP - atkSum;}else{remainingHP = enemy.HP; alert("Netrafil si ho."); } 
  enemy.HP = remainingHP;
  player.Mana = ubermanu; }else {remainingHP = enemy.HP; alert("Nemáš dostatok many."); } 

 var atkSuma = enemy.Atk() - player.Def();
  if (atkSuma>0){
  remainingHP = player.HP - atkSuma;}else{remainingHP = player.HP; alert("Blokuješ jeho útok."); }
  player.HP = remainingHP;
  if (player.HP<1){
    alert("Si mrtvy");
    hi();
  }  

 if (enemy.HP<1){
    alert("Nepriatel skapal!");
  }  
  hi(); 
};

var playerAttacks = function(){
 
   playerAttack();
    hi();
  



  
};


// KUZLO2
var kuzlo2 = function(){
  var atkSum = player.sila2() - enemy.Def();
  var ubermanu = player.Mana - player.ma2;
  if (ubermanu>-1) {
  if (atkSum>0){ 
  remainingHP = enemy.HP - atkSum;}else{remainingHP = enemy.HP; alert("Netrafil si ho."); } 
  enemy.HP = remainingHP;
  player.Mana = ubermanu; }else {remainingHP = enemy.HP; alert("Nemáš dostatok many."); } 

 var atkSuma = enemy.Atk() - player.Def();
  if (atkSuma>0){
  remainingHP = player.HP - atkSuma;}else{remainingHP = player.HP; alert("Blokuješ jeho útok."); }
  player.HP = remainingHP;
  if (player.HP<1){
    alert("Si mrtvy");
    hi();
  }  

 if (enemy.HP<1){
    alert("Nepriatel skapal!");
  }  
  hi(); 
};

var playerAttacks = function(){
 
   playerAttack();
    hi();
};

// KUZLO3
var kuzlo3 = function(){
  var atkSum = player.sila3() - enemy.Def();
  var ubermanu = player.Mana - player.ma3;
  if (ubermanu>-1) {
  if (atkSum>0){ 
  remainingHP = enemy.HP - atkSum;}else{remainingHP = enemy.HP; alert("Netrafil si ho."); } 
  enemy.HP = remainingHP;
 
Marschmallow
Profil
mm, zabalte prosím kód ve [#4], takhle neobarvené se to opravdu číst nedá...


FAKTOR2:
Stačí na konec kódu přidat [/pre]. Taky by neškodilo kód odsazovat ;)
FAKTOR2
Profil
Marschmallow:
Kod sa nezmestil :)


Ináč som to už vyriešil. Na začiatku bol ešte icludovaný súbor functions.php ten riadok som zmazal a funguje to.

<html>
    <head>
        <link rel="stylesheet" href="bootstrap.css">
        <link rel="stylesheet" href="style.css">
        <style type="text/css"></style>
     
<?php
require_once "../../maincore.php";
require_once "../../config.php";
$ide = $userdata["user_id"];
$nicke = dbarray(mysql_query("SELECT * FROM fusion_users WHERE user_id='$ide'"));
$menos = "".$nicke["user_name"]."";?>    
           
    </head>
    <body style="color: #F89406; background-color: #000000">
<center><div class="maincontainer">
            <div class="panel">
                <div class="entity player"><img src="Waro.jpg" width="300" height="200" class="img" 

border="0"/></a></div>


<h2><span class="playerName"><? echo $menos;?> </span></h2>  
                    <div class="progress">
                        <div class="bar" id="playerHealthLevel"></div>
                    </div>
          
              <div class="progress">
                        <div class="mana" id="playerManaLevel"></div>
                    </div>
      
                    <input id="playerAttack" type="button" value="Attack" onclick="playerAttacks();" />
                    <input id="potion" type="button" value="Heal" onclick="potion();" />
          <input id="potion" type="button" value="Kuzlo" onclick="kuzlo();" />
          <input id="potion" type="button" value="Zvíš obranu" onclick="obrana1();" />
                </div><br><br><br><br><br><br>................................
                       <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
            <?php 
 
include "funkce.php";
  ?> 
       
    </body>
</html>
pcmanik
Profil
FAKTOR2:
Je mi jasné, že sa len tak hráš s jazykom, ale:
1. Zabezpečuj vstupy a výstupy.
2. Čo robia tie magické konštrukcie "". $premenna ."" podľa teba?
3. Načo používaš input type button keď existuje samostatný prvok <button></button>
4. Includuješ súbor funkcie, ale pritom tam máš len jeden dlhý kód, rozdeľ ho do logických celkov a naozaj tam tie funkcie aj vytvor, kód sa ti tam opakuje.
5.Tvoja funkcia dbarray je len kratší názov pre mysql_fetch_array?
6. Mysql je zastaralé a v budúcich verziách php bude zastaralé, prejdi na mysqli alebo PDO.
7. Nemiešaj anglický a český kód, máš v tom bordel potom, udržuj nejaké coding standarts.
8. Tag center som teda už riadne dlho nevidel - ten tag už totiž ani v špecifikácii HTML5 neexistuje.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: