2 Player M:TG Online Card Game...

I’m developing an online card game for Magic: The Gathering that will, at first, be only a 2 Player game. I am proficient in Java, but the Socket Programming is where I’m the most ignorant…

Firstly, I want this to be as live action as possible (basically, if I move a card on the table, then the other player sees me moving the card)…I don’t think this type of animation is too demanding, so I’m planning on using TCP/IP.

My questions is, once the connection between the two players is made (when connecting, one serving as the server, and the other the client), am I going to be able to have each of the players be able to send and receive messages simultaneously? And if so, how do I do that?

I guess my ignorance of SocketProgramming is showing through now, but I have this notion that in order to receive something, you have to be listening for that particular someting. Is it possible to have the GUI running on ONE thread, and when a message is needed to be sent, I can send that on ANOTHER thread? While simultaneously listening on yet ANOTHER thread for information coming from the other client (in case he plays/moves a card)?

Once again, I’m new to this socket programming thing…and any input will be helpful. Also, if I’m completely missing something, or if you think i’m looking too much into this, please, your other suggestions are welcome.

Thanx…

LordWilson

With just two players, use the following pattern (this is the simplest solution, but not the most intelligent - more intelligent methods aren’t appropriate for such a simple case).

One client opens a ServerSocket, and dedicates a Thread to:

  • listening to the ServerSocket (SS)
  • Fetching a Socket from the SS when an incoming connection occurs.
  • …plus all the stuff we’re about to do with the Socket

Each client dedicates two threads (the first client above can have one of these as a re-use of the SS thread it already has) to the Socket.

For each client, one thread is attached to the Socket.getInputStream(), the other on Socket.getOutputStream(). The Threads have various public methods like [for a thread on an OutputStream:] “sendTextMessage( String message )” or [for a thread on an InputStream] “addStreamListener( StreamListener )”.

Note: the StreamListener is a class (or preferably an interface) you write that has methods like “receivedTextMessage( String message)”. If it’s an interface, you could have your GUI implement it, and whenever “receivedTextMessage” is called, it could update a JList of received messages, and call repaint().

That’s the process, hopefully it makes sense? I’m half-asleep right now, and have checked what I wrote, and it seems sensible, but I’m too tired to know for sure :(.

Not to be a stick in the mud, but I know many of the artists for M:tG and what they have said of WoTC, which is now part of Hasbro, is that they are ruthless when it comes to licensing and copyrights. I would advise you to beware of any sort of violations.

who the heck invented legal issues anyway!!??

javatypo,

Two sides to that coin, unfortunately. Those of us who want to take something and make it better, as I see LordWilson is trying to, and those of us who want to profit from the hard work we’ve put in (the artists who originally created the art, and are usually paid on comissions).

In between that are pirates, both corporate (those who actually hold the copyrights, and in some cases, abuse them) and individuals (who steal other people’s work without regard to the ramifications of doing so).

It’s not a fun spot to be in. The only reason I brought it up is that Hasbro is KNOWN to enforce their copyrights, so even if LordWilson was writing this game to teach himself programming, or as an experiment, they might go after him.

Of course, MtG could never be produced as a commercial game without their express permission. But that’s not my point.

Yeah, be careful. The Wizards basically claim they own the concept of a customisable card game, and have vigorously defended that claim in the past. Watch your step.

Not that I agree with them in this case, however! I find the concept of a single company laying claim to an entire genre of games despicable.

Charlie,

I am working with a CCG developer who has specifically run up against Wizards of the Coast on this. Just so you know how crazy it can get:

  1. they have a patent for the MtG style of CCG

  2. they vigorously defended it.

  3. Hasbro bought them specifically to get hold of that patent, as it applies to two games they wanted: Yu-Gi-Oh! and Dragonball Z.

So yes, they are dangerous.