Paper Plane Game: Design, Implementation and Abstraction Project

Verified

Added on  2022/09/14

|2
|323
|23
Project
AI Summary
This assignment involves the design and implementation of a Paper Plane Game, including the application of object-oriented programming principles. The game features a paper plane that moves across a window with a brick-style background. The paper plane can move in three directions: South, South West, and South East. The assignment also explores the concept of abstraction and when it would be useful, such as if the game involved different shapes for obstacles. The solution provided includes a discussion on the potential use of abstract classes and how they could simplify the code and improve maintainability. However, in the provided solution, abstraction was not implemented as the assignment did not require it. The solution also includes the implementation of the game's movement and behavior, such as the paper plane reappearing at the top of the window when it exits at the bottom or when a key is pressed. The provided solution also includes some code snippets that demonstrate the use of abstraction using abstract classes and methods.
Document Page
Paper Plane Game
Abstraction of classes is useful when you have several related methods that performs a certain thing of
a similar function in a similar way. For instance, if there are two shapes with different number of sides
that you want to define a function of calculating the area of both differently, abstraction should be
applied. An abstract class Shape can be defined with an abstract method that returns the area of the
shape.
If both Rectangle and Triangle or circle classes, inherit from the ‘Shape Abstract class’, they will have
to define their own implementation. Therefore, it assists in leveraging the super class. The objects can
be stored in the same array or list , then call the respective method based on the current instance. In the
Paper Plane Game,I have not applied abstraction anywhere because I did not see it much useful in such
a case. However, if the obstacles were of different shapes, then I would appreciate the existence of
abstract classes since i would have stored everything as a basic shape. This would have enabled me to
treat Circles, Triangles, Rectangles and even polygons as just a shape therefore utilizing the concept of
super-classes , abstraction and abstract class.
public abstract class Shape{
/**
* Abstract method to calculate area of a shape
*/
public abstract double area();
}
public class Rectangle extends Shape{
/**
*Assuming that the Rectangle subclass has width and height fields
*/
public double area(){
return length * width;
}
}
public class Circle extends Shape{
/**
*Assuming that the Circle subclass has radius field
*/
public double area(){
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
return PI * radius * radius;
}
}
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]