Question
Hello, so I am almost finished with my domino game which involves java, I need to have a working flip method so it swaps the
Hello, so I am almost finished with my domino game which involves java, I need to have a working flip method so it swaps the numbers around,so the first piece would be 6 on top and 1 on the bottom if i called the flip method.
import ecs100.*; import java.util.*; import java.awt.Color; import java.util.ArrayList;
/** YOUR DOCUMENTATION COMMENT */
public class DominoGame{ public static final int NUM_HAND = 5; // Number of dominos in hand
// Fields: hand, table and selectedPos private Domino[] hand;; // the hand (fixed size array of Dominos) private ArrayList
private int selectedPos = 0; // selected position in the hand. private int first; private int second; // (You shouldn't add any more fields for core or completion)
/** YOUR DOCUMENTATION COMMENT */ public DominoGame() { // Initialize the hand and table fields hand = new Domino[5]; table = new ArrayList
public void restart(){ table.clear(); // Set the hand field to be empty for (int i = 0; i
this.redraw(); }
/** YOUR DOCUMENTATION COMMENT */ public void pickup(){ for (int i = 0; i
this.redraw(); }
/** YOUR DOCUMENTATION COMMENT */ public void removeDomino(){ // Remove the domino at the selected position in the hand (if there is one) if (hand[selectedPos] != null) { hand[selectedPos] = null; } this.redraw(); }
/** YOUR DOCUMENTATION COMMENT */ public void placeDomino(){ // Move the domino at the selected position in the hand (if there is one) to the table if (hand[selectedPos] != null) { table.add(hand[selectedPos]); hand[selectedPos] = null; }
this.redraw(); }
public void DominoGame() { // Initialize the numbers on the domino to be random values first = (int)(Math.random() * 6) + 1; second = (int)(Math.random() * 6) + 1; }
public int getFirst() { return first; }
public int getSecond() { return second; }
public void flipNums() { // Swap the values of first and second int temp = first; first = second; second = temp; }
public void flip() { int temp = first; first = second; second = temp; }
public void flipDomino(){ int temp = first; first = second; second = temp;
this.redraw(); }
/** YOUR DOCUMENTATION COMMENT */ public void moveToLeftEnd(){ if (selectedPos > 0) { Domino temp = hand[selectedPos]; hand[selectedPos] = hand[selectedPos - 1]; hand[selectedPos - 1] = temp; selectedPos--; }
this.redraw(); }
/** YOUR DOCUMENTATION COMMENT */ public void moveToRightEnd(){ if (selectedPos
this.redraw(); }
/** YOUR DOCUMENTATION COMMENT */ public void suggestDomino(){ /*# YOUR CODE HERE */
}
Step 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