Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

OK So I have am using Java and using a main to call my Classes blow I will post my what i have so far

OK So I have am using Java and using a main to call my Classes blow I will post my what i have so far and what my overall requirements. I am not sure how to call my classes via main to have the ability to move pieces on the board, please help! thanks,

public class Main { public static void main(String[] args) { Board myBoard = new Board();

} }

Other classes below seperated by classes sorry, hard to copy paste

class Piece { String name; String color; Piece(String name, String color) { this.name = name; this.color = color; } void move(int x, int y, int a, int b, String[][] grid) { int x = Integer.parseInt(newCoordinates[0]) - 1; int y = Integer.parseInt(newCoordinates[1]) - 1; String temp = grid[x][y]; grid[x][y] = grid[a][b]; grid[a][b] = temp; } }

class Square { Piece piece; Square() { this.piece = null; } Piece getPiece() { return this.piece; } void setPiece(Piece piece) { this.piece = piece; } }

class Board { Square[][] squares = new Square[8][8]; Board() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { squares[i][j] = new Square(); } } } void setPieceOnSpace(Piece piece, int x, int y) { squares[x][y].setPiece(piece); } void removePieceFromSpace(int x, int y) { squares[x][y].setPiece(null); } void displayBoard() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (squares[i][j].getPiece() == null) { System.out.print("_ "); } else { System.out.print(squares[i][j].getPiece().name + " "); } } System.out.println(); } } }

Now the requirements

create 3 classes

Board

Square Piece

Board Class:

Design Board owns the squares. The board will create and manage the squares. The squares will contain, but wont exclusively own the Pieces. But theyll be our holders. Pieces for now will be very simple a name and 1 function. See functions below.

Board (Something like this but willl need colors)

Variables:

Squares

Functions:

SetPieceOnSpace

Takes a piece as input

Sets the piece on given coordinates

RemovePieceFromSpace

Takes coordinates as input

Removes the piece at those coordinates and places an Empty piece now

Constructor

Sets the board by default for every board we create

Square

Variables:

Piece

Functions:

GetPiece

Returns the piece on the square

SetPiece

Sets a piece on the square

Takes a piece as input

Constructor

Generic constructor

Specific constructor Piece

Points ( black and white pieces) or what ever color you have facing each other

Variables (total pieces / aka piece count pet side)

Name

Color

Functions: ( doesnt have to work like a checkers board just needs to be set up with pieces as such) Needs ability to replace pieces code like this to replace a square with user input)

Move

As long as the piece move to the coordinates specified youve meet the criteria.

Objective: youll setup the board, display it, and ask the user to type a piece name, enter coordinates to move that piece. Remove the piece from its original position, replacing it with an empty, and placing it on the new square. Youll then print the board, and ask the user if theyd like to keep going or quit.

Thank you I wrote a book just trying my best to figure this out

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions