Page 1 of 1
Making a P2P game or anything else using PHP...
Posted: Sat Apr 01, 2006 1:39 pm
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
Posted: Sat Apr 01, 2006 5:46 pm
by Christopher
Is the game turn based or attempting to be real-time?
Posted: Mon Apr 03, 2006 2:59 pm
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...
Posted: Mon Apr 03, 2006 3:27 pm
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
Posted: Fri Apr 07, 2006 8:37 am
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?
Posted: Fri Apr 07, 2006 8:41 am
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.
Posted: Fri Apr 07, 2006 8:44 am
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 ?
Posted: Fri Apr 07, 2006 9:23 am
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.)
Posted: Fri Apr 07, 2006 9:40 am
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...
Posted: Fri Apr 07, 2006 10:52 am
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.
Posted: Tue Apr 11, 2006 7:19 am
by BDKR
I would go Python before going Java. A lot more flexible and simple.
Posted: Mon May 01, 2006 1:20 pm
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?
Posted: Wed May 10, 2006 8:49 am
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?
Posted: Fri May 19, 2006 11:10 am
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.
Posted: Tue May 23, 2006 7:55 am
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.