辅导MVC implementation 帮做COSC 2391/2401 编程、Software Architecture 辅导、AWT/Swing U编程

2018-09-23 辅导MVC implementation 帮做COSC 2391/2401  编程、Software Architecture 辅导、AWT/Swing U编程
Software Architecture Design and ImplementationCOSC 2391/2401 Semester 2, 2018Casino Style Card GameAssignment Part 2: AWT/Swing UI Implementation (25 marks)This assignment requires you to build an AWT/Swing graphical user interface for the Card Game thatreuses your code from assignment part 1.You should build on top of your existing assignment part 1 functionality and should not need tochange your existing Game Engine code if it was correct in assignment part 1. You can seek help inthe tutelab/consultation to finish assignment part 1 if necessary (since it is a core requirement of thiscourse that you should be able to work with basic OO classes and interfaces). Furthermore, you willrequire a solid understanding of classes/interfaces to write effective AWT/Swing!As part of your new implementation you must write a GameEngineCallbackGUI class that is addedto the GameEngine via the existing addGameEngineCallback() method. This class will beresponsible for managing all of the graphical updates as the game is played. NOTE: this class shouldnot actually implement the UI functionality but instead for cohesion it should call methods on otherclasses, especially the view. To state another way, it must be the entry point for any UI code resultingfrom game play, in order to avoid coupling between the GameEngine and the UI which is counter tothe original specification.This GameEngineCallbackGUI is to be added in addition to the console basedGameEngineCallbackImpl from assignment 1 in order to demonstrate that your GameEngine canwork with multiple callbacks i.e. both (all) callbacks are called for any relevant operation such asdealHouse()/dealPlayer(). NOTE: This is the main reason the assignment part 1 specificationrequired the GameEngineImpl to handle multiple callbacks!AWT/Swing User InterfaceYou are to develop an AWT/Swing user interface that implements the following basic functionality:Add players (including name and initial betting points balance)Place a bet (per player) and display an error message for invalid betsPlayer deals (per player) .. each card is shown in real-time as it is dealtHouse deals (automatically after all players have bet/dealt) .. each card is shown in real-time as it isdealtDisplay results including updated player balances after house dealNOTE: You should set your delay to 1 second (1000ms) for testing and submission.It is up to you how to design the layout and appearance of your interface and you should focus onclarity and simplicity rather than elaborate design. However, to demonstrate competency you shouldinclude at least one each of the following.A pull-down menu (like the standard File menu in Eclipse)A dialog boxA toolbarA status barA switchable per player panel which represents the dealt cards (see UI Implementation/Limitationsbelow)A summary panel which is always visible which shows player names and their current points balance Marking emphasis will be on the quality of your code and your ability to implement the requiredfunctionality as well as basic usability of the UI (based on the usability attributes described in thelecture notes).Your code should be structured using the Model View Controller pattern (MVC) where theGameEngineImpl from assignment part 1 serves as the model, the listeners represent thecontrollers as separate classes (each in a separate file placed in the controller package), whereasthe GameEngineCallbackImpl and new GameEngineCallbackGUI are part of a view package(or sub-packages), as are any additional UI classes such as frames, dialogs, components, menus etc.Furthermore, you must NOT use static referencing (e.g. no use of the Singleton pattern) and thereforeall references required by different classes must be passed as parameters (e.g. via constructors).IMPORTANT: All of your GUI code (MVC views including the GameEngineCallbackGUI andcontrollers) should be separate from your GameEngineImpl implementation (MVC model).Furthermore, all of your GUI code should call your GameEngineImpl implementation via theGameEngine interface only. You should not add any UI code to the GameEngineImpl with theprimary test being that your UI code should work with any GameEngine implementation (for exampleour own implementation we will use for testing). i.e. your UI should not require anything additionalfrom the assignment 1 GameEngineImpl if implemented correctly according to the Javadoc andassignment 1 specification. Finally, your GameEngineImpl should still pass the Validator checksfrom assignment 1.NOTE: It is a core learning outcome of this assignment to demonstrate that encapsulation andprogramming to interfaces provides complete separation such that code written by independentparties can work together seamlessly without any change!UI Implementation/LimitationsYou must only display the UI for a single player at a time, whereby the visible/active player can bedirectly selected from a list or combo box. The dealt cards are the most important part of part of theplayer UI.The card panel must have the appearance of animation but can be as simple as a JLabel that isupdated for each new intermediate result received from the GameEngineCallback methods, but itwill likely be more rewarding and impress your friends if you can find some nice creative commons orfree for personal use card graphics :) You cannot however simply replicate the logging behaviour ofassignment 1 in a JTextArea or similar component.More importantly, since the UI is per player, if a player is currently visible and being dealt cards, whenyou switch to another player the UI should stop animating the dealt cards and should instead displaythe last cards dealt to the player you switched to. You can however assume that only one player willbe dealt to at a time so you do not have to handle concurrency in the Game Engine.All this behaviour is readily facilitated by the GameEngineCallback which receives a Playerinstance as a parameter, so as long as your GUI keeps track of the current player it can receiveupdates for all players and display only the current/relevant player in the GUI, while yourGameEngineCallbackImpl from assignment 1 will log all players to the console.NOTE: Although threads will be covered towards the end of the semester, AWT/Swing requires allcalls to the UI (any methods in AWT/Swing such as creating a component, laying out, or updating) tobe done on the AWT Event Dispatch Thread. Furthermore, since thedealPlayer(…)/dealHouse(…) methods of GameEngineImpl execute in a loop with a delay it isnecessary to run them in a separate thread so they do not lock up the UI.To achieve this you can use the code below. You don’t need to know exactly how this works for now(although the API docs are useful here and we will also cover in class) but hopefully you are able toidentify how the code is simply using anonymous inner classes to execute some code on a separatethread! To call a GameEngineImpl method (such as dealPlayer()) on a separate thread. new Thread() { @Override public void run() { //call long running GameEngine methods on separate thread } }.start();To update the GUI from the callback .. SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // do GUI update on UI thread } });Implementation DetailsIMPORTANT: As with assignment one you must not change any of the interfaces. You mayimplement any other helper classes that you need to. A correct implementation should not require anychanges to the GameEngineImpl, only the addition of new AWT/Swing classes to build the UI, inaddition to a new GameEngineCallbackGUI.To demonstrate cohesion and correct OO techniques, all UI code must be written carefully by hand.You can use builder tools (such as NetBeans) to aid prototyping but all final code must be written byhand. You will lose marks for if you submit generated code! You will also be breaching the third partycode requirement below.SUMMARY1. You should use MVC implementation for your system.2. You should write all your listeners as separate controller classes in the controllerpackage.3. You must not use any static referencing (e.g. no use of the Singleton pattern permitted).4. You should aim to provide high cohesion and low coupling.5. You should aim for maximum encapsulation and information hiding.6. You should rigorously avoid code duplication.7. You should comment important sections of your code remembering that clear and readilycomprehensible code is preferable to a comment.8. Since this course is concerned with OO design you should avoid the use of Java 8 lambdaswhich are a functional programming construct.9. You should use extra threads where necessary (based on the sample code provided above)to ensure smooth UI operation.10. You should handle all exceptions with a sensible error message but do not need to handlethem in the GUI (a console log is sufficient)