Skip to main content
GameDev.net gamedev.net
🔒 Locked

Is PHP enough? (For a Web Browser Game?)

Started by JeremyWB Oct 3, 2005 at 4:00 PM 12 replies 3k views
Original Post
JeremyWB
JeremyWB
I was planning to write an online, multi-player game in PHP. But as I think about this more, about what I want to do, I wonder if PHP alone can pull this off. To be honest, I'm new at PHP, and this will be my first online attempt. I don't think I'm incapable, though. I've been doing research for this game for too long to give up now, and I have seen it down before. Hm, let me give an example of why I'm concerned. For starters, this is a medieval strategy/war game. I know, there's lots of those, but none are to my liking. I want to make one that's free of fantasy, closer to the Hundred Years War. Anyway, for example, you send your troops to attack a tower (to seige) far off, and the script determines that it will literally take 48 real-time hours for your troops to even reach their target destination (I think one minute of real-time would equal one hour of game time, so 24 minutes = a day, etc). Anyway, if no one was even playing, I'd still want the troops to get there and start attacking in 48 hours. These battles will happen independantly of whether anyone is playing at the time, or not. Lots of things like this need to be going on in the background, like farmers harvesting their crops, for instance. Pretty much all of the time. I don't know enough about PHP to know for sure, but I'm going to take a wild guess and assume that I'll need to learn something else to do this legwork. Can anyone fill me in and tell me what I should do? If PHP can't do this background work, what could? How would you do it?
Undeadlnsanity
Undeadlnsanity
You could quite easily create a text based game using PHP and a databse such as MySQL.

There are many of these around, check out google: http://www.google.co.uk/search?q=online+text+rpg
JeremyWB
JeremyWB
Quote:
Original post by Undeadlnsanity
You could quite easily create a text based game using PHP and a databse such as MySQL.

There are many of these around, check out google: http://www.google.co.uk/search?q=online+text+rpg


What is MySQL?
Undeadlnsanity
Undeadlnsanity
MySQL is a database that is used for storing information. It can be accessed using PHP.

http://www.mysql.com
EvilCloneVlad
EvilCloneVlad
mySQL is a database, combined with PHP you can do just about anything, though it would take some serious effort. Since you are new to PHP it would also take you alot longer. To use PHP and mySQL you need a web server that supports both and if you are wanting to do local testing (on your own computer as you develop it, instead of having to upload each time to test) then you will need to install a web server such as apache or something, php, and mysql on your computer.

Also there is alot of resources for using both PHP and mySQL. Some resources can be found at www.php.net and www.mysql.com.
JeremyWB
JeremyWB
So PHP can run time-based events whether or not anyone is playing? Things can go on independantly in the background?
JeremyWB
JeremyWB
I see. I did download Apache 2.0 and PHP 5.0.5. I couldn't get them to work together, despite my hours of trying. So I have been using PHP as a script-translator for my PHP files for now, practicing.
EvilCloneVlad
EvilCloneVlad
I am fairly sure that it is possible, though it may be tough and I do not know exactly how it would be accomplished, I'm fairly certain it can be accomplished. There are many games out there that i believe have been built using php and a database. i believe games like utopia (http://games.swirve.com) are built using php. I haven't done a whole lot of game development using PHP and mySQL.
SpaceRook
SpaceRook
There's a book on Amazon called "PHP Game Development".

Is your game going to be browser based? You'll probably want to make sure you know some HTML and &#106avascript basics. <br/><br/>PHP isn't the only option. There's also JSP which you could use with the free Apache Tomcat. That would also give you the power of Java.
JeremyWB
JeremyWB
I definately want it to be a browser based game. I have seen many, especially MUDs, but this isn't going to be a MUD. You'll be able to click on menus and enter numbers, like how much % tax you want to impose on your lands, how much gold you offer your soldiers per week, etc. You'll raise armies--infantry, calvary--and nobility will act dependantly of you because they have their own land under you, which is worked by serfs, farmers and possibly yeoman (I don't know yet). There will be an economy going on the background, how much oats, grain, peas, barley, nuts, berries is harvested, and when, and from where... even each soldier will have his own stats--loyalty, resolve, stamina, strength, speed... as you can see it's going to have lots of layers, so to speak. But not a lot of micro-management, because AI will take care of that. Your job as the player will be to wage war, or expand, or both. Form alliances with other players, etc. Ah, and there will be a honor/dishonor system; tyrants will attract soldiers who like to pillage, and good kings will attract honorable men who prefer to crusade. That's the jist of it, really. It's just that when you send an army, depending on how far away the enemy is (in miles), and considering how many miles a day a soldier can march (12-24, I think I read), and considering that 1 minute of real time = 1 hour of their time... you get what I'm saying, I hope... there will be time-based events going on all of the time, and that is what worries me. But if PHP can pull it off, I'm all for it.
greytone
greytone
From your posts I am getting the feeling you want the game content to be fairly dynamic. IE Game content moves, dropdown menus, etc. PHP alone can't do that. PHP runs once on the server, and generates static HTML content. PHP's graphics functions do the same thing and generate static images such as jpgs.

What your describing can be done with a combination of &#106avascript and php. It works like this -

Php runs on the server and has access to the database but only runs once and can not create dynamic content. &#106avascript runs &#111;n the client’s computer, and can change html content dynamically but has no access to the server.<br><br>All your dynamic content is controlled by the &#106avascript, IE the menu's and moving of the images. If you look into how to create &#106avascript menus you will find often they are created by positioning, showing, and hiding div elements using &#106avascript. You can move your game content the same way.<br><br>When your game needs access to the database the &#106avascript can call a PHP script in a hidden iframe to get the data it needs. That is the &#106avascript sets the URL of the iframe to the phpscript with the required variables. Then after a seconds checks to see if a resulting text string has been displayed and parses that to get the values it needs...<br><br>Any time specific information that you wish to keep updated when nobody is &#111;n the game would have to be done with a server-side script.<br><br>-<br><br>The whole thing is a little complicated, mainly because scripting languages in combination with web browsers are not really designed for making games :) but like I say it certainly can be done.<br><br>Hope that helps, and good luck<br><br><br>-Greytone<br><br><br>
JeremyWB
JeremyWB
Quote:
Original post by greytone
Any time specific information that you wish to keep updated when nobody is on the game would have to be done with a server-side script.

-

The whole thing is a little complicated, mainly because scripting languages in combination with web browsers are not really designed for making games :) but like I say it certainly can be done.

Hope that helps, and good luck


-Greytone


I'm weird, I know. So a server-side, script, eh? Like CGI, Perl, or what would you recommend?
Zanthos
Zanthos
Quote:
Original post by JeremyWB
So PHP can run time-based events whether or not anyone is playing? Things can go on independantly in the background?


Some webhosting companies allow access to your account's crontab either via some admin system (ala cpanel) or otherwise. You can either use this tab to access the script directly, or via lynx. There's plenty of documentation floating around on how to do this, a couple of articles:

Link #1

Link #2

Some hosting companies may prefer for you to request changes to your crontab via email, others may (as mentioned previously) allow access via cpanel.. emailing them beforehand is your best bet :)

Good look with the game, and make sure you have a good book or two on DHTML and &#106avascript if you go with client-side scripting also :)<br>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.