Game Architectural Question

J

Jack Burton

Hi,
I'm new to this group and I'm writing because my java knowledge lack of
pattern and standard solutions for common (or less) problems. Hope you
can help me better than I did :)

I'm trying to build an online web game: you command a fleet in space,
so you can move the fleet between planets and combat other fleets. I
need a sort of background task that, perhaps reading from a DB various
scheduled travels and fleet positions, could "move the fleets" and
"manage battles". I thought of a task that wake up every X minutes (let
say 5) and check all this (move a bit a fleet, delegate a battle
between two fleets to another task, and so on).

Do you have any suggestions using java language/pattern/common
solutions?


Thank you,
Jack Burton
 
O

Oliver Wong

Jack Burton said:
Hi,
I'm new to this group and I'm writing because my java knowledge lack of
pattern and standard solutions for common (or less) problems. Hope you
can help me better than I did :)

I'm trying to build an online web game: you command a fleet in space,
so you can move the fleet between planets and combat other fleets. I
need a sort of background task that, perhaps reading from a DB various
scheduled travels and fleet positions, could "move the fleets" and
"manage battles". I thought of a task that wake up every X minutes (let
say 5) and check all this (move a bit a fleet, delegate a battle
between two fleets to another task, and so on).

Do you have any suggestions using java language/pattern/common
solutions?

What I usually do for stuff like this is, instead of running a
background thread or whatever, I have a DB table which basically schedules
when events should occur. For example, if the player says "Move this ship
from its homeplanet of Quartz to planet Nebulon", I'd immediately change the
ship's location from "Quartz" to "space", and then add a scheduled event of
"At stardate 499283, move ship from 'space' to 'Nebulon'".

Then, the next time a player (ANY player in the game) does something, I
run a quick process to calculate the in-game stardate based on the real-life
time, and then look at schedule-table to see which events are in the pass,
according to this stardate, and then trigger all the events in order.

The only problem with this is that if players decide to abandon your
game for a while (e.g. days or months), the events won't actually trigger
until the next time a player logs into the game to check the state. And this
is only a problem if your game also features e-mail notification of events;
the other players won't get the e-mail notification until SOMEBODY logs in.
If this is a problem for you (it won't be, if you don't have e-mail
notification feature), then you can just create a dummy robot account, and
write a small application (in any language, not nescessarily Java) which
just logs into the robot account every 5 minutes, and immediately logs out.

- Oliver
 
J

Jack Burton

This is an interesting point of view, Oliver!
I was thinking about other issues that it can produce (other than the
email notification), but I was only able to argue about performance.

It's true that if at every action a user does I have to check "an event
queue", perhaps it's better to check on a regular basis (thinkin' of
dozens of users). You can argue that the checks could have a minimum
delay, but for every action you have to do a little amount of code (at
least to check if this minimum delay has passed).

Your solution, however, is very clever and coming with not too much
coding effort.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top