Jump to content

Ok newbie needs some help over here!


Tylor_Famous

Recommended Posts

Ok I am working on a SIMPLE game where you feed a dog and walk it and stuff. There are two bars (one for health and the other for how clean the dog is) and I want the bars to change when you take it for a walk and stuff.

 

Simple so far...

I have a "pre-game" page where you pick your dog.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="dog.php">
<select name="dognames">
  <option value="Goldy">Goldy</option>
</select>

<input type="submit" name="button" id="button" value="Submit" />
<input name="health" type="hidden" value="100" />
<input name="cleanness" type="hidden" value="100" />

</form>
</body>
</html>

 

Then the php page with all the code....

<?php

$name = "Golen";
$health = $_POST['health'];
$cleanness = $_POST['health'];
$words = "I love you";
$action = "walk";
$mood = "Happy";

if ($_POST['food'] == 'bone'){
$health = $health + 2;
$cleanness = $cleanness - 2;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style>
#health{
width:100%;
border:#990000 solid 2px;
height:6px;
}
#healthbar{
background-color:#FF0000;
height:6px;
width:<?php echo $health; ?>%;
}




#cleanness{
width:100%;
border:#000066 solid 2px;
height:6px;
}
#cleanbar{
background-color:#0000FF;
height:6px;
width:<?php echo $cleanness; ?>%;
}


p{
padding:0px;
margin:0px;
}

</style>
</head>

<body>
<p><img src="dogpictures/dog images/basic_dog_<?php echo $action; ?>.GIF" alt="Your Device Can Not Support Images, Sorry"  /><br /></p>

<p>Health <?php echo $health; ?>%<div id="health"><div id="healthbar"></div></div></p>

<p>Cleanness: <?php echo $cleanness; ?>%<div id="cleanness"><div id="cleanbar"></div></div></p>


<p>Mood: <?php echo $mood; ?></p>

<p><?php echo $name; ?> says: "<?php echo $words; ?>"</p>

<br />

<form action="<?=$PHP_SELF?>" method="post">
<p>Action:<select name="food" size="1">
  <option value="walk">Take On walk</option>
  <option value="brush">Brush</option>
  <option value="pet">Pet</option>
  <option value="bath">Give Bath</option>
</select>
<input name="Submit" type="submit" value="Submit" />
</form>
</p>

<br />

<form action="<?=$PHP_SELF?>" method="post">
<p>Action:<select name="food" size="1">
  <option value="bone">Dog Bone</option>
  <option value="steak">Steak</option>
  <option value="water">Water</option>
  <option value="dogfood">Dog Food</option>
</select>
<input name="Submit" type="submit" value="Submit" />
</form>
</p>



</body>
</html>

 

I am jsut working $health and  $cleanness right now. I want to press "bone" (from the dropdown menu) and have it bring up the health by 2 and the $cleanness down by 2.

 

The code where this should work is...

<?php 

if ($_POST['food'] == 'bone'){
$health = $health + 2;
$cleanness = $cleanness - 2;
}

?>

 

But of course it isn't working. Infact it seemes to lose it or something because the value of $health (which I can see through the echo) gose away after I feed my dog a bone.

 

I am new and have little idea what I am doing so any help would be GREAT!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.