Network Tic-Tac-Toe (with Chat)
http://www.jars.com



Introduction:

This is my second Java application, the first being The Ultimate Jigsaw Puzzle. Network Tic-Tac-Toe has received a 'Top 25%, 4 Stars' rating from JARS - Java Applet Review Service. The objective was to understand the Networking API provided by Java. Unlike thousands of the other versions of Tic-Tac-Toe that U may find on the WWW, the USP(Unique Selling Point - a little bit of Marketing jargon never harmed anyone) of this implementation is the fact that, this version has re-incarnated itself as a Network Game. Wot that means is that U can play the game with another friend of U'rs who may be hundreds or even thousands of miles away from U, and yet get the feeling that Ur opponent is just across the table. The Chat facility embedded in this applet makes it even more easier for U to forget the geographical separation between U and Ur opponent.

Players Guide:

Pre-Requisites:
There following classes together make up the Network Tic-Tac-Toe application.
Ideally, the server class(TTTServer) should run as a Daemon process on the Web Server hosting this Application. The client class(NetworkTTT) would be embedded in an HTML page on the same server. This HTML page would act as the front end for all players. It is important for both the classes to be present on the same Host. The reason for this is simple. The Java security model prevents applets from contacting any machine other than the one that it came from. Two players can then visit the same site and play the game with each other, with the Webserver acting as the connecting link between them. But alas, ye good soul, things in the real world R far from ideal. Unfortunately, I do not have access to a Webserver which can run the TTTServer daemon process. So I have modified the logic, a little bit to allow U to test and play around with the Application on Ur own PC, and NOT as an applet in the browser. So, in effect, we would be using the same PC as a server and a client using the following steps. I am assuming that U already have the Java Runtime Environment(JRE) set up on Ur machine. OK, now we can start the game session. As U will see, the extremely simple design for the visual interface of the game, eliminates the need to have any doumentation for it. But just for the sake of completeness, I have included it here. There are only three components in the application. The main play-pad for the Tic-Tac-Toe game, an input box where U can type in any text for chatting and the display area where all chat messages from either side endup.
PLAYING THE GAME:
The odd-numbered player PLAYER1, PLAYER3, ..., always has the right to start the first game by clicking inside any of the nine boxes. The clicked box is filled with a "O" and this action is reflected in the second player's window. The first player now has to wait till the second player makes his move. All invalid clicks are ignored. After a game is over (either won or drawn), anyone can start a new game by clicking on any part of the work-area. The player who clears the entries, gets to start the next game.
USING THE CHAT FACILITY:
Type in Ur comments in the input box on the top of the window and press the ENTER key when U R done. The entered message is sent over to the other side and the display area is updated accordingly on both sides. Ideally, these windows would exist on two different PCs.
This image below shows a typical game session being executed on the same PC. The window on the left is controlled by PLAYER1 and the second one is controlled by PLAYER2.

Sample Game Session

Technical Stuff:

I have used the ServerSocket and Socket classes from the java.net package to handle the game sessions. Once a session has been established between two players, the communication is handled using SAMTP (Sameer's Awesome Message Transfer Protocol), which is a protocol that I have specially designed for the Network Tic-Tac-Toe game. SAMTP has been hailed by many, as the protocol for the next Millenium. U'll be hearing more about it in the future ;-)

Security Considerations and Limitations:


Future Enhancements:

I'll try to eliminate as many limitations as possible, from the list above, depending on how much free time I get. Any other ideas, that U may have to enhance the Application, R welcome.

Back to the Main Page
Hosted by www.Geocities.ws

1