-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectFactory.java
More file actions
58 lines (51 loc) · 1.81 KB
/
GameObjectFactory.java
File metadata and controls
58 lines (51 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* I implement a factory pattern for creating game objects. It contains static
* methods for creating instances of different game entities
* Each method takes parameters specific to the type of game object being
* created and returns a new instance of that object.
* The Factory Pattern is used here to encapsulate the instantiation logic of
* game objects, providing a centralized point for object creation.
*/
public final class GameObjectFactory {
// Method to create a Player object
/**
* Creates a new Player object with specified coordinates.
*
* @param x The x-coordinate for the player.
* @param y The y-coordinate for the player.
* @return A new instance of Player.
*/
public static final Player createPlayer(int x, int y) {
return new Player(x, y);
}
// Method to create an Alien object
/**
* Creates a new Alien object with specified coordinates.
*
* @param x The x-coordinate for the alien.
* @param y The y-coordinate for the alien.
* @return A new instance of Alien.
*/
public static final Alien createAlien(int x, int y) {
return new Alien(x, y);
}
// Method to create a bullet object
/**
* Creates a new bullet object with specified coordinates.
*
* @param x The x-coordinate for the bullet.
* @param y The y-coordinate for the bullet.
* @param direction The direction of bullet up or down
* @return A new instance of a bullet.
*/
public static final Bullet createBullet(int x, int y, int direction) {
return new Bullet(x, y, direction);
}
// Method to create an Obstacle object
/**
* @return A new instance of an obstacle.
*/
public static final Obstacle createObstacle() {
return new Obstacle();
}
}