This program does a simple domino game but my problem is that the domino can ove
ID: 3528522 • Letter: T
Question
This program does a simple domino game but my problem is that the domino can overlap another. Anyone can help me debug this. it is not supposed to overlap spaces. /** The game of Domineering. */ public class Domineering { /** Array of board squares, true if occupied. */ private boolean[][] squares; /** The board is initially empty. */ public Domineering () { squares = new boolean[8][8]; // Java initializes all array elements to false } /** Create and play the game. */ public static void main(String[] args) { System.out.println("Welcome to Domineering."); Domineering game = new Domineering(); game.play(); } /**creates a grid for the board. */ public String toString() { String result = " 0 1 2 3 4 5 6 7"; for (int row = 0; row < 8; row++) { result += " " + row; for (int column = 0; column < 8; column++) { if (squares[row][column]) { result += " #"; } else { result += " ."; } } } return result; } /** For reading from the console. */ public static final java.util.Scanner INPUT = new java.util.Scanner(System.in); /** The player who plays their dominoes horizontally. */ public static final boolean HORIZONTAL = false; /** The player who plays their dominoes vertically. */ public static final boolean VERTICAL = true; /** Play until someone wins. */ public void play () { boolean player = HORIZONTAL; while (true) { System.out.println(" " + this); if (player == HORIZONTAL) { System.out.println("Horizontal to play"); } else { System.out.println("Vertical to play"); } if (!(hasLegalMoveFor(player))) { System.out.println("No legal moves -- you lose!"); return; } System.out.print("Row: "); int row = INPUT.nextInt(); System.out.print("Column: "); int column = INPUT.nextInt(); playAt(row, column, player); player = !player; } } /** * Play a domino with its upper left corner at row, column. */ public void playAt(int row, int column, boolean player) { squares[row][column] = true; if (player == HORIZONTAL) { squares[row][column + 1] = true; } else { squares[row + 1][column] = true; } } /** * Return true if there is a legal move for the specified player. */ public boolean hasLegalMoveFor(boolean player) { int rowOffset = 0; int columnOffset = 0; if (player == HORIZONTAL) { columnOffset = 1; } else { rowOffset = 1; } for (int row = 0; row < (8 - rowOffset); row++) { for (int column = 0; column < (8 - columnOffset); column++) { if (!(squares[row][column])) // squares[row + rowOffset][column + columnOffset])) { return true; } } return false; } }Explanation / Answer
#include "game.h" Game::Game(){ Domino* d1 = new Domino; m_Pd1 = d1; } Game::~Game(){ delete m_Pd1; delete m_Pu1; delete m_Pcpu1; delete m_Pb1; delete m_Pt1; } void Game::Start(){} void Game::newGame(){ //Shuffle s1(m_Pd1); User* u1 = new User; Computer* cpu1 = new Computer; m_Pcpu1 = cpu1; m_Pu1 = u1; BuyStone* b1 = new BuyStone; m_Pb1 = b1; Table* t1 = new Table; m_Pt1 = t1; //m_Pu1->appendList(s1.divisionStone()); } void Game::shuffle(){ int x, test = 0, qtdu = 0, qtdcpu = 0, i; int amount; static QList y; bool set = 1; amount = m_Pd1->getSize(); qsrand(time(NULL)); for(i = 0; i appendList(m_Pd1->getStone(x)); qtdu++; test = 1; } else{ if(test == 1 && qtdcpu < 7){ m_Pcpu1->appendList(m_Pd1->getStone(x)); qtdcpu++; test = 0; }else{ m_Pb1->appendList(m_Pd1->getStone(x)); } } } //return QString("Right: %1 | Left: %2 ").arg(m_Pd1->getRight(x)).arg(m_Pd1->getLeft(x)); //return (m_Pd1->getStone(x)); } void Game::largeStone(){ int u, c; int amount; amount = m_Pd1->getSize(); qsrand(time(NULL)); u = (qrand()%amount); c = (qrand()%amount); if(m_Pd1->getPoints(u) > m_Pd1->getPoints(c)) } void Game::playStone(){ }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.