Jump to content
  • Advertisement
Sign in to follow this  
EarthboundMisfit

[web] Writing my first game. Choosing to make it browser based

This topic is 3638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am attempting to write my first game. Since my strong area is ASP.net development, i want to try to write a browser based game. The first thing that came to mind is implementing Carcassonne board game in the browser. I am not very creative, and since this is just an exercise for me, i think it's OK to use someone else's idea. When i sat down and tried to sketch it out, i am not sure what approach i should take. Most of the applications i created before were nothing more then just data input and retrieval, so i am finding it very hard to not think in terms of tables in the database. I am doing my best to translate it to classes in my head, but it just doesn't feel solid enough. What is the best place to start for creating a game like this?

Share this post


Link to post
Share on other sites
Advertisement
Relational DB Tables and OO Classes actually map to each other fairly easily.
If you want to think about your game in terms of classes (instead of in terms of tables), then maybe this will help:

Take these C++ classes. A dog is a animal, and links to a person:
class Person
{
string address;
}

class Animal
{
string name;
int age;
};

class Dog : public Animal
{
int age_in_dog_years;
Person* owner;
};

We can convert these classes into tables. The fields stored in the classes get copied straight into the tables, but each table also gets a new ID field as the primary key. Fields that would be represented as pointers/references in an OO class are stored as foreign-key integers in a table.
Table: Persons
Field: ID [integer] [Primary Key] (auto-increment)
Field: address [string]

Table: Animals
Field: ID [integer] [Primary Key] (auto-increment)
Field: name [string]
Field: age [integer]

Table: Dogs
Field: ID [integer] [Primary Key] (foreign key to Animals table)
Field: age_in_dog_years [integer]
Field: owner [integer] (foreign key to Persons table)


In the OO classes, Dog inherited from Animal (i.e. every dog is an animal). Therefore in the table structure, the Dogs table does not have a regular auto-incrementing primary key. The primary key of the Dogs table is actually a foreign-key that links to a record in the Animals table.
When adding a new Dog to the DB, you must add a new Animal record first, and then add a new Dog record using the new Animal ID.

If you have an Animal ID, and you want to find out if that particular animal is a Dog (i.e. equiv to the C++ dynamic_cast<Dog*>(pAnimal)) then you can just check if that ID appears in the Dogs table, e.g. SELECT * FROM Dogs WHERE ID = <my animal id> ...

Share this post


Link to post
Share on other sites
Probably better to use an Object Relational Mapper (ORM), though. There's little point struggling with converting between objects and tables, especially when it comes to inheritance, when 90% of the hard work can be done for you. ORMs translate classes to tables and objects to rows within that table, and also tend to simplify queries and joins. You lose a little performance, but I doubt that will be a problem when implementing browser-based board games.

EasyPersist is the first example I found on Google; no idea if it's any good. Looks like you mark your properties as persistent and the library handles the SQL for you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!