Module 5: GUI “Low Card” Game

In module 5, you’ll be working on the assignment
GUI “Low Card” Game. In this assignment, there are 5 steps split
into three phases. Step 1, read and display Jlabel Cards. Step 2, encapsulate the Card
Icons in a class GUICard. Step 3, create a CardTable class. Step 4, use the included
CardGameFramework Class. Step 5, create the game “Low-Card.”
You’ll be working with the java.awt and javax.swing packages.
Remember, wild card imports do not affect the efficiency of your program.
For this assignment, you may use the following concepts: inheritance, anonymous objects,
implementing the swing system, inner classes, and bubble sort.
For Step 1 and Phase 1, you will be creating an array representing 57 JLabel objects with
icons and labels set that represent playing cards. There will be a total of 52 standard
playing cards, plus 4 jokers, plus 1 back image card. For the main method, you will need to create
loops to initialize all the individual cards. This can be done using the helper methods
outlined in the sample provided. The naming of cards and card suits can be set using for
loops. Since the file names are 2 characters, you can split the first half of the file name
and use the first character to determine value and the second character to determine the
suit. With that information, you can use the suggested helper methods to set the correct
value and suit. As the assignment specs stated, major point
loss if you initialize the cards using 52 literal names instead of using array logic. Once complete, you’ll want to display all
the cards on a JFrame. For the layout manager, the GridLayout style would work best to evenly
divide the cards in the Jframe. For steps 2 and 3 in phase 2, you’ll be
encapsulating the Card Icons in a class GUICard. In addition, you will be creating a CardTable
class that will extend Jframe. Last, you’ll be adding additional methods and adjustments
to your code from the module 3 assignment. For step 2, you’ll be creating a GUICard
class. This class will use your code from phase 1 to go from a 1D array of playing cards
to a 2D array of playing cards. The 2D array will have the standard deck of playing cards
plus one joker for each suit. For the loadCardIcons() method, I would use the same separation of
the file name characters to determine the values and suit for each card. The getIcon
method can return a card using some helper methods that take a Card object and returns
the value and suit to determine the Card being returned from the Icons 2D array. For Step 3, you’ll be creating a class derived
from JFrame. You’ll be using the grid layout with Jpanels to create the playing field.
In the constructor, you’ll be setting up the playing field with the Jpanels housing
the playing area and the players’ cards. In the main method, you’ll be adding Jlabels
to the panels in the field. For the construction of the JPanels, it would be useful to use
multiple layout managers. You can have a separate Grid Layout manager for each Jpanel to neatly
space everything out. Last in phase 2, you’ll be making modifications
to the existing code you created in module 3. For the Card class, one method you’ll
need to implement is a bubble sort algorithm with a Card array. It would be useful to break
the method down into multiple parts. The main sort method can handle the actual swapping
of place between cards while a helper function can determine which card precedes the other.
This helper function could return a boolean value to determine which action to take. In
the main method of phase 2, you’ll be creating a random card generator. For this
method, you can use the Math.Random class and method nextInt to generate a random card
position. In the other classes, Deck and Hand, you’ll be making some minor adjusts to account
for Joker and other accessor and mutator methods .
In steps 4 and 5, in phase 3, we’ll be using the CardGameFramework class and creating the
game “Low-Card.” In Step 4, you’ll be combining the included
CardGameFramework with your main from phase 2. The steps to look out for are steps 3 and
4. In Step 3, you will not use the static method randomCardGenerator to get a card.
You will have to use the inspectCard method from Deck class to return a Card object and
than pass that Card object as an argument to the GUICard class method getIcon. In Step
4, ensure that the same playing field loads correctly like it did in phase 2.
In Step 5, you’ll be creating the game “Low-Card.” For this game, You will need to implement
a game in which a computer player and yourself pick the lowest card. Since you are already
using Jlabels, you can attach them to a Jbutton using the add method. From there, you can
assign actionListeners to them. Though you can create an inner class for your action
listener, it would be easier to implement ActionListener and with a simple multi-way
if else statement in the actionPerformed method. The game rules are simple enough to not require
multiple actionListeners. This actionListener can determine the outcome of the game and
display win or lose. As for the computer player’s decision making, the best strategy would be
for it beat the human players card with the next lowest card in the field rather than
the lowest card in the player’s deck. To do that, it would be useful to sort the computer
player’s cards and doing a bubble sort like iteration. Once the next lowest card is found,
have computer play it on the field. Since you already developed a bubble sort method
earlier, you can use some of the code from that method definition.
Just a couple of quick tips for this assignment. For the Jframe object, ensure you pass an
argument to the setDefaultCloseOperation method as the default is to hide the window and not
exit the program. Anonymous objects can be used widely for various
GUI elements. Useful if you know the GUI objects do not need to call any methods or interact
with anything else in the program. I hope this rundown of the program for module
5 helps. Good luck everyone.

Tags:, ,

Add a Comment

Your email address will not be published. Required fields are marked *