-1
I’m working on a complex code, so I’m just gonna pass on the necessary.
Basically I’m trying to create an algorithm in php that simulates a video game inventory, where we can equip items in the character, and remove them later. to ensure that the items are equipped and unadjusted, I made this code:
if($equip == 0) {
if($sword == 1) {
$damage = $damage+3;
$weapon = 'Sword'; $sword=3;
} elseif($sword == 2 && $setweapon == 1) {
$damage = $damage-3;
$sword = 3;
}
if($plate == 1) {
$defense = $defense+3;
$armor = "Chestplate";
$plate = 3;
} elseif($plate == 2) {
$defense = $defense-3;
$plate = 3;
}
if($staff == 1) {
$damage = $damage+1;
$mana = $mana+15;
$weapon = 'Staff';
$staff = 3;
} elseif($sword == 2 && $setweapon == 0){
$damage = $damage-1;
$mana = $mana-15;
$staff = 3;
}
if($cape == 1) {
$defense = $defense+2;
$mana = $mana+15;
$armor = 'Cape';
$cape = 3;
} elseif($cape == 2) {
$defense = $defense-2;
$mana = $mana-15;
$cape = 3;
}
if($bow == 1) {
$damage = $damage+2;
$distance = $distance+2;
$weapon = 'Bow';
$bow = 3;
} elseif($bow == 2 && $setweapon == 0) {
$damage = $damage-2;
$distance = $distance-2;
$bow = 3;
}
if($vest == 1) {
$dextery = $dextery+15;
$defense = $defense+2;
$armor = 'Vest';
$vest = 3;
} elseif($vest == 2) {
$dextery = $dextery-15;
$defense = $defense-2;
$vest = 3;
}
$equip = 1;
}
All right, this works well for when the game starts and automatically equips it according to the character’s class. My intention is to try to make a small menu, where I choose an item that is with the number 3 (Items number 3 would appear in my inventory) and turn it to 1, equipping in my character.
But how will I identify this item that will be equipped in html?
Have you studied classes?
– Woss
To be frank, I don’t know
– riki481
I just saw what classes are. I tried to use classes in C# and it didn’t work (just like all my code), I won’t use classes in my code (too complicated for my level).
– riki481
In my opinion, your question as a whole you will hardly get an adequate answer. If something brief is enough for you: create a link in HTML with a query string (
index.php?item_id=1234
) pointing out the ID of such an item. Then in PHP you get this id via GET:$_GET['item_id']
. I believe that in addition will make your question outside the scope of the site.– LipESprY
and how I query?
– riki481