PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,099 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,026 people online right now. Registration is fast and FREE... Join Now!




Want to make a web based game?

5 Pages V < 1 2 3 4 > »   

Want to make a web based game?, Look no further

Rating  3
BlackRaven

RE: Want To Make A Web Based Game?

23 Feb, 2008 - 07:09 PM
Post #21

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 3

hi everyone,
I'm developing a browser game travian/ikariam-like for my last assignment in my college right now, but I'm stuck at the time countdown. I still don't know how to make the time is still tik-ing while the user is offline, I try to connect the database with windows base program like delphi but still no use. someone can help me?? thanks

Note : if you guys have some article that can help can you please send to raven.kurogane [at] Gmail [dot] com. thanks very much
User is offlineProfile CardPM
+Quote Post

Martyr2

RE: Want To Make A Web Based Game?

23 Feb, 2008 - 07:28 PM
Post #22

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,307



Thanked: 837 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
QUOTE(BlackRaven @ 23 Feb, 2008 - 07:09 PM) *

hi everyone,
I'm developing a browser game travian/ikariam-like for my last assignment in my college right now, but I'm stuck at the time countdown. I still don't know how to make the time is still tik-ing while the user is offline, I try to connect the database with windows base program like delphi but still no use. someone can help me?? thanks

Note : if you guys have some article that can help can you please send to raven.kurogane [at] Gmail [dot] com. thanks very much


Well like mentioned before, cron jobs typically control the whole time factor of things when it comes to game world stuff happening to inactive or disconnected players (resources being accumulated). But don't think of it so much as time passing while being off line as much as the time that has passed since the user last was on being calculated.

So what do I mean by that? Lets say you were last on at noon on a Friday. Instead of saying that a user must know about every second between then and the following noon on Saturday, think of it as when the user logs on at noon on Saturday that you calculate the time now minus the time of the past and you can say that the user hasn't been on for 24 hours.

Meanwhile things like resources have been accumulating every hour (because of cron) and attacks were made at random intervals.

Your cron job would run a script to update real world resources every hour, adding to your account while you are offline. Attacks are made at 4pm on Friday and again on 2am Saturday. When the user logs in you can tell the user that based on the current time - time they were last logged in that X number of resources have been added/subtracted and 2 attacks had occurred. If they leave again and login 10 minutes later you could say that no resources had been added and no attacks have occurred.

I hope I am making sense with this.

