954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Coding a PvP Arena - Help

Hey guys. Ive been working on an online game and Im attempting to code the attack arena. Bascialy what i want is people to be able to "sit down" at some sort of "table" (kinda like online poker) then they would battle it out at that "table" or arena etc. Is there a way to do that using PHP or would I have to pick up something like ajax? Thanks.

Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 
Hey guys. Ive been working on an online game and Im attempting to code the attack arena. Bascialy what i want is people to be able to "sit down" at some sort of "table" (kinda like online poker) then they would battle it out at that "table" or arena etc. Is there a way to do that using PHP or would I have to pick up something like ajax? Thanks.

You can definitely create something like that with JavaScript (AJAX) on the browser end and PHP on the server end.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 
You can definitely create something like that with JavaScript (AJAX) on the browser end and PHP on the server end.

Are there any resources out there that would point me in the right direction? Thanks.

Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 

You could do it in PHP, but I think using ajax would be a better choice for keeping all the different users synced at the table. Just google for 'ajax tutorial' and you'll get tons of results.

Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
 


Simple Example of XMLHTTPRequest (AJAX) with PHP Server Script
Query: (examples: day, month, year)

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

Thanks for the help. I understand the basics, like creating a simple form you posted above, but I have scoured the net for advanced topics and found nothing. For example what I would like to do, create some sort of "table" system where people can "sit down" or enter the arena, and there is nothing. I don't really know where to go from here. My main problem is having many different "areas" that can support just two people to have a turn based battle. I think I can create the battle system no problem but its the "table/arena" system that is giving me the trouble. How can I make it so that when someone "sits in" that no one else can sit in that seat and only one other person could "sit in" or join the arena at the opposing side?

Thansk for all the help again and I hope you can point me in the right direction:)

Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 

Are you thinking of using a database to store the data you need for this? Its the easiest way to achieve this as PHP can only persist states across HTTP requests using either a database or the disk unless you have a special setup such as memcached etc.

You will just need to create a single battle by entering it as a row in the database. Then you can assign users to that battle via their username, or session id.
You can keep track of who's turn it is via a column on the same table.

BTW: The AJAX bit is just for making your webpage more application like, so it doesn't have to reload on each challengers turn. But its not necessary. I think it would be easier for you to go with just PHP if you aren't used to developing with AJAX as it requires more coding than the traditional model..

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

Are you thinking of using a database to store the data you need for this? Its the easiest way to achieve this as PHP can only persist states across HTTP requests using either a database or the disk unless you have a special setup such as memcached etc.

You will just need to create a single battle by entering it as a row in the database. Then you can assign users to that battle via their username, or session id. You can keep track of who's turn it is via a column on the same table.

BTW: The AJAX bit is just for making your webpage more application like, so it doesn't have to reload on each challengers turn. But its not necessary. I think it would be easier for you to go with just PHP if you aren't used to developing with AJAX as it requires more coding than the traditional model..


I have thought about how to code it with just PHP, which I agree would be easier, but I don't know how to implement the turn based element into the PHP code. Would I just have to have an auto refresh script or something like that? Thanks.

Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 
I have thought about how to code it with just PHP, which I agree would be easier, but I don't know how to implement the turn based element into the PHP code. Would I just have to have an auto refresh script or something like that? Thanks.

Oh I see what you mean.
You could auto refresh and Iframe or hidden frame, but AJAX is probably simpler.

Just make periodic AJAX requests to the server in the background, to check if the other user has taken their turn. If they have, then update the current user with this information.

This is called HTTP Polling.

The other method's you can use are HTTP Binding (Comet), and HTTP BOSH defined in the XMPP/Jabber Specs: http://www.xmpp.org/extensions/xep-0124.html .
HTTP BOSH is the most efficient bandwidth wise and latency wise, but hardest to implement. (It requires a special server - Apache should have a module out soon for that though)

You can also use the "on-demand JavaScript" method. Its where you update the DOM with a

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

Thanks!!! How about creating an "table" type system? I dont really know where to start w/ this topic.

Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 
Thanks!!! How about creating an "table" type system? I dont really know where to start w/ this topic.

I'm not sure I understand the "table" type system. Could you elaborate on that?

I'm assuming it is a table where a user can create an instance, like a battle, and other users viewing the table can view the open instances and the onces currently being played. A user can then choose to join an instance (2 players) or create a new instance and wait?

??

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

I'm not sure I understand the "table" type system. Could you elaborate on that?

I'm assuming it is a table where a user can create an instance, like a battle, and other users viewing the table can view the open instances and the onces currently being played. A user can then choose to join an instance (2 players) or create a new instance and wait?

??

Exactly. Id like to create the same type of system as online poker where a user can "sit in" but in this case you would be fighting and it would be limited to two users.

Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You