Project 1
Project 1: Moving Objects

Objectives

Upon Completion of this project, students will be able to :
Implement small classes that conform to a set specification.
Use multiple classes together to solve a larger problem.
Use logic to enforce a valid internal state and perform computations.
Description

The purpose of this project is to create the beginnings of a simple Java game involving moving objects that can be clicked on. The first thing to create is window for the game and a set of moving objects. Most of the code for the window has already been provided for you. Take a look at the classes GameFrame and DrawPanel in the Project 1 source code. Those classes are set up to display a window and to draw and move two objects on the screen: a circle and a rectangle. There is some code missing, however. Look at the sections marked with TODO comments. You will need to add some code there to initialize objects and link the code you create to the game. You should not modify any of the existing code as this stage. This is especially true for the variable and method declarations in those classes. (Notice that they all use interfaces instead of using a concrete class. That is they use ICircle instead of a class like Circle.)

The majority of the project is about implementing the following six interfaces:
IArea
ICircle
IDrawCircle
IDrawRect
IRectangle
IVector
Each interface lists the mandatory methods for the classes you need to implement. You may implement other methods in your classes to help you if you wish, but you must have at least those in the interface. Fairly detailed descriptions of what each method is required to do are listed above each method.

You must decide what data to include in your classes and how to store it.

While you are coding notice how the code is designed. For instance, there is a ICircle interface and a IDrawCircle interface. Why are these two not combined to form a circle that can draw itself? Would the single interface/class be more or less complicated than the separated versions? Would it be as clear as to what each interface/class represents?

Classes & Files

For grading purposes, the classes you implement must have certain names and provide certain constructors. They are as follows:

DrawArea implements IArea
constructor: public DrawArea(int x, int y, int width, int height)
Circle implements ICircle
constructor: public Circle(int rad, int x, int y, Color col)
DrawCircle implements IDrawCircle
constructor: public DrawCircle(ICircle cir, IVector vel, IArea drawArea)
DrawRect implements IDrawRect
constructor: public DrawRect(IRectangle rect, IVector vel, IArea drawArea)
Rectangle implements IRectangle
constructor: public Rectangle(int x, int y, int width, int height, Color col)
Vector implements IVector
constructor: public Vector(int vx, int vy)
You may include other constructors if you wish, but these must be there.

A typical implementation of the Circle class may start like this:

public class Circle implements ICircle
{
//add class variables

public Circle(int rad, int x, int y, Color col)
{//initialize variables
}
...
}

The implements ICircle after the class name tell the compiler that Circle conforms to the ICircle interface. If you do not have the methods defined in the body of ICircle, then the compiler will give you errors. (Hint: Eclipse will help you by giving you the option to fix those errors by automatically creating them. You can also just copy and paste the methods from ICircle and add a body to them.)

Do not change the interfaces! Doing so will cause the grader to error when you submit your work. Only modify you own classes and the areas in GameFrame and DrawPanel that are marked.

Test each class to see that it works as expected. Be sure to run your program and see what it does and if it is behaving as you wanted it to.

Submitting your Program

Submit your program through web-CAT. Web-CAT will provide you with 70% of your grade. The other 30% will come from the instructor.

Submit GameFrame, DrawPanel and the classes for the six interfaces you implemented. Do not submit the interface files (IArea, ICircle, etc.).

Ezzaral commented: This isn't a homework completion service. -3

I haven't read your entire post but first off you need to post code inside the code tags and also you will be probably get someone telling you that they won't do your homework for you and that you need to do some work before they offer their advice.

I haven't compiled the code you posted but in order to make something move you need to add that component to a frame or panel and assign a listener to it - for example if I want an image to move when i use the arrows I would use:

public void keyPressed(KeyEvent e) {

        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
       
            dx = -5;
        }

and so on. The int variable dx is the position of the image, thus it decreases when we press the left arrow key. You will need methods for moving, getting the current x & y position as well as getting the image.

This is a free forum - you don't need to pay and shouldn't pay even if someone offers to help you for a fee. You got to try for yourself

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.