From 405495f0a8d8d0411a0731b924c2bfd42ac4db69 Mon Sep 17 00:00:00 2001 From: YanchaoMiao <11710204@mail.sustech.edu.cn> Date: Sun, 24 May 2020 19:12:06 +0800 Subject: [PATCH] Create GameObject.java --- .../com/iluwatar/component/GameObject.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 component/src/main/java/com/iluwatar/component/GameObject.java diff --git a/component/src/main/java/com/iluwatar/component/GameObject.java b/component/src/main/java/com/iluwatar/component/GameObject.java new file mode 100644 index 000000000..78844e6ba --- /dev/null +++ b/component/src/main/java/com/iluwatar/component/GameObject.java @@ -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 componentArrayList; + + /** + * Constructor for GameObject + * @param componentArrayList is the list of this object contains + */ + + public GameObject(ArrayList 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); + } + } +}