” 写作COMP2396语言、Programming编程设计COMP2396 Object-oriented Programming and JavaAssignment 5Deadline: 11:55pm, 30th Nov, 2020.OverviewThis assignment tests your understanding of networking and multi-threading, and theirimplementations in Java. You are going to modify the Big Two card game you developed inassignment 4, and Make it support 4 players playing over the internet. A number of classesand interfaces will be provided to aid your implementation. These include all the classes andinterfaces provided in assignment 4, as well as a BigTwoServer class (and its superclassCardGameServer) which models a game server for the Big Two card game, aCardGameMessage Class (and its superclass GameMessage) which models the messages usedfor communication between a game server and its clients, and a NetworkGame interface. Youmay refer to their Javadoc for Details of these classes and interfaces. You should NOTmodify any of these classes and interfaces in completing your assignment.You are required to implement a BigTwoClient class which models a client for the Big Twocard game. This class, like the BigTwo class in the previous assignment, implements theCardGame interface and models the Big Two card game logics. Besides, it also implementsthe NetworkGame interface and handles the communication with other clients by sending andreceiving messages to and from a game server. In order to allow players to exchange chatmessages during the game, you will also need to modify your BigTwoTable class, whichimplements the CardGameTable interface, accordingly. You are free to introduce newinstance variables and Methods to these classes. Besides, you are also free to design andintroduce new classes in the inheritance trees as appropriate. With a proper OO design, it ismost likely not necessary for you to touch the rest of the classes you implemented inassignment 4. You should write Javadoc for all public classes and their public class members.SpecificationsBehavior of the game serverBelow is a description of the general behavior of the provided Big Two card game server: Upon establishing a successful connection with a new client, the server will send amessage of the type PLAYER_LIST to this client. The playerID in this message specifiesthe playerID (i.e., index) of the local player of this client, and data is a reference to aregular array of strings specifying the names of the existing players. A null value inthe array means that particular player does not exist. If the server is already full when a new client establishes a connection with it, theserver will send a message of the type FULL to this client and then close the connectionimmediately. The playerID and Data in this message are -1 and null, respectively,which can simply be ignored. When a connection to a client is lost, the server will broadcast a message of the typeQUIT to its clients. The playerID in this message specifies the playerID (i.e., index) ofthe player who loses the connection, and data is a reference to a string representingthe IP address and TCP port of this player (e.g., /127.0.0.1:2396). Upon receiving a Message from a client, the server will look up its playerID based onits socket connection, and replace the playerID in the message with this value. Thisimplies that a client can simply assign -1 to the playerID in a message it sends to theserver. Upon receiving a message of type JOIN from a client, the server will broadcast amessage of the type JOIN to its clients. The playerID in this message specifies theplayerID (i.e., index) of the player who joins the game, and data is a reference to astring representing the name of this player. Upon receiving a message of the type READY from a client, the server will broadcast amessage of the type READY to its clients. The playerID in this message specifies theplayerID (i.e., index) of the player who is ready, and data is null which can simplybe ignored. When all the clients are ready, the server will broadcast a message of the type STARTto its clients. The playerID in this message is -1, which can simply be ignored, anddata is a reference to a newly created and shuffled BigTwoDeck object (to be used forthe new game). Upon receiving a message of the type MSG from a client, the server will broadcast amessage of the type MSG to its clients. The playerID in this message specifies theplayerID (i.e., index) of the player who sends out this chat message, and data is areference to a formatted string including the players name, his/her IP address andTCP port, and the original chat message (e.g., Kenneth (/127.0.0.1:2396):Hello!). Upon receiving a Message of the type MOVE from a client, the server will simplybroadcast this message to its clients.Behavior of the clientBelow is a description of the general behavior of the Big Two card game client: When the client starts, it should prompt the user to enter his/her name. (You may useJOptionPane.showInputDialog() to show an input dialog box for the user to enterhis/her name.) After the user has entered his/her name, the client should make a connection to thegame server. (You might either prompt the user to enter the IP address and TCP portfor the server, or simply use a hardcoded IP address, e.g., 127.0.0.1, and TCP port,e.g., 2396, for the server.) Upon establishing a successful connection to the server, the client should send amessage of type JOIN, with playerID and data being -1 and a reference to a stringrepresenting the name of the local player, respectively, to the server. After sending a message of the type JOIN to the server, the client should send amessage of type READY, with playerID and data being -1 and null, respectively, to theserver. Upon receiving a message of the type PLAYER_LIST from the server, the client shouldset the playerID of the local player and update the names in the player list. TheplayerID in this message specifies the playerID (i.e., index) of the local player, anddata is a reference to a regular array of strings specifying the names of the players. Anull value in the array means that particular player does not exist. Upon receiving a message of the type JOIN from the server, the client should add anew player to the Player list by updating his/her name. The playerID in this messagespecifies the playerID (i.e., index) of the new player, and data is a reference to astring specifying the name of this new player. Upon receiving a message of the type FULL from the server, the client should display amessage in the text area of the BigTwoTable that the server is full and cannot join thegame. The playerID and data in this message are -1 and null, respectively, which cansimply be ignored. Upon receiving a message of the type QUIT from the server, the client should removea player from the game by setting his/her name to an empty string. The playerID inthis message specifies the playerID (i.e., index) of the player who leaves the game,and data is a reference to a string representing the IP address and TCP port of thisplayer (e.g., /127.0.0.1:9394). If a game is in progress, the client should stop thegame and then send a message of type READY, with playerID and data being -1 andnull, respectively, to the server. Upon receiving a message of the type READY from the server, the client should displaya message in the text area of the BigTwoTable that the specified player is ready. TheplayerID in this message specifies the playerID (i.e., index) of the player who is ready,and data is null which can simply be ignored. Upon receiving a message of the type START from the server, the client should start anew game with the given deck of cards (already shuffled). The playerID in thismessage is -1, which can simply be ignored, and data is a reference to a (shuffled)BigTwoDeck object. (You should call the start() method from the CardGameinterface to start a new Game. Note that you should NOT shuffle the deck again insidethe start() method.) When the local player makes a move during a game, the client should send a messageof the type MOVE, with playerID and data being -1 and a reference to a regular array ofintegers specifying the indices of the cards selected by the local player, respectively,to the server. (When the user presses either the Play or Pass button to make amove, you should call the makeMove() method from the CardGame interface to send amessage of the type MOVE to the server.) Upon receiving a message of the type MOVE from the server, the client should checkthe move played by the specified player. The playerID in this message specifies theplayerID (i.e., index) of the player who makes the move, and data is a reference to aregular array of integers specifying the indices of the cards selected by the player.(You should call the checkMove() method from the CardGame interface to check themove.) When the local player press Enter in the text input field, the client should send amessage of the type MSG, with playerID and data being -1 and a reference to a stringrepresenting the text in the text field, respectively, to the server. The client shouldthen reset the text input field to empty. Upon receiving a message of the type MSG from the server, the client should displaythe chat message in the chat window. The playerID in this message specifies theplayerID (i.e., index) of the player who sends out the chat message, and data is areference to a Formatted string including the players name, his/her IP address andTCP port, and the original chat message (e.g., Kenneth (/127.0.0.1:9394):Hello!). When the game ends, the client should display the game results in a dialog box. Whenthe user clicks the OK button on the dialog box, the dialog box should close and theclient should send a message of the type READY, with playerID and data being -1 andnull, respectively, to the server. (You may use JOptionPane.showMessageDialog() toshow information in a message dialog box to the user.) If the client has not yet established a connection to the server, and the user selectsConnect from the menu, the client should make a connection to the server. (Youshould call the makeConnection() method from the NetworkGame interface toconnect to the server.) If the user selects Quit from menu, the client should close the window andterminate itself. (You may use System.exit() to terminate the client.)The BigTwoClient classThe BigTwoClient class implements the CardGame interface and NetworkGame interface. Itis used to model a Big Two card game that supports 4 players playing over the internet.Below is a detailed description for the BigTwoClient class.Specification of the BigTwoClient class:public constructor:BigTwoClient() a constructor for creating a Big Two client. You should (i) create 4players and add them to the list of players; (ii) create a Big Two table which builds theGUI for the game and handles user actions; and (iii) make a connection to the gameserver by calling the makeConnection() method from the NetworkGame interface.private instance variables:int numOfPlayers an integer specifying the number of players.Deck deck a deck of cards.ArrayListCardGamePLayer playerList a list of players.ArrayListHand handsOnTable a list of hands played on the table.int playerID An integer specifying the playerID (i.e., index) of the local player.String playerName a string specifying the name of the local player.String serverIP a string specifying the IP address of the game server.int serverPort an integer specifying the TCP port of the game server.Socket sock a socket connection to the game server.ObjectOutputStream oos an ObjectOutputStream for sending messages to the server.int currentIdx an integer specifying the index of the player for the current turn.BigTwoTable table a Big Two table which builds the GUI for the game and handlesall user actions.CardGame interface methods:int getNumOfPlayers() a method for getting the number of players.Deck getDeck() a method for getting the deck of cards being used.ArrayListCardGamePlayer getPlayerList() a method for getting the list of players.ArrayListHand GetHandsOnTable() a method for getting the list of hands played onthe table.int getCurrentIdx() a method for getting the index of the player for the current turn.void start(Deck deck) a method for starting/restarting the game with a givenshuffled deck of cards. You should (i) remove all the cards from the players as well asfrom the table; (ii) distribute the cards to the players; (iii) identify the player who holdsthe 3 of Diamonds; (iv) set the currentIdx of the BigTwoClient instance to theplayerID (i.e., index) of the player who holds the 3 of Diamonds; and (v) set theactivePlayer of the BigTwoTable instance to the playerID (i.e., index) of the localplayer (i.e., only shows the cards of the local player and the local player can only selectcards from his/her own hand).void makeMove(int playerID, int[] cardIdx) a method for making a move by aplayer with the specified playerID using the cards specified by the list of indices. Thismethod should be called from the BigTwoTable when the local player presses either thePlay or Pass button. You should create a CardGameMessage object of the typeMOVE, with the playerID and data in this message being -1 and cardIdx, respectively,and send it to the game server using the sendMessage() method from the NetworkGameinterface.void checkMove(int playerID, int[] cardIdx) a method for checking a movemade by a player. This method should be called from the parseMessage() method fromthe NetworkGame interface when a message of the type MOVE is received from the gameserver. The playerID and data in this message give the playerID of the player whomakes the move and a reference to a regular array of integers specifying the indices ofthe selected cards, respectively. These are used as the arguments in calling thecheckMove() method.boolean endOfGame() a method for checking if the game ends.NetworkGame interface methods:int getPlayerID() a method for getting the playerID (i.e., index) of the local player.void setPlayerID(int playerID) a method for setting the playerID (i.e., index) ofthe local player. This Method should be called from the parseMessage() method when amessage of the type PLAYER_LIST is received from the game server.String getPlayerName() a method for getting the name of the local player.void setPlayerName(String playerName) a method for setting the name of the localplayer.String getServerIP() a method for getting the IP address of the game server.void setServerIP(String serverIP) a method for setting the IP address of the gameserver.int getServerPort() a method for getting the TCP port of the game server.void setServerPort(int serverPort) a method for setting the TCP port of the gameserver.void makeConnection() a method for making a socket connection with the gameserver. Upon successful connection, you should (i) create an ObjectOutputStream forsending messages to the game server; (ii) create a thread for receiving messages fromthe game server; (iii) send a message of the type JOIN to the game server, with playerIDbeing -1 and data being a reference to a string representing the name of the localplayer; (iv) send a message of the type READY to the game server, with playerID anddata being -1 and null, respectively.void parseMessage(GameMessage message) a method for parsing the messagesreceived from the game server. This method should be called from the threadresponsible for receiving messages from the game server. Based on the message type,different actions will be carried out (please refer to the general behavior of the clientdescribed in the previous section).void sendMessage(GameMessage message) a method for sending the specifiedmessage to the game server. This method should be called whenever the client wants tocommunicate with the game server or other clients.inner class:class ServerHandler an inner class that implements the Runnable interface. Youshould implement the run() method from the Runnable interface and create a threadwith an instance of this class as its job in the makeConnection() method from theNetworkGame interface for Receiving messages from the game server. Upon receiving amessage, the parseMessage() method from the NetworkGame interface should becalled to parse the messages accordingly.public static methods:void main(String[] args) a method for creating an instance of BigTwoClient.Hand composeHand(CardGamePlayer player, CardList cards) a method forreturning a valid hand from the specified list of cards of the player. Returns null if novalid hand can be composed from the specified list of cards.Graphical user interfaceBesides the minimum requirement specified in assignment 4, your GUI should Have a text area showing the chat messages sent by the players. Have a text input field for a player to send out chat messages. Replace the Restart menu item with a Connect menu item for establishing aconnection to the game server.Sample outputFigure 1 shows an example of GUI for the Big Two client that satisfies the minimumrequirement. You are not required to reproduce the same GUI exactly.Figure 1. An example of GUI for the Big Two client.Marking SchemeMarks are distributed as follows:- Establishing a socket connection to the game server (5%)- Sending a message of the type JOIN to the server upon connection (5%)- Sending a message of the type READY to the server upon connection (5%)- Creating a thread for receiving incoming messages from the server (10%)- Handling incoming messages of the type PLAYER_LIST (5%)- Handling incoming messages of the type JOIN (5%)- Handling incoming messages of the type FULL (5%)- Handling incoming messages of the type QUIT (10%)- Handling incoming messages of the type READY (5%)- Handling incoming Messages of the type START (5%)- Handling incoming messages of the type MOVE (5%)- Handling incoming messages of the type MSG (5%)- Handling events from the Play and Pass buttons (5%)- Handling events from the chat input field (5%)- Implementation of the chat message area (5%)- Implementation of the chat input field (5%)- Implementation of the Connect menu item (5%)- Handling possible concurrency problem (5%)SubmissionPlease pack the source code (*.java) and images of your application into a single zip file,and submit it to the Course Moodle page.A few points to note:- Always remember to write Javadoc for all public classes and their public classmembers.- Always remember to Submit the source code files (*.java) but NOT the bytecodefiles (*.class).- Always double Check after your submission to ensure that you have submitted themost up-to-date Source code files.- Your assignment will not be marked if you have only submitted the bytecode files(*.class). You will get zero mark for the assignment.- Please submit your assignment on time. Late submission will not be accepted.~ End ~如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。