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.
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
1. create a class called MemoryBoard. a. MemoryBoard will represent a grid of memory squares. it...
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...
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...
In java How to get started; Create a class called Card. The card has three fields; a value , a suit and a face. The card class has a constructor that takes three values for the three fields. Create a no-args constructor. The Card class has three get methods to return the values of each of the fields. The Card class has a toString( ) method. The Card class has a compareTo( ) method that uses the value of the...
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...
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...
*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...
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...
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...
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...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...