To get something like this running you have to timestamp important events and attach it to the user in some way (typically an account that links back to the user's account table) and then your cron job which is running your world resource allocation. Your cron job has only one purpose, take a snapshot of the world and modify resources. The user's actions will dictate what has happened to the user based on the time they were last active.

smile.gif

This post has been edited by Martyr2: 23 Feb, 2008 - 07:28 PM
User is offlineProfile CardPM
+Quote Post

BlackRaven

RE: Want To Make A Web Based Game?

24 Feb, 2008 - 02:59 AM
Post #23

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 3

I'm sorry still not get in to the cron job part. do you meant with cron job, is like an action-time-based script that handle all of the time module at the game ?
yeah ..... my friend tell me that too, pehaps the time system can be handle by record the time when user logoff so when user login I can calculate how many time have been pass and I can decide how many resource user get, which building has been done. but I think that it can be done one side, I mean if the time is for two sides like Attacking someone, I think it still can't solve the problem. thanks
User is offlineProfile CardPM
+Quote Post

Martyr2

RE: Want To Make A Web Based Game?

26 Feb, 2008 - 12:31 PM
Post #24

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,307



Thanked: 837 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
QUOTE(BlackRaven @ 24 Feb, 2008 - 02:59 AM) *

I'm sorry still not get in to the cron job part. do you meant with cron job, is like an action-time-based script that handle all of the time module at the game ?
yeah ..... my friend tell me that too, pehaps the time system can be handle by record the time when user logoff so when user login I can calculate how many time have been pass and I can decide how many resource user get, which building has been done. but I think that it can be done one side, I mean if the time is for two sides like Attacking someone, I think it still can't solve the problem. thanks


I have provided a link to what cron jobs are, so scroll up this thread to see the link and check it out. Cron jobs are a system task, not related to the actual game code. It will just run a game script which will handle manipulating player data.

Now as far as the record time for an event, it doesn't necessarily have to be just when the login and logoff but anytime a page is refreshed and the PHP code is executed. Timestamping an event can set the event "in stone". Just like it would in history. This is a fixed point in time that can be seen by either side of a two-side game. If the person attacking attacks a person, the actual attack would have the timestamp. The player that was attacked would see the attack happened 2 secs, 2 minutes, 2 days ago etc. The attacker would see that they attacked 2 secs, 2 minutes, 2 days ago.

Lets say 5 minutes later both the attacked and the attacker refresh their page. There would be a calculation in the page to take the time now - the timestamp of the attack and see that it happened 5minutes 2secs, 7 minutes, or 2 days and 5 minutes ago.

Timestamping the actual event again makes it a fixed point and that both sides of a conflict or such will see it to their own relative time. So tinker around with the concept. This is the mechanism used in many online games. Especially turn based games. You have to know when an event had taken place and how long ago it took place since you can't be online all the time. This setup will also allow you to form a history log of attacks and events.

smile.gif
User is offlineProfile CardPM
+Quote Post

Aerodizz

RE: Want To Make A Web Based Game?

25 Mar, 2008 - 01:25 PM
Post #25

New D.I.C Head
*

Joined: 9 Sep, 2007
Posts: 2


My Contributions
Atm I have a game name... I will start using Freehostia untill i have enough money for a payd one.. But i have the scripts and i got the tip to upload them.. So i logged in on Freehostia.. my account and uploaded my "Crime" Script.

But when i clicked on it.. It said "Page Could Not Be Found"

So i dont know what to do sad.gif
User is offlineProfile CardPM
+Quote Post

CyberPetWorld

RE: Want To Make A Web Based Game?

4 Apr, 2008 - 01:49 AM
Post #26

New D.I.C Head
*

Joined: 1 Apr, 2008
Posts: 17


My Contributions
Hello,

I have a website that is a virtual pet community which has various PHP games that members can play to gain points, etc.

I am very interested in your post and would love to learn how to script games.

One thing I have in mind is currently members can only battle against enemies that I upload to the community. What I would like to do is set it up so members can battle against each others pets and send each other battle requests. It would also be good to have a league table that rates its members.

Is there anyone out there that could help me? It would involve adding to a system and database that is already in place.

Thanks

Justin
User is offlineProfile CardPM
+Quote Post

Martyr2

RE: Want To Make A Web Based Game?

8 Apr, 2008 - 03:18 PM
Post #27

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,307



Thanked: 837 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
QUOTE(Aerodizz @ 25 Mar, 2008 - 02:25 PM) *

Atm I have a game name... I will start using Freehostia untill i have enough money for a payd one.. But i have the scripts and i got the tip to upload them.. So i logged in on Freehostia.. my account and uploaded my "Crime" Script.

But when i clicked on it.. It said "Page Could Not Be Found"

So i dont know what to do sad.gif


If you successfully uploaded a script to your host, it is just a matter of knowing where your script is located and typing in the URL. If you are getting the page could not be found error, you either mistyped the name or need to change the URL to reflect your script. I would first check your capitalization of the file name and make sure it exactly matches what you uploaded as well as your spelling. Second I would make sure you are typing in the correct address to get to your account and your page.

Let me know how that goes. smile.gif
User is offlineProfile CardPM
+Quote Post

Martyr2

RE: Want To Make A Web Based Game?

8 Apr, 2008 - 03:26 PM
Post #28

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,307



Thanked: 837 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
QUOTE(CyberPetWorld @ 4 Apr, 2008 - 02:49 AM) *

Hello,

I have a website that is a virtual pet community which has various PHP games that members can play to gain points, etc.

I am very interested in your post and would love to learn how to script games.

One thing I have in mind is currently members can only battle against enemies that I upload to the community. What I would like to do is set it up so members can battle against each others pets and send each other battle requests. It would also be good to have a league table that rates its members.

Is there anyone out there that could help me? It would involve adding to a system and database that is already in place.

Thanks

Justin


Something like this could be accomplished through the use of a table which would keep track of the battle requests. When a user makes a request, you would add a line to a table which would track things like who sent the request (their id), who the message is for (their id), a date the request was launched (so you know keep track of how old the request is and time limits for the person to respond), a special unique request ID, and any details about who is doing the battle and with what pets.

When the person being attacked then logs in, their page can read battle requests and presented with a button to accept the challenge. The battle can then engage and as soon as battle is over, resources are divided and the request is cleared from the table.

Think of it as a queue for battle. When both parties agree on the battle, it then happens and at the end the request is removed from the queue. This will allow a person to essentially battle, end the battle, click for another request and jump into battle again with another party.

smile.gif
User is offlineProfile CardPM
+Quote Post

Dark_Light

RE: Want To Make A Web Based Game?

22 Apr, 2008 - 10:58 PM
Post #29

New D.I.C Head
*

Joined: 22 Apr, 2008
Posts: 10


My Contributions
I want a guide how to program periodic events. Cron i think it was called...
User is offlineProfile CardPM
+Quote Post

Martyr2

RE: Want To Make A Web Based Game?

29 Apr, 2008 - 02:32 PM
Post #30

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,307



Thanked: 837 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
If you look earlier in this thread, links were provided to sites which show how to use cron to setup game events. All you need to do is just have the scheduled jobs run scripts at specific times of day etc.

smile.gif
User is offlineProfile CardPM
+Quote Post

freylast

RE: Want To Make A Web Based Game?

11 Aug, 2008 - 03:03 AM
Post #31

New D.I.C Head
*

Joined: 11 Aug, 2008
Posts: 1

hi,i make simple RPG php game,but i confuse about quest...
can you help me what i must do first?like table that i must make or else
thanks...
( sorry my english bad smile.gif )
User is offlineProfile CardPM
+Quote Post

kiwi2

RE: Want To Make A Web Based Game?

16 Sep, 2008 - 03:59 AM
Post #32

D.I.C Head
Group Icon

Joined: 16 Sep, 2008
Posts: 164



Thanked: 4 times
Dream Kudos: 300
My Contributions
For beginners here is a simple webgame called catch-a-thief.
If u r serious about game development this kind of game is a good place to start.
<?php
include "thiefcss.php";
?>
<div id='ca'>
<?php
$img = "";
$mess ="";
$array = array("Jewellery_Store" , "Art_Gallery" , "Bank" , "Museum" , "Trade_Show");
$thifee = array("Prison" , "Little_Old_Ladies_House");
$new = array_merge($array, $thifee);
if (!isset ($_GET['thief']) )
{
$img ='beg.jpg';
$guess = '0';
$mess = "<h4>The thief moves around quickly see if you can either catch him or put him behind bars, if you manage to pick the same location as the thief, you catch him, if he lands in prison you win, but if he gets into the little old ladies house you lose</h4>";
shuffle($array);
$thief = $array['0'];
echo "$thief";
}
else if (isset($_GET['thief']) )
{
if ($_GET['thief'] == $_GET['yourpick'])
{
$img ='caught.jpg';
$mess = "<a href='catchthief.php'>You have caught the thief,play again</a><br />";
}
else if ($_GET['thief'] == 'Prison')
{
$img ='cops.jpg';
$mess ="<h2>You Have put the thief behind bars, you win</h2><a href='catchthief.php'>Play again!!<a/><br />";
}
else if ($_GET['thief'] == 'Little_Old_Ladies_House')
{
$img ='beg.jpg';
$mess ="<H2>The Thief is in the Little Old Ladies House, you lose</h2><a href='catchthief.php'>Play again!!<a/><br />";
}
else

{
echo "<b>Thief's present location $_GET[thief]<br />";
$img = 'beg.jpg';
$mess = "The thief is on the move your time is running out";

$array = array("Jewellery_Store" , "Art_Gallery" , "Bank" , "Museum" , "Trade_Show");
$thifee = array("Prison" , "Little_Old_Ladies_House");
$new = array_merge($array, $thifee);
shuffle($new);
$thief = $new['0'];
$yourpick = $_GET['yourpick'];
}
}

$guess = (int) $_GET['guess'];
$guess++;
echo "$guess<br />";
if ($_GET['guess'] < 6)
{
echo "$mess<br />";
echo "<img src='$img' /><br />";

echo "<form action='catchthief.php' method='get'>Thiefs Location<br /><input type='hidden' name='thief' value='$thief' /><br />Your Locatiin<br /><input type='text' name='location' value='$yourpick' /><br />Guess where the the thief will be next<br /><input type='radio' name='yourpick' value='Jewellery_Store' />Jewellery Store<br />
<input type='radio' name='yourpick' value='Art_Gallery' />Art Gallery<br />
<input type='radio' name='yourpick' value='Bank' />Bank<br />
<input type='radio' name='yourpick' value='Trade_Show' />Trade Show<br />
<input type='radio' name='yourpick' value='Museum' />Museum<br /><input type='hidden' value='$guess' name='guess' /><input type='submit' value='catch thief' />";
}
else
{
echo "<img src='$img'/><br />";
echo "$mess<br />";
echo "<a href='catchthief.php'>Play Again</a><br />";
echo "<b>Game Over</b>";
}
?>
</div>






User is offlineProfile CardPM
+Quote Post

edu2004eu

RE: Want To Make A Web Based Game?

17 Sep, 2008 - 03:07 AM
Post #33

New D.I.C Head
Group Icon

Joined: 26 Aug, 2007
Posts: 47


Dream Kudos: 25
My Contributions
For everybody who is looking for a good host for their games which has cron jobs, take a look at www.novahost.org. I used it for my game and it has a very good uptime, although it's free biggrin.gif
(don't want to advertise, just helping out the people who are looking for a host.

And for anybody who is trying to start making a game, you have to plan it very carefully and preferrably use a CVS system, especially if you are working with other people. I made an OK game I would say, in almost a year... so be prepared for long nights of hard work and lots of coffee...
User is offlineProfile CardPM
+Quote Post

ghqwerty

RE: Want To Make A Web Based Game?

22 Sep, 2008 - 12:14 PM
Post #34

if($spareTime > 0){ $this->writeCode(); }
Group Icon

Joined: 8 Aug, 2008
Posts: 748



Thanked: 24 times
Dream Kudos: 25
My Contributions
i just downloaded freemind

i would recommend people download this as its free and will be VERY helpful for planning out a game

its a mindmap system
User is offlineProfile CardPM
+Quote Post

Limitation

RE: Want To Make A Web Based Game?

27 Sep, 2008 - 11:12 AM
Post #35

New D.I.C Head
*

Joined: 27 Sep, 2008
Posts: 19



Thanked: 1 times
My Contributions
Hello everyone!
Well Im working on a text based games atm, I have got a WAMP Server (Includes MySQL, PHP, Apache etc) but I have encountered some problem and confused with the database on the MyAdmin part of local host. I have just been learning php for sometime and created a login script. It works fine, but I have no idea how to get it in the database and get it running (for practice) so I can continue further. I have tried loads of times but it shows an error (in the database) etc...

If you lot understood me lol, Help would be apreciated.

Thanks biggrin.gif
User is offlineProfile CardPM
+Quote Post

Hary

RE: Want To Make A Web Based Game?

28 Sep, 2008 - 09:34 AM
Post #36

D.I.C Regular
Group Icon

Joined: 23 Sep, 2008
Posts: 411



Thanked: 40 times
My Contributions
QUOTE(Limitation @ 27 Sep, 2008 - 12:12 PM) *

I have tried loads of times but it shows an error (in the database) etc...


What commands did you use and what errors did you get? Without more information it is hard to tell what is wrong.

in PHP:
CODE

<?php
// we connect to example.com and port 3307
$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

// we connect to localhost at port 3307
$link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>


For more information, see the PHP Manual

Default user/password should be provided in the documentation, I guess it is root or admin and no password

User is offlineProfile CardPM
+Quote Post

kiwi2

RE: Want To Make A Web Based Game?

30 Oct, 2008 - 03:31 AM
Post #37

D.I.C Head
Group Icon

Joined: 16 Sep, 2008
Posts: 164



Thanked: 4 times
Dream Kudos: 300
My Contributions
WARS OF CAQUSANDRA, mmorgp, has begun, I'll post the code as I go along, but I would love a little help, perhaps when it is finished a tutorial might be in it.

In the beginning when the world had only begun to learn, in the beginning when man had only begun to learn... survival was the key, .. survival of the fittest meant that unless you committed yourself to the art of living you would be left behind.
The old world has set its sights on conquering the blight of caqusandra, are you up to the challenge.

[code]
mysql table, please crit it, this is the basis for the game, good planning here will save a lot of time.

<?php
include "config.php";
$query = "CREATE TABLE multi(id SMALLINT(5)
UNSIGNED NOT NULL
AUTO_INCREMENT,
PRIMARY KEY(id), userp VARCHAR(10), password VARCHAR(19), loc TEXT, avatar TEXT, tokens VARCHAR(100), weapons VARCHAR(100), wars VARCHAR(50), position VARCHAR(50), hunt VARCHAR(50), loot VARCHAR(50), maps VARCHAR(100), strategy TEXT, bal VARCHAR(100), history TEXT, other1 TEXT, other2 TEXT, other3 VARCHAR(100), other4 VARCHAR(255), other5 VARCHAR(100), other6 VARCHAR(100))";
print "running query";
mysql_query($query, $link) or die
("CREATE TABLE error: " . mysql_error());
mysql_close($link);
?>[code]

User is offlineProfile CardPM
+Quote Post

laces12

RE: Want To Make A Web Based Game?

21 Nov, 2008 - 07:04 AM
Post #38

D.I.C Head
**

Joined: 20 Nov, 2008
Posts: 69



Thanked: 1 times
My Contributions
would be interesting, but no code??
User is offlineProfile CardPM
+Quote Post

Clubwarzs

RE: Want To Make A Web Based Game?

27 Dec, 2008 - 04:00 PM
Post #39

New D.I.C Head
*

Joined: 27 Dec, 2008
Posts: 2

Hello,

My name is Jeff. I am not sure if I am in the right area or not. But my question I wanted to out forth, was I have spent a good deal of 2 years learning everything from simple html to php, to css and now java. I find myself stuck alot of times because I have to work through errors on my own and sometimes it takes days if not weeks for me to figure them out. So what I wanted to know is there a site where I can go to test the codes in action prior to uploading to my site. Or if anyone can tell me how to use dreamweaver to test on local server before uploading.


thanks Jeff
User is offlineProfile CardPM
+Quote Post

Valek

RE: Want To Make A Web Based Game?

27 Dec, 2008 - 10:41 PM
Post #40

The Real SkyNet
Group Icon

Joined: 8 Nov, 2008
Posts: 627



Thanked: 43 times
Dream Kudos: 175
My Contributions
Try installing XAMPP.
User is offlineProfile CardPM
+Quote Post

5 Pages V < 1 2 3 4 > » 
Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 12:10PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month