twilitegxa Posted May 2, 2010 Share Posted May 2, 2010 What would be the best way to go about this: I have a table that displays a random enemy from a table (hit points, defense, experience earned, etc). Let's say to begin with, I have a set number that the enemy's hit points are reduced by if the player chooses to attack the enemy (6). What would be the best way in which to set this up to where the enemy's hit points get reduced each time the player clicks the attack button and the hit points get reduced by the number (6 in this case)? Since the code is generating a random enemy, other players playing at the same time could run the risk of generating the same enemy, so is there a way I could avoid this? I was thinking there could be some way to not actually alter the table data, but rather just do it within the browser window, but I'm not sure what technology would be best to use. Maybe AJAX? Any suggestions on how would be the best way to go about this? Link to comment https://forums.phpfreaks.com/topic/200482-any-suggestions/ Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Share Posted May 2, 2010 when you fight an enemy, it'll set their status to fighting in the database. So when you go to fight an enemy, you cant fight any of them that are already fighting. You have a button, or form I'm guessing. In the form tag, include "onSubmit='validateform(this)'" you would then in javascript at the top of the page.. do the form validation for that form. (Google about javascript form validating) You'd include a php script inside the javascript form validation (No need to close the javascript.. it allows php inside) for which you process your queries etc for the fight. Reducing 6 each time an attack is boring. You might want to add some adventure into it. $hploss = rand(0,10); //Random number between 0 and 10 Link to comment https://forums.phpfreaks.com/topic/200482-any-suggestions/#findComment-1052042 Share on other sites More sharing options...
twilitegxa Posted May 2, 2010 Author Share Posted May 2, 2010 Well, it is going to be more involved than 6 points each time, I was jut using it as a starting example. Thank you for the suggestion. I will work on some of that now and see if I have any more questions. :-) Link to comment https://forums.phpfreaks.com/topic/200482-any-suggestions/#findComment-1052046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.