Question
This project has three parts, and we have finished the first two parts and I posted all the five class files(Card.java, Deck.java, Board.java, BoardSquare.java, Game.java)
This project has three parts, and we have finished the first two parts and I posted all the five class files(Card.java, Deck.java, Board.java, BoardSquare.java, Game.java) and a class named GameText below. GameText is used to test Game class.
The third needs to creat a JavaFx application based on Game class.
The set game is like this. https://www.setgame.com/set/puzzle
public class Card
{
//store all the instance
public enum Color {RED, PURPLE, GREEN};
public enum Shape {OVAL, SQUARE, DIAMOND};
public enum Fill {SOLID, HATCHED, OUTLINE};
private int rank;
private Color color;
private Shape shape;
private Fill fill;
/**
Constructor takes all the variables
@param rank describe the number
@param c describe the color
@param s describe the fill
*/
public Card(int rank, Color c, Shape s, Fill f)
{
this.rank = rank;
this.color = c;
this.shape = s;
this.fill = f;
}
/**
toString method returns the information about Card
@return all imformation about the Card
*/
@Override
public String toString()
{
return rank + "_" + color + "_" + shape + "_" + fill;
}
/**
isSet method returns the boolean result between three cards
@return the boolean result
*/
public static boolean isSet(Card c1, Card c2, Card c3)
{
boolean rankOk = false;
boolean colorOk = false;
boolean shapeOk = false;
boolean fillOk = false;
if(c1.rank == c2.rank && c1.rank == c3.rank) //determine if all ranks same
rankOk = true;
else if(c1.rank != c2.rank && c2.rank != c3.rank && c1.rank != c3.rank) //determine if all ranks different
rankOk = true;
if(c1.fill == c2.fill && c1.fill == c3.fill) //determine if all fill same
fillOk = true;
else if(c1.fill != c2.fill && c2.fill != c3.fill && c1.fill != c3.fill) //determine if all fill different
fillOk = true;
if(c1.shape == c2.shape && c1.shape == c3.shape) //determine if all shape same
shapeOk = true;
else if(c1.shape != c2.shape && c2.shape != c3.shape && c1.shape != c3.shape) //determine if all shape different
shapeOk = true;
if(c1.color == c2.color && c1.color == c3.color) //determine if all color same
colorOk = true;
else if(c1.color != c2.color && c2.color != c3.color && c1.color != c3.color) //determine if all color different
colorOk = true;
boolean set = rankOk && colorOk && fillOk && shapeOk;
return set;
}
}
import java.util.*;
public class Deck
{
private static ArrayList deck;
private static Card removedCard;
/**
Constructor creates a arraylist contains 81 deck
*/
public Deck()
{
Card.Color[] colors = Card.Color.values();
Card.Fill[] fills = Card.Fill.values();
Card.Shape[] shapes = Card.Shape.values();
deck = new ArrayList();
//create the 81 deck,
for(int rank = 1; rank
{
for(int c = 0; c
for(int s = 0; s
for(int f = 0; f
deck.add(new Card(rank, colors[c], shapes[s], fills[f]));
}
}
/**
shuffle method shuffles all deck in the deck deck
*/
public void shuffle()
{
Collections.shuffle(deck);
}
/**
isEmpty method returns the boolean result about if the deck is empty
@return the boolean result of empty
*/
public static boolean isEmpty()
{
boolean empty = false;
if (deck.isEmpty())
empty = true;
return empty;
}
/**
getTopCard method returns the information about the top of the card in the deck
@return the removed card
*/
public static Card getTopCard()
{
removedCard = deck.get(0); //also represents the choosen card
deck.remove(0);
return removedCard;
}
/**
toString method returns the information about card in deck
@return the deck
*/
public String toString()
{
String str = "";
for(Card c: deck)
str += c + " ";
return str;
}
}
import java.util.ArrayList;
public class Board
{
private ArrayList> board;
private BoardSquare bs;
/**
Constructor accepts a Deck object and
grabs 12 cards from deck
and sets them into the 2D arraylist
@param deck describe the deck object
*/
public Board(Deck deck)
{
board = new ArrayList>();
for(int row = 0; row
{
board.add(new ArrayList ());
for(int col = 0; col
{
board.get(row).add(new BoardSquare(deck.getTopCard(), row, col));
}
}
}
/**
replaceCard method replace the card with specific row and column
@param newCard describes the instance of Card class
@param row describes the row number
@param col describes the column number
*/
public void replaceCard(Card newCard, int row, int col)
{
bs.setCard(newCard);
bs.setRow(row);
bs.setCol(col);
}
/**
getBoardSquare method returns the boardsquare
@param row describes the row number
@param col describes the column number
@return BoardSquare with its row and col
*/
public BoardSquare getBoardSquare(int row, int col)
{
bs = board.get(row).get(col);
return bs;
}
/**
add3 method add three cards at the end of each row
@param deck describe the Deck class
*/
public void add3(Deck deck)
{
int col = board.get(0).size() - 1;
for(int row = 0; row
{
board.get(row).add(new BoardSquare(deck.getTopCard(), row, col));
}
}
/**
getCard method returns the information about Card
@param row describes the row number
@param col describes the column number
@return everything about the Card
*/
public Card getCard(int row, int col)
{
return getBoardSquare(row, col).getCard();
}
/**
numRows method returns the numbers of rows
@return everything about the rows
*/
public int numRows()
{
return board.size();
}
/**
numCols method returns the numbers of columns
@return everything about the column
*/
public int numCols()
{
return board.get(0).size();
}
/**
toString method returns BoardSquare
@return everything about BoardSquare
*/
@Override
public String toString()
{
int rows = numRows();
int cols = numCols();
String str = "";
for(int r = 0; r
{
for(int c = 0; c
{
str += getCard(r, c).toString() + "\t";
}
str += " ";
}
return str;
}
}
public class BoardSquare
{
private Card card;
private int row, col;
boolean selected;
/**
Constructor accepts a Card object, row position and column position
@param card describes the Card object
@param row describes the row number of this object
@param col describes the colume number of this object
*/
public BoardSquare(Card card, int r, int c)
{
this.card = card;
this.row = r;
this.col = c;
this.selected = false;
}
/**
getCard method returns the information about Card
@return all imformation about the Card
*/
public Card getCard()
{
return card;
}
/**
setCard method set the card object
@param card describe the card object
*/
public void setCard(Card card)
{
this.card = card;
}
/**
getRow method returns the information about row
@return all imformation about the row
*/
public int getRow()
{
return row;
}
/**
setRow method set the row
@param card describe the row integer number
*/
public void setRow(int row)
{
this.row = row;
}
/**
getCol method returns the information about column
@return all imformation about the column
*/
public int getCol()
{
return col;
}
/**
setCol method set the column
@param card describe the column integer number
*/
public void setCol(int col)
{
this.col = col;
}
/**
isSelected method return the boolean result that the square is selected
@return the boolean result of the selection
*/
public boolean isSelected()
{
return selected;
}
/**
setSelected method takes the boolean result of the selection
@param selected describe the boolean result of the selection
*/
public void setSelected(boolean selected)
{
this.selected = selected;
}
@Override
public String toString()
{
return card.toString();
}
}
import java.util.ArrayList;
class Game{ private static final int MAXNUM = 3; public Deck d; public Board b; public BoardSquare bs; public ArrayList selectedList = new ArrayList(); public ArrayList cards = new ArrayList(); /** The instructor creates the deck and board instance we need and shuffle the card */ public Game() { d = new Deck(); //shuffle the cards in deck class d.shuffle(); b = new Board(d); } /** This method adds the cards to the array lists and selected the card @param row describes the row of the card @param col describes the column of the card */ public void addToSelected(int row, int col) { //add one card to each array list selectedList.add(b.getBoardSquare(row,col)); cards.add(b.getCard(row,col)); } /** This method return the number of the selected cards @return the number of the cards */ public int numSelected(){ //the number of selected cards is exactly the array list size return selectedList.size(); } /** This method determines whether three of the cards are a set */ public void testSelected(){ //call the isSet method to test three cards if (Card.isSet(cards.get(0), cards.get(1), cards.get(2))) { System.out.print("set!"); for(int i = 0; i = MAXNUM) { selectedList.clear(); cards.clear(); } } /** This method reomoves the selected cards in both array lists @param row describes the row of the card @param row describes the column of the card */ public void removeSelected(int row, int col){ b.getBoardSquare(row, col).setSelected(false); for(int i = 0; i
import java.util.Scanner; import java.util.ArrayList;
public class GameText {
public static void main(String [] args) { // create game Game g = new Game(); // display board System.out.println(g); // connect Scanner to keyboard Scanner keyboard = new Scanner(System.in); // variables for user input int row, col; String input; // flag for ending boolean stop = false; // while the game isn't over and user doesn't want to quit while (!g.outOfCards() && !stop) { // give user their choices System.out.print("(s)elect, (u)nselect, (a)dd3, (l)ist selected, (e)nd: "); // get user choice input = keyboard.nextLine(); // act on choice // select if (input.equalsIgnoreCase("s")) { System.out.print("row col ? "); row = keyboard.nextInt(); col = keyboard.nextInt(); g.addToSelected(row,col); // if it's the 3rd card selected if (g.numSelected() == 3) { // is it a set? // if it is a set, the cards are replaced // if it is NOT a set, all selected cards are unselected g.testSelected(); // re-display board System.out.println(g); } } // unselect else if (input.equalsIgnoreCase("u")) { System.out.print("row col ? "); row = keyboard.nextInt(); col = keyboard.nextInt(); g.removeSelected(row,col); } // add 3 cards (1 to each row), redisplay else if (input.equalsIgnoreCase("a")) { g.add3(); System.out.println(g); } // list all cards currently selected else if (input.equalsIgnoreCase("l")) { ArrayList selected = g.getSelected(); System.out.println(selected); } // user wants to be done else if (input.equalsIgnoreCase("e")) { stop = true; } if (!stop) input = keyboard.nextLine(); // get next choice } }
}
This final phase of implementation for your game will be applying a graphical user interface, using JavaFX. I have demonstrated my implementation, however, you are not bound to my GUI design decisions. Be creative! When the game begins, the user should be presented with the 12 face up cards, the number of cards remaining in the deck, and a means to select a card, deselect a selected card, add three cards to the face up cards (1 to the end of each row) or exit the program When a card is selected, there should be some visual indication. When a card is deselected, the visual indication should be removed. When 3 cards are selected, the game should evaluate the 3 cards to determine if they form a set. If they do, remove the cards and replace them with 3 new cards from the Deck. If the 3 cards do not form a set, remove the selection on the 3 cards and take no further action If there are at least 3 cards left in the Deck and less than 18 cards currently face up, the user may choose to "Add 3" cards to the face up cards At any point, the user should be able to terminate the game You may make minor modifications, if needed, to your existing classes, however, your GUI should be independent of the other classes. Your GUI class (or main GUI class if you choose to have multiple classes-not req'd) will have an instance of the Game class. You are 'unplugging' the GameText class and 'plugging in' in the GUI version Rubric (10) Reasonable layout of GUI (8) Accurate display of all cards (individually) (5) Accurate display of board (initially12 cards face up) (2) Indicate number of cards in Deck remaining (5) Cards are selectable/unselectable Determine if 3 cards are a set (automatic when 3 cards are selected) (10) Replace cards if set (3) Unselect Cards if not set . (10) Add 3 cards to board (5) Add 3 ability taken away if less than 3 cards in deck or 18 cards showing (2) Exit (-10) GUI implementation integrated into Game classes. This final phase of implementation for your game will be applying a graphical user interface, using JavaFX. I have demonstrated my implementation, however, you are not bound to my GUI design decisions. Be creative! When the game begins, the user should be presented with the 12 face up cards, the number of cards remaining in the deck, and a means to select a card, deselect a selected card, add three cards to the face up cards (1 to the end of each row) or exit the program When a card is selected, there should be some visual indication. When a card is deselected, the visual indication should be removed. When 3 cards are selected, the game should evaluate the 3 cards to determine if they form a set. If they do, remove the cards and replace them with 3 new cards from the Deck. If the 3 cards do not form a set, remove the selection on the 3 cards and take no further action If there are at least 3 cards left in the Deck and less than 18 cards currently face up, the user may choose to "Add 3" cards to the face up cards At any point, the user should be able to terminate the game You may make minor modifications, if needed, to your existing classes, however, your GUI should be independent of the other classes. Your GUI class (or main GUI class if you choose to have multiple classes-not req'd) will have an instance of the Game class. You are 'unplugging' the GameText class and 'plugging in' in the GUI version Rubric (10) Reasonable layout of GUI (8) Accurate display of all cards (individually) (5) Accurate display of board (initially12 cards face up) (2) Indicate number of cards in Deck remaining (5) Cards are selectable/unselectable Determine if 3 cards are a set (automatic when 3 cards are selected) (10) Replace cards if set (3) Unselect Cards if not set . (10) Add 3 cards to board (5) Add 3 ability taken away if less than 3 cards in deck or 18 cards showing (2) Exit (-10) GUI implementation integrated into Game classesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started