Question

1. create a class called MemoryBoard. a. MemoryBoard will represent a grid of memory squares. it...

1. create a class called MemoryBoard.

a. MemoryBoard will represent a grid of memory squares. it needs to track all of the squares on the board, the cars set it's using, the width and the height of the board, the number of turns that have been taken, and the current player's id.

2. create a arraylist to store the squares on the board. it should store Square objects. the class should also store the width(an int), the number of turns taken(an int), the set of cards(a CardSet), and the current player's id(an int).

3. make this class inherit jPanel

4. make MemoryBoard implement the Board interface.

5. Implement the following methods from the board interface:

a. getBoardWidth- gets the width of the board and returns the variable.

b. getBoardHeight- gets te height of the board and returns the variable.

c. getTurns- gets the number of turns used and returns the variable.

d. getCurrentPlayer- gets the id of the curent player and returns the variable.

e. setCurrentPlayer- sets the current player's id and update the variable.

f. getTotalNumMatches- counts the number of matches made in the game. return 0, will be implmented later.

g. getMatchesByPlayer- returns the first copy of the cards that were matched by a player. return null, implement later.

h. findCard- finds a card on the board. return null, implement later.

i. getSquare- returns a swuare at the coordinates given. If both the x and y are valid ( the x and y are betwee 0 and te board's width/height), return the square from the arraylist that corresponds to that x ans y. if eighter or both x and y is not valid return null.

j. getPossibleMatches- determines the number of possible matches that can be made in the game. First, determine the number of squares on the board(use the width and height) and divide by 2. return the smaller of this number and the maximum number od cards in your CardSet variable.

k. resetBoard- ressets the board to its original state. first, remove all the cards from te square on the board. using an iterato loop over your araylist and call the removeCard method on each square. using your CardSet, get a new shuffle of the cards.Store arraylsit in a local variable. Using a counting loop, loop over all of the cards in the shuffle arraylist. in the loop, get a Card from that arraylist and get a square from your arraylist of squares. call the square's setCard method and give it the card. the card at position 0 should go into the square at position 0 and so forth. set the number of turns to 0.

6. create a constructor that takes a CardSet and two ints( width and height). Store the CardSet in the appropriate variable. if either of the width or height is 0 or less, both the with and the height should be set to 5(use a constant). set the curent player id to 0. create a new arraylist and store it in the class variable. Set the preffered size of the board to 105*width x 105*height.

use a loop to ceate all the squares in the board. count from 0 to the number of squares on the board. in the loop create a new MemorySquare object and store it in a local variable.use local variable as parameter. add this square to your arraylist of Aquares and to the MemoryBoard. Set the preferred size of the square to be 100 x 100.

call resetBoard to initialize the board.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public static MemoryBord implements Board extends jPanel
{
int width, height, noOfTurns, curPlayerId ;
Set<Integer> CardSet = new HashSet<Integer>();
Arraylist squares = new Arraylist<Integer>();

MemoryBoard(Set CS, int width, int height)
{
   CardSet = addAll(CS);
   if(width<=0) width=5;
   if(height<=0) height=5;
   curPlayerId = 0;
   ArrayList NewList = new ArrayList<Integer>(105*105);
   for(i=0; i<width*height; i++)
   {
   /* As I dont have definition of MemorySquare */
   /* I am assuming that MemorySquare is a class with */
   /* `integer value` parameter */
   MemorySquare element = new MemorySquare();
   element.value = 0;

   NewList.add(element.value);
   }
}

getBoardWidth()
{
   return width;
}

getBoardHeight()
{
   return height;
}

getTurns()
{
   return noOfTurns;
}

getCurrentPlayer()
{
   return curPlayerId;
}

setCurrentPlayer(int a)
{
   curPlayerId = a;
}

getTotalNumMatches()
{
   return 0;
}

getMatchesByPlayer()
{
   return null;
}

findCard(String cardName)
{
   return null;
}

int getSquare(int x, int y)
{
   if((x>=0 && x<=width) && (y>=0 && y<=height))
   {
   return squares.get(width*x + y);
   }
   return 0;
}

getPossibleMatches(String cardName)
{
   noOfSq = (width* height)/2;
   if(noOfSq < CardSet.size()) return noOfSq;
   else return CardSet.size();
}

void resetBoard()
{
   for(int elem : squares){
   removeCard(elem);
   }

   /*
   Some Code Here
   */

}
  
}


The resetBoard function is not complete.
You have mentioned that :-
*Remove all the cards from Arralylist squares
*Assign it to temp list
*Reshuffle the temp & do new assingments
But, when we have already empptied the Arraylist Squares, what is the point in shuffle ?

Please clear the above statements, so that resetBoard function can be completed

Add a comment
Know the answer?
Add Answer to:
1. create a class called MemoryBoard. a. MemoryBoard will represent a grid of memory squares. it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriat...

    Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: • Print every card in the...

  • Using C++ Create a Blackjack program with the following features: Single player game against the dealer....

    Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card. Face cards count as 10. Player starts with $500. Player places bet before being dealt a card in a new game. New game: Deal 2 cards to each...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • Java Instructions of assignment: Inside 1st class - Find the int width and height of a...

    Java Instructions of assignment: Inside 1st class - Find the int width and height of a rectangle; include methods to set and get the width and height; and a method to calculate and return the area Inside 2nd class - Use an ArrayList to store 10 unique dimensions of the rectangle class - Set the width & height using a constructor or setter methods - Create a bubble sort algorithm list inside a method to set the areas in descending...

  • *in Java 1. Create a card class with two attributes, suit and rank. 2.In the card...

    *in Java 1. Create a card class with two attributes, suit and rank. 2.In the card class, create several methods: a. createDeck – input what type of deck (bridge or pinochle) is to be created and output an array of either 52 or 48 cards. b.shuffleDeck – input an unshuffled deck array and return a shuffled one. + Create a swap method to help shuffle the deck c. countBridgePoints – inputs a 13-card bridge ‘hand’-array and returns the number of...

  • Player Class Represents a participant in the game of blackjack. Must meet the following requirements: Stores...

    Player Class Represents a participant in the game of blackjack. Must meet the following requirements: Stores the individual cards that are dealt (i.e. cannot just store the sum of the cards, you need to track which specific cards you receive) Provided methods: decide_hit(self): decides whether hit or stand by randomly selecting one of the two options. Parameters: None Returns: True to indicate a hit, False to indicate a stand Must implement the following methods: Hi!! i just need help with...

  • CS102 : JAVA Object-Oriented Programming. 1 Write a class Card whose instances represent a single playing...

    CS102 : JAVA Object-Oriented Programming. 1 Write a class Card whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties an integer for the rank (1 (corresponding to Ace) ,2,3, 13 (correspond ing to King) and suit (Spades, Hearts, Diamonds, or Clubs). Make the suit an enumerated data type. Include getters and setters and a method that tests if a card is valid. Write a class named Deck whose instances are full...

  • Create a class called Horse. It has an instance var which is a string called "breed"...

    Create a class called Horse. It has an instance var which is a string called "breed" create a constructor to set and an a accessor method to return back the breed. Then in a main driver class, create an ArrayList with 5 Horses. Create the following static method which returns back the total horses in the ArrayList of a certain breed. public static int getBreed(List<Horse> h, String breed);

  • WEB230 - JavaScript 1 Assignment 6a Use Events and DOM manipulation to create a playable Tic...

    WEB230 - JavaScript 1 Assignment 6a Use Events and DOM manipulation to create a playable Tic Tac Toe game. Do the following using JavaScript. Do not modify the HTML file. When you see this symbol: save and refresh the browser (this should happen automatically if you are using Brackets with Live Preview), then check your code to make sure it is working before you proceed. 1. Create two variables called "playerX" and "playero". Set them to the DOM element with...

  • In Java Create a testing class that does the following to the given codes below: To...

    In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT