Page 1 of 1

suggestions

Posted: Wed Jul 02, 2003 6:18 am
by Drachlen
Me and a couple of friends plan on making some type of game thats webbased using PHP. I don't have any coding problems(right now), I'm just looking for a suggestion on checking what things the player has upgraded, and then displaying the next upgrade. What I mean by this is if the player does a such task, it enables soandso upgrade. What do you suggest i do for the coding part of this? I was thinking about making a bunch of fields for each upgrade, value 0 being they cant get it yet, and 1 being they can. Then a bunch of if statements checking what the field values are, but maybe this wouldn't be the best way.. Suggestions? :D

Posted: Wed Jul 02, 2003 6:47 am
by Stoker
I have no experience with online games and that, I would assume that if the "fields" doesnt need to be searched on or selected individually the quicker way to store and receive it may be as a (big) serialized array, and in the application pass this array around by reference all the time and when testing the capabilities just use if's as you mentioned..
if ($usersetting['beercount'] > 5) allow_barvisit(&$usersetting);

Posted: Wed Jul 02, 2003 7:02 am
by qartis
Okay, you've got a player playing your game, and his name is "MAD_DOG". Let's pretend what the player "MAD_DOG" wants to do, is to upgrade a "bar", to a "tavern". Note, the only diference between a "bar" and a "tavern" is that a "tavern" has 1000 health, instead of the 500 health that a bar has. The health of a building is used in battle, to identify when a building is just broken, and when it's completely demolished.

So, let's identify our tables:

players
  • player_id
    player_name
building_types
  • building_id
    building_name
    building_health
building_instances
  • id
    building_id
    owner_id
    health

In our game, there are many types of buildings, but for the sake of simplicity, we'll only speak of two: bars, and taverns. There are 2 entries into `building_types`:

Code: Select all

building_id: 11
building_name: bar
building_health: 500

Code: Select all

building_id: 12
building_name: tavern
building_health: 1000

MAD_DOG is a registered player, so there's an entry in `players`:

Code: Select all

player_id: 430
player_name: MAD_DOG

So he's logged on, going his thing, and he sees an impending battle. He decides he'll need an e-drink afterwards, so he'll want to fortify his bar. He's upgrading his bar to a tavern.

When he built this bar last november, the table `building_instances` got a new row:

Code: Select all

id: 1376
building_id: 11
owner_id: 430
health: 300
Okay, so he clicks on his bar, and he game returns the building id of '1376', the id of his bar. He then clicks 'upgrade'. The game has an array of buildings and their upgrades, and magically outputs the upgrade to a bar: the tavern.

We won't worry about the cost to upgrade right now, so he clicks on 'upgrade', and his bar becomes a tavern. In that time, the following change was done to table `building_instances`:

Code: Select all

id: 1376
building_id: 12
owner_id: 430
health: 1000
What just happened? Well, his bar is still the same building, id 1376 (the 1376th structure created in the whole game), so it's the same building, it's just a different building_type: it's now a number 12.

Referring back to the table `building_types`, an 11 was a bar, and a 12 is now a tavern. Every time someone clicks to see building 1376, they'll now see it's owned by MAD_DOG [user 430], its health is 1000, and it's a building_type 12. A simple SQL query to table `building_types`, and you can convert the number 12 into the type "tavern", so his bar became a tavern.



I can tell I've accidentally explained it in the most complicated way possible, so someone else can have a go at it too. But if you don't understand anything I just said, try first to understand the database layout, and the difference between a `building_instance`, and a `building_type`.