Making a P2P game or anything else using PHP...

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Making a P2P game or anything else using PHP...

Post by The-Master »

Hi, recently i got the idea of making a text-based browser game using PHP, but, the game will be directly between the players(Peer2Peer), for example if one player challenges another it will auto redirect him to the game script... i thought of using socket for this great idea... if you have any other suggestion i'll be glad to hear...

if some of you are intrested in PHP+Socket check this:
http://www.zend.com/pecl/tutorials/sock ... c=0&view=1
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Is the game turn based or attempting to be real-time?
(#10850)
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post by The-Master »

well both are nice, it doesn't matter, but real-time is better :)
if you know anything that can provide this great feature, i'll be more than happy to hear 'bout it!

the DB is ready and the registration, login, members list, some game info and graphics are ready but the game itself is yet to be made...
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Your PHP code is still running on the server, in order to open a socket on a machine the code has to be running on that machine, that would mean either writing a client side application in java for example and opening the socket locally, which eliminates the need for PHP, what you could do however with PHP is have each client connected to the server and have the server relay messages to the appropriate client
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post by The-Master »

that sounds nice but i don't know how to write java applications... but i like the idea of a client side application.
it may be possible to open a socket at the same machine that the code is running on if i find a host that provides this service but minwhile the application is the only way.

is there some other language usable to make a client side application?
if not, do you know a site or a book that can teach me to write Java applications?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

bah.you can write client side in PHP and make it an exe...don't recall the name of the software but search for php exe files or something along those lines in the forums,you should find something. Or maybe someone with a better memory than me will reply.
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post by The-Master »

k thanks! i found some cool thing using men's best friend!(google):
http://java.sun.com/j2ee/releases/

this may be my solution!

by the way are you talking about http://www.priadoblender.com ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Given the fact that you're providing a link to the java Enterprise Edition i'm afraid you'll need some (a lot) more time to realise your plans. (Btw, sockets are part of J2SE and can be used in an applet too.)
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post by The-Master »

well in the start of my project i didn't want to even look at other languages such as Java i wanted pure PHP, the game is highly featured and it's all written in PHP until i got to the battle part of it... php didn't provide the feature i needed... so i turned to other languages... i just need to make one small application using java, nothing fancy... if i'll learn the basics of java i am ready to go...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I have read that this http://www.heroesmini.com/ is a PHP/Ajax application. You might want to look at it for ideas/inspiration.
(#10850)
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

I would go Python before going Java. A lot more flexible and simple.
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post by The-Master »

i found the way! this is it! just need to test it!
the way is:
i make a table named "battle" wich consists 3 rows:
*battle int(11) ===> this is a 0/1(yes/no) row wich tells us if the player is in-battle or out of battle...
*attacker char(50) ===> this tells us the name of the player attacking someone(only for someone who is being attacked).
*defencer char(5) ===> this tells us the name of the player defending(the one who is being attacked) this is only for attacking players.

*when someone is entering a battle his "battle" row in the DB changes to "1" wich means in-battle.
*whenever the battle is ended both "attacker" and "defender" are unset in the DB...

and the main code:

Code: Select all

// pull data from table "battle"
if($battle == 1) {
// redirect the player to the "battle.php" page...
}
elseif($attacker != "") {
// redirect the player to the "defend.php?enemy=$attacker" page...
}
elseif($defender != "") {
// redirect the player to the "attack.php?enemy=$defender" page...
}
else {
// go to main game page...
}
and all the vars of the player stats(race, class, HP, MP, etc...) will be set to a session in the defender and the attacker side from the $_GET['enemy'] thing...

you think this will work? if you do any suggestions to improve?
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

That would require the user to reload the page manually to continue their battle.

What if one person AFKs during a battle? Would the other person have to wait him out?
BadgerC82
Forum Commoner
Posts: 25
Joined: Tue Feb 07, 2006 6:53 am

Post by BadgerC82 »

Look at one of the links above that mentions AJAX.

that may definitly be your best solution... Tho u may be a bit out of your depth with writing a real time game as it seems as though you may not have a great deal of coding experience ;)

Try a turn based one first, then move on.
WDPEjoe
Forum Newbie
Posts: 4
Joined: Sat May 06, 2006 4:14 pm

Post by WDPEjoe »

First, if you have a column in mysql that is only 0 or 1, I suggest using the ENUM datatype (since you'll never need 4,000,000 [or whatever the INT type goes up to unsigned] in that column).

Second, here is the simple answer: For now, web-based PHP applications have no real-time abilities.

You can somewhat get around this by using the XMLHttpRequest (or the corresponding activex [module? - i forget the technical name] for IE) object in Javascript. Using this, you could
1) have the relevant information about a battle saved on the server (XML file/database/whatever)
2) have the XMLHttpRequest object query the server every few seconds (using setTimeout in JS)
3) if there has been a change then the server should respond with the necessary information
4) use JS to update the page as necessary

Making a web-based game with PHP/MySQL/Javascript is a concept I've been toying around with theoretically (I haven't put together anything in code yet). The limitations of the technologies mean that you could probably come up with a nice game that is a turn-based/real-time hybrid (I think). It would be like a fast-paced turn-based game.

One thing to keep in mind though is that the more times you're connecting to your server, the more of a performance hit it will be. I can imagine a disaster in the situation where a lot of people are playing against each other and the server is getting swamped with update requests from the browser.

All of the stuff I just talked about is well-documented by the way, just look up AJAX.
Post Reply