I have a program that currently works as a chat server. It’s a turn based card game with a chat box to communicate with the opponent. The chat stuff all works over the connection, but I’m to the point where I need to start sending certain cards to the opponent, so that when I play a card, my opponent will see it on his screen. I want the client computer to receive the object or collection of objects, figure out what the card type is based on its properties, and then put the card in the correct location. The sending and receiving part is what I don’t understand how to accomplish. From what I’ve read, this requires serialization and I just don’t know where to begin with this. Please assist! I’m using visual studio.
Share
Answering my own question again… I ended up creating a new class called card container which contains the cardType as a string and the card id as a int. There are also other properties for the card container so I know where the card goes. Then I serialized the card container (which is ‘cc’ in the following code) and sent it as follows:
The client listens on its TCPClient for anything at all and picks up the card with the following code:
Depending on what data the cardcontainer has determines which method the client now calls. For example, when this is received, the created cc is passed to my CardReceived method which then has a bunch of if, elseif statements. One of those would be