Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a Java code for below problem. Your goal is to create a memory game where two players need to match pairs of cards.

I need a Java code for below problem.
Your goal is to create a memory game where two players need to match pairs of cards.
This project must be implemented using Object Oriented Programming and you must
create different classes in order to implement this game.
A memory game starts off with a board screen with cards face down in a 2D grid.
Players take turns to choose two cards at a time. Cards chosen by a player are revealed
and if they match, the player collects the cards (they are taken off the board) and scores
two points. If the cards do not match, they are placed face down again and it is then the
other players turn .
Rules of the Game:
Ask the user for a value of n(even number so all cards can be matched)
Create an n * n grid of cards/ blanks containing randomly selected characters(make
sure each character has one match/ there must be pairs of 2 for equal characters).
Player 1 picks two positions and cards are opened and shown.
If the cards are equal, the player collects the cards (cards are removed from play and
the player scores two points) and goes again. If the cards do not match, they are turned
face down and it is now the other players turn.
Player 2 now picks two positions and the cards are opened and shown.
Play continues until all the cards have been collected by either of the users.
Whoever has the most cards at the end of the game wins. Player points should be
recorded and a winner should be selected at the end or a draw can be announced.
Players should have the option to restart the game after a current game ends.
Ending Conditions:
Once all of the cards have been matched the game ends and the winning player is
announced
Part A : Class Diagram
Create a Class Diagram for the memory game. Think about the most basic class you
will need to implement this game and build up from there. Think about the attributes
(variables) that each class should have along with methods which operate on these
variables.
Part B: Game Implementation/ Requirements
There should be a board screen where players can see the current cards left as
well as the score of the two players. Your program should create a board that
consists of cards which are randomly generated every time the game starts and
placed in a nxn grid where n is an even number given by the user at the beginning
of play. Create the board so that there is always a match card to be found for
every card on the board.
Players take turns to play (select two cards from the board one after the other ).
If a player chooses to open a card the value of the card should be shown. If a
player matches two cards the cards should disappear from the card options.
Player points should be recorded and a winner should be selected at the end or a
draw can be announced.
Players should have the option to restart the game after a current game ends.
You should at least have 3 classes, one for the Card, one for the Board and one
can be the Main class or Game class with the main method in it.
Here is a sample class diagram for this project. Remember this is part of the design
process and you may need to go back and add or change things and that is okay. It is
just part of the debugging and code development process.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

What is the distribution of B(s) + B(t), s t?

Answered: 1 week ago

Question

True or False for little oh : 2 * ( n ^ 2 ) = o ( n ^ 3 )

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago