Question

import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; public class RedGamePiece extends GamePiece { public RedGamePiece...

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;


public class RedGamePiece extends GamePiece
{
        public RedGamePiece (int row, int col) {
                super (row, col, Player.RED);
        }

        public RedGamePiece (Position pos) {
                this (pos.r, pos.c);
        }
        
        protected boolean validNonJump (int dr, int dc, GameSquares squares)
        {
                if ((dr == -1) && ( (dc == -1) || (dc == 1) ))
                {
                        if (squares.getSquare(pos.r + dr, pos.c + dc).getPiece() == null)
                                return true;
                }
                
                return false;
        }
        
        protected boolean validJump (int dr, int dc, GameSquares squares)
        {               
                return false;
        }
        
        public void drawPiece (Graphics2D g2, int x, int y, int width, int height)
        {
                Ellipse2D.Double outline = new Ellipse2D.Double (x + width * DIST_FROM_EDGE + LINE_WIDTH / 2,
                                                                                                                 y + height * DIST_FROM_EDGE + LINE_WIDTH / 2,
                                                                                                                 width * (1 - 2 * DIST_FROM_EDGE) - LINE_WIDTH,
                                                                                                                 height * (1 - 2 * DIST_FROM_EDGE) - LINE_WIDTH);

                g2.setColor (Color.RED);

                BasicStroke stroke = new BasicStroke (LINE_WIDTH);
                g2.setStroke(stroke);
                g2.fill (outline);

                if (selected)
                {
                        g2.setColor (Color.GREEN);
                        g2.draw (outline);
                }

        }
}

HELP PLEASE

Modify the code so that there are twelve RED pieces, positioned on the black squares of the bottom three rows of the board.

Create a BlackGamePiece class, and add BLACK pieces to their appropriate starting positions (i.e. on the 12 black squares in the top 3 rows of the board).

Ensure that BLACK pieces move appropriately.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.BasicStroke;

import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.geom.Ellipse2D;

public class RedGamePiece extends GamePiece

{

public RedGamePiece (int row, int col) {

super (row, col, Player.RED);

}

public RedGamePiece (Position pos) {

this (pos.r, pos.c);

}

protected boolean validNonJump (int dr, int dc, GameSquares squares)

{

if ((dr == -1) && ( (dc == -1) || (dc == 1) ))

{

if (squares.getSquare(pos.r + dr, pos.c + dc).getPiece() == null)

return true;

}

return false;

}

protected boolean validJump (int dr, int dc, GameSquares squares)

{

return false;

}

public void drawPiece (Graphics2D g2, int x, int y, int width, int height)
{

Ellipse2D.Double outline = new Ellipse2D.Double (x + width * DIST_FROM_EDGE + LINE_WIDTH / 2,

y + height * DIST_FROM_EDGE + LINE_WIDTH / 2,

width * (1 - 2 * DIST_FROM_EDGE) - LINE_WIDTH,

height * (1 - 2 * DIST_FROM_EDGE) - LINE_WIDTH);

g2.setColor (Color.RED);

BasicStroke stroke = new BasicStroke (LINE_WIDTH);

g2.setStroke(stroke);

g2.fill (outline);

if (selected)

{

g2.setColor (Color.GREEN);

g2.draw (outline);

}

}

}

Add a comment
Know the answer?
Add Answer to:
import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; public class RedGamePiece extends GamePiece { public RedGamePiece...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver {    public static...

    Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver {    public static String solve(char[][] grid) {        // TODO        /*        * 1. Construct a graph using grid        * 2. Use BFS to find shortest path from start to finish        * 3. Return the sequence of moves to get from start to finish        */               // Hardcoded solution to toyTest        return...

  • Please use my code to implement the above instructions. My Grid class: import java.util.ArrayList; import java.util.Collections;...

    Please use my code to implement the above instructions. My Grid class: import java.util.ArrayList; import java.util.Collections; class Grid { private boolean bombGrid[][]; private int countGrid[][]; private int numRows; private int numColumns; private int numBombs; public Grid() { this(10, 10, 25); }    public Grid(int rows, int columns) { this(rows, columns, 25); }    public Grid(int rows, int columns, int numBombs) { this.numRows = rows; this.numColumns = columns; this.numBombs = numBombs; createBombGrid(); createCountGrid(); }    public int getNumRows() { return numRows;...

  • Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner...

    Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...

  • please help me to creating UML class diagrams. Snake.java package graphichal2; import java.awt.Color; import java.awt.Font; import...

    please help me to creating UML class diagrams. Snake.java package graphichal2; import java.awt.Color; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Random; enum Dir{L, U, R, D}; class Food { public static int FOODSTYLE = 1; private int m = r.nextInt(Yard.WIDTH / Yard.B_WIDTH); private int n = r.nextInt(Yard.HEIGHT / Yard.B_WIDTH - 30/Yard.B_WIDTH) + 30/Yard.B_WIDTH;// 竖格 public static Random r = new Random(); public int getM() { return m; } public void setM(int m)...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*;...

    ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPanel implements ActionListener { public static final int DELAY = 50; // delay between repaints in millis private static final String DUMP_IMAGE_PROPERTY_NAME = "drawingpanel.save"; private static String TARGET_IMAGE_FILE_NAME = null; private static final boolean PRETTY = true; // true to anti-alias private static boolean DUMP_IMAGE = true; // true to write DrawingPanel to file private int width, height; // dimensions...

  • How can I make a test case with Junit? import java.util.ArrayList; import board.Board; public class Pawn...

    How can I make a test case with Junit? import java.util.ArrayList; import board.Board; public class Pawn extends Piece{    public Pawn(int positionX, int positionY, boolean isWhite) {        super("P", positionX, positionY, isWhite);    }    @Override    public String getPossibleMoves() {        ArrayList<String> possibleMoves = new ArrayList<>();               //check side, different color pawns go on different ways        if(isWhite) {            if(positionX != 7 && positionY != 0) {           ...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT