Casino Style Card Game
This assignment requires you to build an AWT/Swing graphical user interface for the Card Game that reuses your code from assignment part 1.
You should build on top of your existing assignment part 1 functionality and should not need to change your existing Game Engine code if it was correct in assignment part 1. You can seek help in the tutelab/consultation to finish assignment part 1 if necessary (since it is a core requirement of this course that you should be able to work with basic OO classes and interfaces). Furthermore, you will require 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 added to the GameEngine via the existing addGameEngineCallback() method. This class will be responsible for managing all of the graphical updates as the game is played. NOTE: this class should not actually implement the UI functionality but instead for cohesion it should call methods on other classes, especially the view. To state another way, it must be the entry point for any UI code resulting from game play, in order to avoid coupling between the GameEngine and the UI which is counter to the original specification.
This GameEngineCallbackGUI is to be added in addition to the console based GameEngineCallbackImpl from assignment 1 in order to demonstrate that your GameEngine can work with multiple callbacks i.e. both (all) callbacks are called for any relevant operation such as dealHouse()/dealPlayer(). NOTE: This is the main reason the assignment part 1 specification required the GameEngineImpl to handle multiple callbacks!
AWT/Swing User Interface
You 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 bets Player deals (per player) .. each card is shown in real-time as it is dealt
House deals (automatically after all players have bet/dealt) .. each card is shown in real-time as it is dealt
Display results including updated player balances after house deal
NOTE: 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 on clarity and simplicity rather than elaborate design. However, to demonstrate competency you should include at least one each of the following.
A pull-down menu (like the standard File menu in Eclipse) A dialog box
A toolbar
A status bar
A switchable per player panel which represents the dealt cards (see UI Implementation/Limitations below)
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 required functionality as well as basic usability of the UI (based on the usability attributes described in the lecture notes).
Your code should be structured using the Model View Controller pattern (MVC) where the GameEngineImpl from assignment part 1 serves as the model, the listeners represent the controllers as separate classes (each in a separate file placed in the controller package), whereas the 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 therefore all 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 and controllers) should be separate from your GameEngineImpl implementation (MVC model).
Furthermore, all of your GUI code should call your GameEngineImpl implementation via the GameEngine interface only. You should not add any UI code to the GameEngineImpl with the primary test being that your UI code should work with any GameEngine implementation (for example our own implementation we will use for testing). i.e. your UI should not require anything additional from the assignment 1 GameEngineImpl if implemented correctly according to the Javadoc and assignment 1 specification. Finally, your GameEngineImpl should still pass the Validator checks from assignment 1.
NOTE: It is a core learning outcome of this assignment to demonstrate that encapsulation and programming to interfaces provides complete separation such that code written by independent parties can work together seamlessly without any change!
You must only display the UI for a single player at a time, whereby the visible/active player can be directly selected from a list or combo box. The dealt cards are the most important part of part of the player UI.
The card panel must have the appearance of animation but can be as simple as a JLabel that is updated for each new intermediate result received from the GameEngineCallback methods, but it will likely be more rewarding and impress your friends if you can find some nice creative commons or free for personal use card graphics ? You cannot however simply replicate the logging behaviour of assignment 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, when you switch to another player the UI should stop animating the dealt cards and should instead display the last cards dealt to the player you switched to. You can however assume that only one player will be 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 Player instance as a parameter, so as long as your GUI keeps track of the current player it can receive updates for all players and display only the current/relevant player in the GUI, while your GameEngineCallbackImpl 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 all calls to the UI (any methods in AWT/Swing such as creating a component, laying out, or updating) to be done on the AWT Event Dispatch Thread. Furthermore, since the dealPlayer(…)/dealHouse(…) methods of GameEngineImpl execute in a loop with a delay it is necessary 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 to identify how the code is simply using anonymous inner classes to execute some code on a separate thread!
To call a GameEngineImpl method (such as dealPlayer()) on a separate thread.