Author: Tian Ma Class: ECE 491 last modified May 4/2004 ECE 491 Final Project Multiplayer Internet Card Game Goal of the Project The goals for this project are to demonstrate, experience, and explore all aspects of Java Internet Programming. This project will concentrate on three main areas of Java Java communications (Sockets) Graphical User Interface (GUI) Object Oriented Implementation Other Advance Features Problem Statement: In today s world, many people would like to play games with 2 or more persons rather than playing with boring computers. However, to have people gather in one place to start a game is not always a suitable solution. Finding partners might also be a problem. Solution: This project, I implemented a multiplayer card game to allow players to play a card game across Internet so people will not need to worry about finding partners and gather people in one location to play the game. With Internet, they can play the game with people all over the world. Main Features of this Application A public chat room as a GUI allows people to communicate with others and see whom they want to play with in private rooms. Players are connected by socket connection People can choose to play games in 10 private rooms. A game can be play between 2-4 persons through the internet with socket connection. Each games in each of the private room can be play simultaneously. A separate chat engine is built in each private rooms. So that people can still communicate to each other while they are in the game. Communications in the private rooms are restricted to each room, so that there messages in each of the private rooms will not be display in main room.
Tian Ma ECE 491 Final Project: Multiplayer Card Game Program Architecture ClientServer Conn Server Thread Server Engine Server Interface Client Interface Static Commands Command Interpreter Client Engine Main Client Engine Sort Cards GameRules PlayInfo StartPlayer Cards Game Engine Game Game GUI methods GameGUI Game Room Info GameGUI Commands MainRoom GUI EntranceGUI Game Room Location
Explanations: The overall architecture is pretty much self-explanatory. Double arrow indicate bidirectional dependencies (dependent in both way). One arrow denotes single dependency. Instead of each of the classes I will explain some key classes since you can find all the explanations in the documentations. ). The game class basically implements the game. One can see there are many class associated with game. The TestServer class runs the server. The TestApplet.html is use for people to accessing the server. The client engine handle all the actions execute by the client (e.g. chat, enter game room, play cards, etc ). The server engine handle all the actions execute by the server. The client server connection connects the client engine and server engine through server interface and client interface respectfully. From the diagram above, first the clients access the TestApplet it will lead him to enter the entrance GUI, the action listener will sends actions to the Client Engine and the client engine will sends action to the client interface and so on following the diagram until the server gets it. After the server get the actions, it interpret what action to be taken (command interpreter), then perform the necessary tasks in the engine. If all goes well, players are connected and proceed to MainRoom GUI. The MainRoom GUI basically follows the same principles as it implements listeners and sends actions to the client engine, so as other GUI (e.g. game gui commands). So basically, the flow of the program is behave having a GUI listens the command sends to Client Engine and Client Engine performs all the actions. Game Introductions: The card game that I implemented is pronounce as Da Lao Er in Chinese, or translated in English as Big 2, or pronounce as Daifugo in Japanese, or translated in English as Big rich. This is a very popular card game in Asia. The reason I choose to implement this card game is that this is the only card game that I enjoy playing and play well. Whatever name you want to called it, all we care is how to play? There are so many rules of playing it. So I will have my own rules too. These are the rules that I normally playing with my friends Tian s Game Rules Game Objective The objective of the game is to be the first one to get rid of all of your cards by playing them. Cards can be played singly or in certain playable combinations. The first person who get rid of all the cards wins, while others score penalty points. This Game can be play by 2 4 players (4 players is the best).
Playing the game: The player who holds a diamond 3 (or the smallest card if less than 4 player) will begins and must play this card, either by itself or as part of a playable combination. The person to this player's right plays next, and follows the counter clockwise direction. N W E S At your turn you must either pass (play no cards) or beat the previous play by playing a higher combination of the same number of cards. Single card must be beat by single card, pairs must be beat by pairs, triples must be beat by triples, and 5 cards must beat 5 cards. This continues for several rounds if necessary, until all but one of the players pass in succession, or no one being able or willing to beat the last play. The person who played highest (all the others having passed) wins the turn and begins again by playing any card or legal combination of cards. You are never under any obligation to beat a card or set of cards just because you are able to - you may always choose to pass and keep your high cards for a better opportunity. Passing does not prevent you from playing when your turn comes round again. Card Ranking The ranking of the cards from smallest to largest are the following: 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < Jack < Queen < King < Ace < 2 Suits Ranking for the card have the same number the rank will define by the Suit diamonds<clubs<hearts<spades Notations: d diamond c club h hearts s - spades Playable Combinations: Single card
The ranking of the single cards from smallest to largest are the following: 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < Jack < Queen < King < Ace < 2 for the card have the same number, the rank will define by a Suit diamonds<clubs<hearts<spades For example, a 3d < heart 3h 2 cards (Pairs) A pair of cards who have the same number (faces). For example, a pair of 2s, pair of Jacks. The rank is determine by the rank of the cards. If the two pairs have the same number, their rank will be determine by their suits. For example, (jack d, jack h) < (jack c and jack s) 3 cards (Triples) Three cards of the same number. 3 Aces, 3 tens, etc. 5 cards Ranking: Straights<Flush<Full House<Four of a kind<straight Flush 1. A Straight consists of five cards of consecutive rank with mixed suits. A straight with higher ranks beats a lower one, irrespective of the suits of the cards. When the ranks are the same, the suit of the largest card determines which is higher. For example, 3d 4c 5d 6c 7d < 3c 4d 5c 6d 7s, since 7d<7s 2. A Flush consists of any five cards of the same suit. A flush in a higher suit beats a flush in a lower suit, irrespective of the ranks of the cards. Between two flushes in the same suit, the one with the largest card determines the rank of a flush. For example, 3d 5d 6d 7d 8d < 3d 6d 8d 9d 10d, since 8d<10d 3. A Full House consists of three cards of the same number and a pairs; between two full houses, the one whose triple is of higher rank is better. For example, 5d 5c 5s 6d 6d < 8d 8c 8h 3c 3s
4. Four of a kind (or quads) are made up of all four cards of the same number, plus any fifth card. The fifth card must be included - four equal cards by themselves are not a playable combination. Between two fours of a kind, the rank of the four cards determines which is higher. 5. A Straight Flush consists of five consecutive cards of the same suit, twos ranking below threes and aces ranking high or low, as in straights. The rank of the highest card determines which of two straight flushes is higher; between two equal ranked straight flushes, the one in the higher suit is better For example, 3d 4d 5d 6d 7d<3h 4h 5h 6h 7h Scores: The players other than the winner score penalty points for the cards remaining in their hands. If you have: 1-7 cards, one penalty point for each cards 8 9 cards, 2 points per card, total of 16, 18 points respectably 10 12 cards, 3 points per card cards, total of 30 33, 36 respectably 13 cards 4 points per card, total of 52 points, because you never played any cards at all. The winner, having no cards, gets no penalty points for the hand.
Step by Step Tutorial how to Run the program: Note: This project is tested on PC running with Windows XP Professional Edition, with Internet Information Service (IIS) installed. First compiled all the files and type at command prompt to start the server javac *.java java Test Server See below: Open up the TestApplet.html file, entrance frame should pop up see below: You can change the host address in the input textfield or use local host for default. I tested my program using localhost.
Now: Enter your name Click one of the icons below to enter, the image you clicked will be use to denote your identity later in the game Error handing will be alert by dialog boxes. For example, name length, server error, etc.
If you enter successfully, the entrance window should close and you should be able to enter main room Main Room In main room one can chat and communicate publicly. Simply type the messages in the input filed and clicked chat. The intention of this is to let people communicate and choose whom they want to play with. Each user can have a choice of 10 private game rooms, therefore a maximum 10 groups can be played through the server simultaneously. Once they enter the private game room, a game can be started, and they conversation will be fixed within their game room.
Clicked the buttons on the lower right to enter the game room. The following picture illustrated Prof.Pyo and I have joined. I am the 1 st person entered the game and name is label with (1stP). Until the game has started, other people who wish to entered are welcome until it hits the size limit which is 4. Now a new player Shashank has enter the game room wondering if anybody if the game room. But since Prof.Pyo and I are in the game room, therefore Shashank just sees himself in the main room.
Shashank sees 2 player in the game room 0, therefore he choose to enter game room too. Also another player name other who are also enter GameRoom0. Note: only 1 st person enters the game can start the game. In this case it s me, so I clicked the start button.
According to the rules, the one who hold the smallest card (3d) get s to play first then play in CCW direction. In this case, I am lucky in enough to play first. Notice my name is color white signal everybody it is my turn. There is no combination of diamond 3 I can only play with a single card, so I will play just a single card. Use a mouse to select the card, the card should pop up, if it s your turn and you are playing according to the rules. After clicking the button you card will be display in the center. Now my card has popped out. The next player who gets the turn is Prof. Pyo, since we play in the CCW direction, his name is colored white to signal his turn. (See below)
Since this is 3d (diamond 3), the smallest card everybody would like to beat this card. Below, Prof. Pyo will play 5 to beat this card.
Now the turn will be set to Shashank will all others are OBSERVER. We can continue to play this card until no body wants to beat this card. If they don t want to beat this card, they can click pass to give the turn to others. Let s consider Shashank click PASS. He will give the turn to other to play the card. Let s consider other and I also don t want to beat this card. Then Prof. Pyo win s the turn since no body is willing to beat his card. He can play whatever combination he wants to get rid of the cards. Now, Prof. Pyo play straights: 5 6 7 8 9
In this case, Shashank can beat him with straights 6 7 8 9 10, since the last card 10>9 to get rid of five cards.
Other can beat him with 8 9 10 J Q (see below)
I can beat her by full house, since full house > than any straights Following the same patterns. Consider I win the game.
Other players score penalty points depend on how many cards they have. 1 7 cards same points as number of cards 8 9 cards double their points on the number of cards, total of 16, 18 respectably. 10-12 cards triple their points on the number of cards, total of 30,33,36 respectably 13 cards 13*4=52 points Only I can restart the game by clicking start since I am the 1 st P. (see below) Click the Exit button on the game will go back to Mainroom, and click x on the frame will close the applet You can play this game with 2 persons and 3 persons following the same rules, however, I highly recommand playing by 4 persons since it is much challenging.
Illustration of two Person Game Illustration of 3 person Game
There are 10 game rooms available and each groups can be play simultaneously. Chatting in the game are private as their messages are showed with respect to their game rooms. Time (hours) spend on this project Weekly hours spend on final project Week of 3/7-3/13 8 Week of 3/14-3/20 12 Week of 3/21-3/27 25 Week of 3/28-4/3 15 Week of 4/11-4/17 16 Week of 4/18-4/24 28 Week of 4/25-4/31 8 Total hours 112 Conclusion: This multi-player card game project have demonstrated important aspects of Java Internet and especially how how people communicate through the internet using Java. This project is highly related to what we learned in our class. It captures almost every topics we have covered such as: GUI programming, Networking, Applets, Inheritance, and more. The game Da Lao Er is a card game that I really enjoy playing. Since my implementation is done in an Object Oriented way, it can be extended to play other card games as well with no hardship. Although this project took me 112 hours to complete, I truly enjoyed the entire process, except for debugging! This project enhanced my skills in Java and it built-up my confidence on what I can do with Java. Furthermore, it has demonstrated my thorough understanding of Java Internet programming and my ability to develop Java Internet application.
This document was created with Win2PDF available at http://www.daneprairie.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only.