Monday 21 March 2016

I'm creating a multiplayer card game for learning purposes, and am confused about how to organise game data server-side and in the database. Any advice would be appreciated!

Hey guys! I've created a chat application before, and now want to get into something a bit more complicated. So I decided to re-create the board game Dominion. I'm using Express, MongoDB with Mongoose, and Socket.io, just as I did with the chat app before.Now, I'm confused about how to store card-related information in the database. A game basically has 17 reserve stacks of cards, a discard pile, plus a stack, a hand and a discard pile for each player (2-4 players per game).A few things I'm aware of:Card stacks, hands and discard piles can probably be handled with the same model, so I'll only refer to card stacks from now on.Reserve card stacks only contain one type of card, so I just need to save how many cards are left, and create a card when it is drawn from the stack.So, I see several ways of saving a game's stacks and cards in the database (or without it), and am confused about what technique would be better:1. Everything in the database I could create a mongoose model for card stacks and one for cards. Then each stack would be something like:MongooseModel CardStack:{ cards:array of ids } MongooseModel CardCellar:{ //cellar is the name of one of the cards in the game id:some_id, cost:2, ... } This means a lot of objects in the database! Late game, you can easily have dozens of cards in each of the players' hands, so it would be dozens to hundreds of objects per game. Seems like a lot? This also means lot's of models for the different card types.2. Less models Same as above, but using only one model for all card types:MongooseModel Card:{ id:some_id, name:'Cellar', cost:2, ... } In this case I would have only one collection for all cards in any game. Is that better?3. Use the database much less Since Dominion has only like 28 card types total, I could create a mongoose model for card stacks, and store card types in a js/json object that is not in the db. The idea being, that all card objects of one type in the database are exact duplicates. Seems unnecessary.MongooseModel CardStack:{ cards:array of ids } Object cardTypes:{ cellar:{ cost:2, ... } } This means a lot less objects in the database, but means I'll need to load a js/json file from the file system every time I want to access cards. Is this a bad thing? Actually, I probably could load it just once globally in the file with my socket.io game logic...That's my thoughts so far. Any advice would be appreciated :)

Submitted March 21, 2016 at 03:42PM by DJLaMeche

No comments:

Post a Comment