Question

I HAVE THE FOLLOWING CODE IN JAVA FOR A SNAKE GAME, I WANT SOMEONE TO EXPLAIN...

I HAVE THE FOLLOWING CODE IN JAVA FOR A SNAKE GAME, I WANT SOMEONE TO EXPLAIN EACH PART OF THE CODE, WHAT'S THE FUNCTION OF EACH PART

THANK YOU

import java.awt.Color;

import java.awt.Graphics;

public class BodyPart {

private int xCoor, yCoor, width, height;

public BodyPart(int xCoor, int yCoor, int tileSize) {

this.xCoor = xCoor;

this.yCoor = yCoor;

width = tileSize;

height = tileSize;

}

public void tick() {

}

public void draw(Graphics g) {

g.setColor(Color.BLACK);

g.fillRect(xCoor * width, yCoor * height, width, height);

}

public int getxCoor() {

return xCoor;

}

public void setxCoor(int xCoor) {

this.xCoor = xCoor;

}

public int getyCoor() {

return yCoor;

}

public void setyCoor(int yCoor) {

this.yCoor = yCoor;

}

  

}

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

Find the description of each line of the code in below images.

Add a comment
Know the answer?
Add Answer to:
I HAVE THE FOLLOWING CODE IN JAVA FOR A SNAKE GAME, I WANT SOMEONE TO EXPLAIN...
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
  • Java Program The goal of this assignment is to develop an event-based game. You are going...

    Java Program The goal of this assignment is to develop an event-based game. You are going to develop a Pong Game. The game board is a rectangle with a ball bouncing around. On the right wall, you will have a rectangular paddle (1/3 of the wall height). The paddle moves with up and down arrows. Next to the game board, there will be a score board. It will show the count of goals, and count of hits to the paddle....

  • 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)...

  • Java question. I am creating a clock program in Java GUI, but it has some problem....

    Java question. I am creating a clock program in Java GUI, but it has some problem. First, The time of the clock is not correct. It has to point at the current time. Second, the position of the clock character is wrong. Please fix it for me please. import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.util.Date; import javax.swing.JPanel; import javax.swing.WindowConstants; public class Clock extends javax.swing.JFrame { public int hour; public int min; public int sec; ClockDial cd; public Clock() {...

  • This is a Clock program in Java. Can you fix my Java program error, and add function to display c...

    This is a Clock program in Java. Can you fix my Java program error, and add function to display current time currently? import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.util.Date; import javax.swing.JPanel; import javax.swing.WindowConstants; public class Clock extends javax.swing.JFrame {    public int hour;    public int min;    public int sec;    ClockDial cd;    public Clock() {        setSize(510, 530);        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);        cd = new ClockDial(this);        getContentPane().add(cd);        Date curr = new Date();        String time = curr.toString();        hour = Integer.parseInt(time.substring(11, 13));        min = Integer.parseInt(time.substring(14, 16));        sec...

  • "Polygon Drawer Write an applet that lets the user click on six points. After the sixth point is clicked, the applet should draw a polygon with a vertex at each point the user clicked." import...

    "Polygon Drawer Write an applet that lets the user click on six points. After the sixth point is clicked, the applet should draw a polygon with a vertex at each point the user clicked." import java.awt.*; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.applet.*; public class PolygonDrawer extends Applet implements MouseListener{ //Declares variables    private int[] X, Y;    private int ptCT;    private final static Color polygonColor = Color.BLUE; //Color stuff    public void init() {        setBackground(Color.BLACK);        addMouseListener(this);        X = new int [450];        Y =...

  • (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */...

    (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */ import java.awt.Graphics; public abstract class Animal { private int x; // x position private int y; // y position private String ID; // animal ID /** default constructor * Sets ID to empty String */ public Animal( ) { ID = ""; } /** Constructor * @param rID Animal ID * @param rX x position * @param rY y position */ public Animal( String...

  • JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but...

    JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but i need to create a jar file . the instructions are below. It has to pass some parameters. I am really confused on doing so.l I dont know what to do next. Can someone help me and give detailed descritiopm opn how you ran the jar file in CMD import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Connect4 {               ...

  • I have to create a java graphics program which will draw 10 rectangles and 10 ellipses...

    I have to create a java graphics program which will draw 10 rectangles and 10 ellipses on the screen. These shapes are to be stored in an arrayList. I have to do this using 6 different class files. I am not sure whether I successfully created an ellipse in the Oval Class & also need help completing the print Class. I need someone to check whether my Oval Class is correct (it successfully creates an ellipse with x, y, width,...

  • ***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...

  • Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles....

    Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...

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