Preparation
Do the following before starting this project:
- Understand how arrays are used (not ArrayLists) 4.12
- Read chapter 11.1 - 11.4
- Due at the start of lab
Objectives
After completing this project, you should be able to:
- create a simple GUI application using Java Swing
- manipulate data in arrays
- describe the concept of separating model and view in an object oriented design
Project Specification
Getting Started
We are providing a BlueJ project to get you started.
- Connect to the CSIS R: drive
- Start Blue J and open the VideoPoker project located on the R: drive in the CS 162 folder
- Save this project to your N: drive
- You will write a new class called "Game", modify the existing GUI class, and not make any changes to the GVcard or GVstack classes.
Your solution must include ALL of the following requirements.
- Remember that it is critical to separate the Model and View. For this project,
you should have a Game class that keeps track of the credits, the current
state of the game, and validates each scoring category. The GUI class should know very little about the rules or state of the game.
- Provide a clever window title to personalize your solution
- Avoid duplicate code in your solution when possible. If you notice multiple lines of code being used in several places then consider placing the code in a method.
- Make methods private unless they need to be public
Rules of the Game
- players begin with a balance of twenty credits
- each round begins with a freshly shuffled deck of 52 cards
- the player presses DEAL and five cards are dealt face up, the player's
balance decreases by one.
- the player chooses to hold zero or more cards by clicking on each
card
- the player presses DRAW and the unselected cards are replaced with
fresh cards
- the game determines the highest payout based on the five cards
- the updated balance is displayed on the screen
- a text message displays the scoring category such as "straight"
or "no payout" at the end of each round. This text message is also used to provide game instructions.
- play continues until 1) player runs out of credits, 2) player selects
quit from the file menu, 3) or player selects New Game from the file
menu and starts over with twenty credits.
- Provide a popup confirmation message using JOptionPane when the player
chooses Quit or Restart.
- Provide a Test Mode for the player to keep drawing as long as they choose to easily test all scoring categories.
Pay Schedule
The following amounts are paid assuming a one credit wager.
- a pair of jacks or higher (1)
- two pairs (2)
- three of a kind (3)
- straight (4)
- flush (6)
- full house (9)
- four of a kind (25)
- straight flush (50)
- royal straight flush (250)
GVcard and GVstack classes
You will not need to make any changes to the GVcard or GVstack classes but will need to be familiar with how to use them. The code is a bit sophisticated but all you really need to understand are the following GVcard methods:
- int getValue ( ) - values range from 2 to 14 (Ace = 14)
- int getSuit ( ) - there are four suits
- void flip ( ) - turn the card over
- boolean isMarked ( ) - return true if the card is selected
And the following GVstack methods:
- GVstack(1) - instantiates one deck of 52 cards
- GVstack(0) - instantiates an empty deck capable of holding cards (can be considered an empty plastic tray)
- shuffle ( )
- GVcard pop ( ) - return and remove the top card
- GVcard topCard ( ) - return the top card but it stays on the deck
- push (card) - add the card to the top of the deck
Game class
Implement a class called "Game" with the following methods:
- declare an instance variable that is an array of five GVstacks (no ArrayLists please). You will also need to instance variables to keep track of the credits, the current message, and a deck of cards.
- you are encouraged to identify additional instance variables and private methods as you see fit.
- declares finals for each of the scoring categories. Remember to use proper style of all caps.
private final int FULL_HOUSE = 9;
- public Game ( ) - instantiate the array of GVstacks and initialize the instance variables.
- public GVstack [ ] getTrays ( ) - return the array of GVstacks. This method is called by GUI to allow it to display the cards and is only ONE line of code.
- public String getMessage ( ) - return the current message.
- public int getCredits ( ) - return the current balance.
- public void deal ( ) - instantiate a new deck of cards, shuffle them, place each of the top five cards into a tray, and turn the cards face up.
- public void draw ( ) - replace each of the cards (not marked) and score the hand by calling an internal method to hide the details
- public void reset ( ) - reset the credits, reset default message and turn the cards face down
- private boolean checkPair ( ) - update the internal message if the cards include a pair (Jacks or higher). Return true if the category was detected and false otherwise.
- private boolean checkTwoPair ( ) - update the internal message if the cards include two pair (any values). Return true if the category was detected and false otherwise.
- private boolean checkThreeOfAKind ( ) - update the internal message if the cards include a three of a kind. Return true if the category was detected and false otherwise.
- private boolean checkFullHouse ( ) - update the internal message if the cards include a full house (three of a kind and a pair). Return true if the category was detected and false otherwise.
- private boolean checkStraight ( ) - update the internal message if the cards include a straight (Ace can be high or low). Return true if the category was detected and false otherwise.
- private boolean checkFlush ( ) - update the internal message if the cards include a flush (five cards with same suit). Return true if the category was detected and false otherwise.
- private boolean checkStraightFlush ( ) - update the internal message if the cards include a straight with all the same suit. Return true if the category was detected and false otherwise. Return true if the category was detected and false otherwise.
- private boolean checkFourOfAKind ( ) - update the internal message if the cards include a four of a kind. Return true if the category was detected and false otherwise.
- private boolean checkRoyalFlush ( ) - update the internal message if the cards include a straight (10, J, Q, K, A) with all the same suit. Return true if the category was detected and false otherwise.
- private void scoreHand ( ) - organize the values and suits from the five cards, make internal method calls to check each of the scoring categories. Update the score for ONLY ONE of the categories (if any). You must check the categories in reverse order of their values so that a lower order is not used instead of a higher order. For example, a three of a kind is less points than a full house.
GUI class
You will need to finish some of the code in the GUI class. The components are already displayed for you. You need to do the following:
- private void setupMenus ( ) - create a file menu with three options: test, reset and quit. Remember to register the action listener for each menu item. Refer to section 11.4.3.
- public void setupFrame ( ) - most of this method is written for you. However, you will need to register the action listeners for each of the buttons or nothing will happen when the player clicks on them.
- public void resetGame ( ) - invoke the reset() in the Game class, enable the Deal button, disable the Draw button, update the credits and update the message.
- Create a boolean instance variable that gets set to 'true' when the player selects testing mode. Both buttons remain enabled during the game to let the player 'cheat' to test all possible scoring categories. This variable is reset to 'false' at the start of each new game.
- public void actionPerformed (ActionEvent e) - Respond appropriately to each of the buttons or menu selections. This method will contain several if statements with appropriate method calls. 1) invoke the Game's deal() method, disable the Deal button, and enable the Draw button when the player clicks on Deal. 2) invoke the Game's draw() method, disable the Draw button, and enable the Deal button when the player clicks on Draw. 3) Display a pop-up message to confirm Quit or Reset menu selections. Do not take action if the player cancel's the choice. 4) set the testing instance variable to 'true' when the Test menu item is selected. 5) In all cases, update the credits and message. (This code is already provided for you.)
Bonus Challenges
If you finish the project early, you may want to attempt some of the
following additional challenges.
- After the deal, automatically select cards from a winning hand so the player does not have to. Select cards for a flush, a three of a kind, four of a kind, two pair, and one pair (Jacks or higher). Give careful thought of where and how to add this code. Strive to keep all methods short and self-contained. (5 pts)
- Use a photo of your instructor for the back side of the cards! (2 pts)
Grading Criteria
This project is worth a possible 100 points.
- Stapled cover page with your name and signed pledge (- 10
pts if missing)
- The code compiles (- 10 pts if it does not)
- Each method does what it is supposed to do (80 pts)
- Source code follows our Java Style
Guide (10 pts)
- Appropriate documentation including javadoc tags (10 pts)
Cover Page
Your project must have a cover page that includes your name, a title,
an appropriate picture and the following signed pledge. "I pledge
that this work is entirely mine, and mine alone (except for any code
provided by my instructor). "
Late Policy
Projects are expected to be turned in on time. However, you are encouraged to complete a project even if you must turn it in late.
- 1 weekday late (-20 pts)
- every subsequent weekday is an additional -10 pts
- Saturday and Sunday are free days
|