Skip to content
Browse files

Added comments and minor change to show function. Moving is still

bugged, it need to be rewritten
  • Loading branch information...
1 parent 4910d8c commit 468fd0aeed7c56f35ce14fb7942a85ff532b3ea5 @JakobekS JakobekS committed
View
41 Tamagotchi/src/com/redditandroiddevelopers/tamagotchi/Fifo.java
@@ -5,27 +5,42 @@
private Object[] object;
private int size = 0;
+ /**
+ * Fifo's creator, make space for one object on start
+ */
public Fifo() {
- object = new Object[1];
+ object = new Object[3];
}
+ /**
+ * Adds object to fifo
+ *
+ * @param ob
+ */
public void add(Object ob) {
if (object.length == size) {
- Object[] temp = new Object[size + 1];
+ Object[] temp = new Object[size + 3];
System.arraycopy(object, 0, temp, 0, size);
object = temp;
temp = null;
}
+
object[size] = ob;
size++;
}
- public Object show() {
- if (size > 0)
- return object[0];
+ /*
+ * Return first object without removing it
+ */
+ public Object show(int iterator) {
+ if (size > 0 && iterator <=size && iterator >=0)
+ return object[iterator];
return null;
}
+ /**
+ * Remove first object from list
+ */
public void removeFirst() {
if (size > 0) {
size--;
@@ -33,6 +48,11 @@ public void removeFirst() {
}
}
+ /**
+ * Return and remove first object from list
+ *
+ * @return
+ */
public Object get() {
if (size > 0) {
Object temp;
@@ -44,15 +64,26 @@ public Object get() {
return null;
}
+ /**
+ * Remove all object from list
+ */
public void clear() {
object = new Object[1];
size = 0;
}
+ /**
+ * Return current size of fifo
+ *
+ * @return
+ */
public int getSize() {
return size;
}
+ /*
+ * Return true if fifo is empty
+ */
public boolean isEmpty() {
return (size <= 0);
}
View
20 Tamagotchi/src/com/redditandroiddevelopers/tamagotchi/creatures/CommonCreature.java
@@ -40,13 +40,6 @@
* @param creatureDefaultTextureRegion
* @param name
*/
- public void lifeCycle() {
- if (actionT != null)
- if (!fifo.isEmpty() && actionT.isDone()) {
- actionT = (Action) fifo.show();
- action((Action) fifo.get());
- }
- }
public CommonCreature(TextureRegion creatureDefaultTextureRegion, String name) {
super(creatureDefaultTextureRegion, Scaling.stretch, Align.CENTER, name);
@@ -62,6 +55,16 @@ public CommonCreature(TextureRegion creatureDefaultTextureRegion, String name) {
}
/**
+ * Function checking for creature actions, called in MainGameScreen Update()
+ */
+ public void lifeCycle() {
+ if (!fifo.isEmpty() && actionT.isDone()) {
+ actionT = (Action) fifo.show(0);
+ action((Action) fifo.get());
+ }
+ }
+
+ /**
* Gets the specific creature parameters.
*
* @return Creature
@@ -113,8 +116,6 @@ else if (x < 0) {
}
}
fifo.add(parallel);
- // action(parallel);
-
}
/**
@@ -148,7 +149,6 @@ private void jump(float y, float duration) {
public void roll(float x, float duration) {
Parallel parallel = Parallel.$(MoveBy.$(x, 0, duration),
RotateBy.$(x > 0 ? -360f : 360f, duration));
- // action(parallel);
fifo.add(parallel);
}

0 comments on commit 468fd0a

Please sign in to comment.
Something went wrong with that request. Please try again.