This project consists of two parts. In part 1, you are required to write a server program which can handle both chat messages and number guess game simultaneously. In part 2, one more game is added to part 1, it is a game that require player to find out which player is “the one”. The bonus of the project is to save all the chat history to the MongoDB and client will load the history and display when it is first connected to the server.
TCP ChatServer: Lab 6, Q3 (node.js server, java client)
TCP Guessing Game: Lab 6, Q4
WS & Socket.IO Chat: Topic 8 Demo (has html and Java client)
Socket.IO Guessing Game: Lab 8, Q1
JSON (Java): Topic 6 Demo (using GSON),
JSON (Java): Topic 8 Demo – See Client (another JSON lib)
Part 1 – Chat and Number Guessing Game: 40%
When a client is started, the player send his / her name to the server, after that he or she can start chatting or play the number guessing together with other players simultaneously. To distinguish chat messages and game messages, game messages are starting with a hash symbol followed by the name of the game and the input, for example:
Hello, my name is Peter. // A Chat message
#guess 35 // Make a guess, 35
Chat messages are broadcast to all connected clients in the following format:
<player name>: <message>
Besides, the following are displayed when a player is connected or disconnected:
SYSTEM: <player name> is connected
SYSTEM: <player name> is disconnected
For the number guessing game, server will generate a random secret integer between 1 and 100 (inclusive) and stored. Every time a player made a guess, a hint (smaller or larger than the secret) will broadcast to all the connected players in the following format:
GUESS@SYSTEM: <player name> made a [smaller / larger] guess: 35
When someone made a correct guess, the following message will be broadcast to call players:
GUESS@SYSTEM: <player name> WON! (The secret is reset, let’s play again!)
For any invalid input sent to the server, such as non-numeric strings, floating point numbers or input out of range, server will send the following message will be displayed on the client who has wrong input (not broadcast):
GUESS@SYSTEM: Invalid input, it should be an int from 1 to 100 (inclusive)
In this project, client and server are communicating using JSON String, client should convert user’s input to a JSON String and send to the server. The server will response or send message to client using JSON String too. After a client received a JSON String, it will parse and display appropriate message to the player.
You are required to design your own JSON String in this project.
Part 2 – WHO is the one: 40%
Part 2 is an add-on to Part 1; you should include Part 1 in this Part.
This game has two type of status, idle and playing. Any player can get the status by input:
The server will return the status and display either the following to the player:
WHO@SYSTEM: Idle or
When the game is idle, any player can start the game by
If the game can start successfully, the status will set to playing and the following message will be broadcast to all players:
WHO@SYSTEM: <name> starts the game.
If the state is already playing, the following message will be show to the player:
WHO@SYSTEM: The game is already started.
Note that, the game can only be started when there are 3 or more players, if there are not enough players, the following message will be show to the player:
WHO@SYSTEM: Not enough player (at least 3).
After the game is started, the server will randomly pick a player as “the one”, following message will be show to “the one” only:
WHO@SYSTEM: You are the one, hide yourself!
And the following message will send to all players:
WHO@SYSTEM: Let’s guess who is the one.
When the game is playing, players (except the one) can make guess by
#who guess <player guess>
If the player make a wrong guess, the following message will be show to the player and become inactive
WHO@SYSTEM: Incorrect guess, you cannot play until the game is restarted or ended.
If the number of active players is reduced to two, the game will be terminated, and the following message will be broadcast to all players:
WHO@SYSTEM: Two players left, <the one> won!
And the status will become idle again.
If the player make a correct guess, the following message will be broadcast to all players
WHO@SYSTEM: <player> find the one, <the one>. Game ended.
The one cannot make any guess, if he/she did, the following will be displayed:
WHO@SYSTEM: You are the one, you cannot make any guess.
There are some special cases when the game is playing.
本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝交易！
E-mail: firstname.lastname@example.org 微信:itcsdx