Quick question about forms RPG game.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmgek
Forum Newbie
Posts: 2
Joined: Sat Sep 04, 2010 11:35 pm

Quick question about forms RPG game.

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Quick question about forms RPG game.

Post 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.
User avatar
arrielmabale
Forum Newbie
Posts: 15
Joined: Fri Aug 13, 2010 3:57 pm
Location: Dubai

Re: Quick question about forms RPG game.

Post 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.
Post Reply