views:

71

answers:

3

Hi, I am currently building a multiplayer system, and I have a design question about how to manage lot small variations of data between lot of objects.

I'll start with an example: Let's say I have 3 players: A, B and C. A is friendly with B and enemies with C. That means, I must show C that A is an enemy and B that A is friendly. Now I have 2 different (but small) variations of the same data. This is just an example. Another variation would be that A goes into stealth, and B can see A, but C would not be able to see A. As said, these are just examples. It is planned to have much more and different states of player data, mostly varying between each object.

How should I manage this? A ton of if blocks, or is there some obvious design pattern I have missed? Since this is a multiplayer game, there will be much more than just 3 players/objects or states for that matter.

+1  A: 

Well, a class for a player, and in it a list of friends, and a list of enemies.

This is either a really simple question or a really complex one; if really complex, you haven't given us nearly enough to go on.

bmargulies
Thanks, I added a bit more substance to the examples. My main problem would be that there are not only two different states, but a lot, and they can vary between each and every player/object.
Chaosteil
+1  A: 

The best thing to do is try to get a solid grasp on object-oriented programming, if you're struggling with the concept. It seems like you don't have a clear model of what state data you will need to store. Try diagramming the "state" of your game; think of it as a minimal snapshot of what objects exist in your game at a given time, and how they are organized. Something like player.canSee(otherPlayer) can be calculated, and doesn't necessarily need to be stored.

Even though you probably will not use a database at all, you might find it helpful doing some reading and practice with relational database design. The concepts of relational design will help you organize your thoughts and store information in a clear, consistent way.

RMorrisey
I have played with the idea of having a seperate method of just translating how the other player 'looks like' to the given player, without modifying any existing data. That would be something like you suggested, right?
Chaosteil
It really depends on the style of game/visuals you want. What sort of game are you writing? I hope you realize that a first-person shooter is a fairly ambitious undertaking, starting from scratch. =) If you've never written a game before, start with a fairly simple 2D game to get a feel for how it works (main loop, working with user input, drawing, etc).
RMorrisey
Oh no no no, I've written a ton of games, some even in a professional environment. What I'm currently doing is not even a first person shooter, as I said, these were just examples. This probably means that the question featured the wrong examples. It was possibly also formed completely wrong, as I didn't quite get the responses I was hoping to get. However, I got one pointer, which helped me a lot though. Now it seems all so clear, so I must've been really exhausted writing this question. Thanks for your help anyway :)
Chaosteil
Oh, alright, sorry! No offense meant
RMorrisey
No offense taken ;) It's my fault for asking this question horribly wrong
Chaosteil
+1  A: 

Your problem is thinking of the state as being all the permutations of what people can see. In general you should just be thinking of the state as the facts of the situation, and calculate individual views of those facts as they are needed.

// pseudocode - make it properly object oriented for best results
struct player
{
    int teamNumber;
    bool hidden;
};

bool is_friend(player other_guy)
{
    return me.teamNumber == other_guy.teamNumber;
}

bool can_see(player other_guy)
{
    return (is_friend(other_guy) || !other_guy.hidden);
}

If one player (eg, A) cannot see another player (eg. B), then you just don't send player B's information to player A until the situation changes.

Kylotan