Write a GUI version of a card matching game using the swing package.
Your program should have 4 rows and 4 columns of cards that have an image that is hidden when the cards are face down. (Note: The cards can have another image facing up like a real deck has on the back)
The game is played by clicking on two cards which are face down. If they match, they stay visible.
If they don't match, they will need to be flipped back face down before choosing another card.
There should be a "Continue" button which flips back two non-matching cards.
If you click on a "face up" card, it should just be ignored.
The "Continue" button should not flip cards when only one has been flipped up. It should only flip cards to the hidden side if there are two non-matching cards turned up.
The number of attempts and the number of matches should be counted and displayed per game.
An attempt is incremented when 2 cards have been flipped up, regardless of match/mismatch.
The score is calculated as attempts/matches. (Keep in mind division by zero)
When the user chooses to end the game, they should be asked to confirm their choice.
If they say YES, they should see a sentence that uses their score to assess the player's memorizing ability before the program exits.
The game will need at least the following:
A 2 Dimensional Board of Cards
Labels to display Status, Matches, Attempts, Score
JButtons:
One to flip the cards back over so their matchable images are hidden
One to end the game. (Remember to confirm the choice before exiting)
Create and use Card class that extends the JButton class. It should have at least the following:
Instance variables:
ImageIcon imageIcon
String imagePath
Constructors:
Default
Overloaded Constructor that takes in the imagePath as a String
Methods:
hideCard()
showCard()
equals(Object o)
Syntax Hint For creating a scaled image that will load fast and fit on your Card:
ImageIcon ic_reg = new ImageIcon("images/myImage.png"); ImageIcon ic_logo = new ImageIcon(((Image) ic_reg.getImage()).getScaledInstance(70, 70, Image.SCALE_FAST));
To set the ImageIcon on a JButton object just call the setIcon method and pass in the name of the ImageIcon object you created.
Score conditions to be used for the end of game status:
score > 97 AMAZING score > 80 Excellent score > 60 OK score > 30 lacking score >10 suffering Score >=0 Mind has escaped
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.