tags:

views:

73

answers:

3

Dears..

i try to make a small applet, this applet is about (Dots-lines)game, and i think all of us konw this game.

"Java applet to play the pencil-and-paper game of "Dots and Boxes", also known as "Lines and Boxes".

The game board is a rectangular grid. Dots are shown for the corners of the board squares. Players take turns drawing the lines that surround each square: top, left, right, and bottom. The player who completes a square by clicking on the fourth line gets that square. At the end of the game, the player with the most squares wins."

So, i make this applet and it's work with me, but my broplem is :

i should play this game by 2 users on network, until now i can only make it betwwen one user and computer.

so is their any idea to meake this applet work between 2 users or more on one network.

thanks for ur listining.

+1  A: 

This is a previous question, of sorts. See http://stackoverflow.com/questions/836007/java-applet-network-connection for info on network programming using applets.

rtenhove
+2  A: 

Browser based applets are not allowed to talk to any other domain then the one which loaded them. This is a security feature of the browser and java (signed applets may be allowed more permissions but things get complicated fast.) The easiest way to overcome this limitation is to have your server proxy information between two or more clients. This means that the clients only talk to the server but the server can talk to each client and can therefore act as a middle man or referee.

Chris Nava
+2  A: 

Have a look at rtenhove's linked answer to learn about the connection restrictions in Java.

Starting off from there the easiest implementation is probably to use a central server. Since you haven't stated your exact problem, I'll just give you an outline of something that could work.

You'll want a central server to accept client connections. You could choose to let players connect to a lobby and chat / pick opponents / etc, but that's a whole lot of hassle to implement..

What I would suggest instead is to have a look at the Google Image Labeler, which randomly puts users together to play a game, without even the option to communicate with eachother. After you pit two players against each other, it's up to you to

  • forward all the moves the players make,
  • to keep control over the game state (who's winning), and
  • to handle clients dropping or disconnecting
    (maybe seamlessly fall back to computer opponent?).

Since you seem to have already implemented most of the game logic, this setup could be the least amount of work to achieve a multi player experience.

If you run into any problems implementing the above setup, or need further explanation please feel free to ask more detailed questions..

Tim