Java - Multiplayer card game

Hey folks,
I’m in the midst of building a card game modeled after a popular card game called “Dominion”
(http://en.wikipedia.org/wiki/Dominion_(card_game)).

I’ve been programming in Java for quite some time now but my job has never required me to produce any sort of GUI nor have I ever produced an application is multiplayer (I’m an integration’s specialist). Note: This game is intended to be used by 2 to 8 people (in total I mean, across 1-4 games). I don’t plan on distributing it or experiencing a large amount of load for the multiplayer component. The game is just going to be distributed to a few close friends who live away.

I have already laid the foundation for this game. I have modeled players, cards, card actions, win states, turn orders, etc.

I’m not overly concerned about the multiplayer concept of the game right now. I would like to know the best way to approach the GUI. I’ve been exploring Java Applets and I think I have an understanding of how to implement the game using an applet. From what I’ve read applets can be pretty slow and it’s very limiting to the size of the images I can use.

Last night I started trying to figure out how user interaction was going to work. ie: How do I detect that the user has moused over a particular card (basically, inside one of many rectangles on the screen), and I was thinking to myself “There has to be a better way”.

So, in your opinion j-g, what’s the best way to approach this? Keeping in mind:The game will eventually be multiplayer.

For what you will be doing, I personally think a java applet will more more then fine. They can have a few hiccups but for a card like game, it really wont be a problem whatsoever.

I personally enjoy applets first. Utilizing either java2d, pulpcore, or slick2d.(among many other great ones)

for cards, you have several choices. You could use a swing like interface and just use a jButton of some kind with custom icons. You could construct your own button class.
http://download.oracle.com/javase/tutorial/uiswing/TOC.html

Although you have “cards”, do you need to interact with them the same way youd interact with a card game like solitaire? (i.e. drag/drop, show hidden, move stacks, dbl click) or do you just have a few choices each turn?

you can also make fullscreen applets if that’s what you meant by limited image sizes?

There are basically three places a card can live.

+ A card can be in a supply

  • Cards that can be bought: will require a mouseover to show additional details about the card, upon clicking on the card you are presented with the option to buy (add to your deck) or cancel. (Viewable to all players)
    +Note: These cards are always in a fixed position, determined when the game is init()

+A card can be in your hand
+Again, these cards can be moused over to display additional text about the card, clicking the card gives you the option of playing it or canceling the request. (Viewable only to the player who owns the card)
+Some cards allow you to draw additional cards to your hand from your deck. This is commonly exploited to allow you to draw potentially dozens of cards to your hand.

+A card can be in play
These cards may only be moused over for additional details. No additional actions can be taken on these cards.

I was talking about the amount of space they take up (in kb), not actual pixels on the screen. There’s twenty or so cards in the base set of dominion but expansions can add up to a hundred or more.

How would an applet limit that? :\

Is this not something I should be worried about?

Sorry, I’m new to this. I assumed loading a lot of images would bog down the works?

Depends on how big the cards are, and if memory does become an issue (I don’t think it will) you can load images on demand and THEN keep them in memory.

Well, how big are the cards?

Just using a single image, you could theoretically have 100,000+ of that image on the screen at once.(As in another post on JGO, they had a competition and plenty of people achieved that)

Even if you had a couple hundred unique images/cards at 10-100kb, you could still probably have in the thousands. But all depends on what quantity you are talking about and what type of system specs you are designing for.

In my experience simply showing images are never ever an issue. They start to hurt more when you start doing things with alpha, rotated aliasing, blending or real time manipulation/generation/modification of images in large quantities.(quantities being hundreds, if not thousands++ of a half dozen type of manipulation per image)

You can get a rough estimate of how much memory you use if you take the image and multiply a pixel’s size by the image’s size and by the total amount of images.

So if you’re using high quality images with alpha like:

BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB)

and you have 100 of those you can do

500 x 500 x 4 x 100 = 100000000 bytes

that’s around 95 megabytes which is pretty manageable, and chances are you won’t even need alpha.

Okay, this eases my concern. There’s nothing crazy happening with these cards other than sliding around the screen when you purchase or play a card.

At most there will be 20 unique images of cards on the screen at once. With potentially multiple copies being drawn at once. The cards themselves are around 50kb each.

To answer your original question, you would have a MouseListener and just loop through all your rects and call card.contains(point). Good luck!

Please let me know if you finish this game. I am in the same situation as yourself, - I own Dominion + Expansions, but get to play it too rarely with my friends because some of them live far away.

Good luck!

Thanks for the help guys, and addictman. I shall do exactly that.