First of all, excuse my English if I can’t explain myself very well, I’ll do my best.
I’m working on a strategy card game, where you place your cards on a board (4x4 squares) by turn.
You should only see the other player cards once he puts them on the board, but I have no idea how to do it.
I’ve tried sending the position to the server and the server is the one who syncs the squares with cards on them.
So my question is, how can I sync the card each player uses once it snaps to the grid?
well, if i understand your question properly, you are already sending the position to the server and is then the server who sends it back to the players, right?
if that’s the case, you can simply send also the card your player just played together with the position that card was played in. and here i think you could send one of the following:
either you send something that represents the card (e.g.: a specific string or id that both players and the server know what that is)
or you send the card itself. for this you can serialize the object (which needs to be serializable)
i find that the string representing the card is the easiest, since you can also see exactly what is sent and receive and can see if it is right or wrong. an example could be:
// define card types
public enum CardType
{
Red,
Magic,
Powerful
}
// Card class
public Card
{
public CardType type;
public Card(CardType newType)
{
this.type = newType;
}
}
// instance of card
Card theCardPlayed = new Card(CardType.Red);
// to send it, just send the variable, that will be one of the strings: "Red", "Magic" or "Powerful"
yournetworobject.send(theCardPlayed.type);
this code is just a reference, of course. hope that was helpful.