1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Oliga [24]
3 years ago
13

Can someone who is skilled at coding create me a Java chess game. Please don't copy from online source codes. Make it original t

hanks! :D
Computers and Technology
1 answer:
enot [183]3 years ago
8 0

copy this and fill in the blanks so you can change it up a bit



--------------------------------------------------------------------------------------------------------------

public class Game {

   private Board board = new Board();

   private Player white;

   private Player black;

   public Game() {

       super();

   }

   public void setColorWhite(Player player) {

       this.white = player;

   }

   public void setColorBlack(Player player) {

       this.black = player;

   }

   public Board getBoard() {

       return board;

   }

   public void setBoard(Board board) {

       this.board = board;

   }

   public Player getWhite() {

       return white;

   }

   public void setWhite(Player white) {

       this.white = white;

   }

   public Player getBlack() {

       return black;

   }

   public void setBlack(Player black) {

       this.black = black;

   }

   public boolean initializeBoardGivenPlayers() {

       if(this.black == null || this.white == null)

           return false;

       this.board = new Board();

       for(int i=0; i<black.getPieces().size(); i++){

           board.getSpot(black.getPieces().get(i).getX(), black.getPieces().get(i).getY()).occupySpot(black.getPieces().get(i));

       }

       return true;

   }

}

Player.java

public class Player {

   public final int PAWNS = 8;

   public final int BISHOPS = 2;

   public final int ROOKS = 2;

   public boolean white;

   private List<Piece> pieces = new ArrayList<>();

   public Player(boolean white) {

       super();

       this.white = white;

   }

   public List<Piece> getPieces() {

       return pieces;

   }

   public void initializePieces(){

       if(this.white == true){

           for(int i=0; i<PAWNS; i++){ // draw pawns

               pieces.add(new Pawn(true,i,2));

           }

           pieces.add(new Rook(true, 0, 0));

           pieces.add(new Rook(true, 7, 0));

           pieces.add(new Bishop(true, 2, 0));

           pieces.add(new Bishop(true, 5, 0));

           pieces.add(new Knight(true, 1, 0));

           pieces.add(new Knight(true, 6, 0));

           pieces.add(new Queen(true, 3, 0));

           pieces.add(new King(true, 4, 0));

       }

       else{

           for(int i=0; i<PAWNS; i++){ // draw pawns

               pieces.add(new Pawn(true,i,6));

           }

           pieces.add(new Rook(true, 0, 7));

           pieces.add(new Rook(true, 7, 7));

           pieces.add(new Bishop(true, 2, 7));

           pieces.add(new Bishop(true, 5, 7));

           pieces.add(new Knight(true, 1, 7));

           pieces.add(new Knight(true, 6, 7));

           pieces.add(new Queen(true, 3, 7));

           pieces.add(new King(true, 4, 7));

       }

   }

}

Board.java

public class Board {

   private Spot[][] spots = new Spot[8][8];

   public Board() {

       super();

       for(int i=0; i<spots.length; i++){

           for(int j=0; j<spots.length; j++){

               this.spots[i][j] = new Spot(i, j);

           }

       }

   }

   public Spot getSpot(int x, int y) {

       return spots[x][y];

   }

}

You might be interested in
Long Answer Questions: a. Briefly explain the types of Control Structures in QBASIC.​
Alexus [3.1K]

Answer:

The three basic types of control structures are sequential, selection and iteration. They can be combined in any way to solve a specified problem. Sequential is the default control structure, statements are executed line by line in the order in which they appear.

7 0
3 years ago
Write a program that prompts the user to enter in a postive number. Only accept positive numbers - if the user supplies a negati
marusya05 [52]

Answer:

The c++ program to check prime numbers is shown below.

#include <iostream>

using namespace std;

int main() {

   int num, prime=0;

   do

   {

       cout<<"Enter a positive number."<<endl;

       cin>>num;

       if(num<1)

       {

           cout<<"Invalid number. Enter a positive number"<<endl;

           cin>>num;

       }

   }while(num<1);

   

   if(num==1 || num==2 || num==3)

       cout<<num<<" is a prime number."<<endl;

   else if(num%2 == 0)

       cout<<num<<" is not a prime number."<<endl;

   else

   {

       for(int k=3; k<num/2; k++)

       {

           if(num%k == 0)

               prime++;

       }    

   if(prime>1)

       cout<<num<<" is not a prime number."<<endl;

   else

       cout<<num<<" is a prime number."<<endl;

   }

}

OUTPUT

Enter a positive number.

-7

Invalid number. Enter a positive number

0

Enter a positive number.

79

79 is a prime number.

Explanation:

The user input is validated for positivity. A do while loop along with an if statement is implemented for verification.

do

   {

       cout<<"Enter a positive number."<<endl;

       cin>>num;

       if(num<1)

       {

           cout<<"Invalid number. Enter a positive number"<<endl;

           cin>>num;

       }

   }while(num<1);

The test for prime number is done by using multiple if else statements.

If user inputs 1, 2, or 3, message is displayed.

Else If user inputs an even number, message is displayed for not prime. This is done by taking modulo of the number upon division by 2.

Else if user inputs neither an even number nor a number less than 3, the modulus of the number is taken with divisors beginning from 3 up to half of the input number.

For this, an integer variable prime is initialized to 0. A number can be completely divisible by itself or by its factors.

If the number is divisible by any of the divisors, value of variable prime is increased by 1. If value of prime is greater than 1, this means that the user input is divisible by more than one divisor. Hence, the given number is not a prime number.

5 0
3 years ago
When I try to add a module into a device, Packet Tracer pop-ups a warning message saying "Cannot add a module when the power is
laiz [17]

plug it into a charger the go to I tunes and it should be there


4 0
3 years ago
An EAP is an:
Oksana_A [137]

i believe the answer would be B

8 0
3 years ago
Read 2 more answers
a _____ is a recreation of a thumbnail in a desktop publishing software, also known as a "rough". a. proof b. digital draft c. l
Dmitrij [34]
D. It’s a sketch. That is, if you talking about, an art piece.
6 0
3 years ago
Other questions:
  • The most efficient way to perform data entry is to keep your hands on the keyboard and press _______ to move to the next cell in
    14·1 answer
  • Write a method that take an integer array as a parameter and returns the sum of positive odd numbers and sum of positive even nu
    13·1 answer
  • Media applications that play audio or video files are part of a class of workkloads called "streaming" workloads (i.e., they bri
    9·1 answer
  • Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values
    13·1 answer
  • In a five-choice multiple-choice test, which letter is most often the correct
    10·2 answers
  • How to open a new word proccessing document
    9·1 answer
  • The term Linux Intrusion Detection System ( LIDS) refers to a command that allows an administrator to run processes as root with
    5·1 answer
  • Which statement about intellectual property is true? (CSI-7.6) Group of answer choices It is okay to use code you find on the in
    14·1 answer
  • The contrast ratio of green-60 text on a yellow-10 background is ___ to 1.
    5·1 answer
  • Which reports indicate how traffic arrived at a website?.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!