Create GameObject.java

This commit is contained in:
YanchaoMiao 2020-05-24 19:12:06 +08:00 committed by Ilkka Seppälä
parent f9ca7f752e
commit 405495f0a8
No known key found for this signature in database
GPG Key ID: 31B7C8F5CC412ECB

View File

@ -0,0 +1,87 @@
package com.iluwatar.component;
import java.util.ArrayList;
/**
* GameObject is a class for all object in the game.
* It was constructed by a collection of component.
*/
public class GameObject {
private int velocity;
private int positionOFx;
private int positionOFy;
ArrayList<Component> componentArrayList;
/**
* Constructor for GameObject
* @param componentArrayList is the list of this object contains
*/
public GameObject(ArrayList<Component> componentArrayList){
this.componentArrayList=new ArrayList<>();
this.componentArrayList.addAll(componentArrayList);
}
/**
* setter for velocity
* @param velocity is the velocity of this object
*/
public void setVelocity(int velocity) {
this.velocity = velocity;
}
/**
* getter for velocity
*/
public int getVelocity() {
return velocity;
}
/**
* setter for PositionOFx
* @param positionOFx is the PositionOFx of this object
*/
public void setPositionOFx(int positionOFx) {
this.positionOFx = positionOFx;
}
/**
* getter for PositionOFx
*/
public int getPositionOFx() {
return positionOFx;
}
/**
* setter for PositionOFy
* @param positionOFy is the PositionOFy of this object
*/
public void setPositionOFy(int positionOFy) {
this.positionOFy = positionOFy;
}
/**
* getter for PositionOFy
*/
public int getPositionOFy() {
return positionOFy;
}
/**
* update for this object's components.
*/
public void update(){
for (Component component : componentArrayList) {
component.update(this);
}
}
}