Page 1 of 1

Quick question about forms RPG game.

Posted: Sat Sep 04, 2010 11:53 pm
by jmgek
I try not to ask questions and usually find the answer on my own. but I have a Quick question

Code: Select all

<?php
	
	$enemy = "150";

if ( $enemy < "0" ) {
	echo "you have killed the monster<br />";
}
		echo "monsters HP" . "$enemy <br />";

	$char = "100";

if ($char < "0"){
	echo "you have died game over!<br />";
}
		echo "your HP" . "$char<br />";

$attack = $enemy - "10";
$focus = $char - "5";


?>
<button type="button" id="$attack">attack</button>

<button type="button" id="$focus">focus</button>

My problem is Is php the best for this? If not I can learn JavaScript as well?. how can i make this work and be refreshed to the user?
I am sorry, I really feel bad asking this.

Thank you in advance!

Re: Quick question about forms RPG game.

Posted: Sun Sep 05, 2010 2:25 am
by requinix
Sure, you can do it with only PHP. It involves a page refresh so the user might not be too happy about that.

Something better would be PHP+AJAX. Button click -> send information to server -> receive information about what happened -> display it to the user. No page refreshes. The backend will look pretty much the same, though - you're still outputting the result of the action, but it won't be coupled to the rest of the page HTML.

Re: Quick question about forms RPG game.

Posted: Sun Sep 05, 2010 3:06 am
by arrielmabale
The best is that you study both of them, Javascripts gives pleasure to users in a way of interactively doing something without most of the page load. Then use php to verify the actions being made.