Replace LinkedList with List, so it is possible to change its implementation later - if needed.

This commit is contained in:
Jan Philipp Timme 2014-11-06 18:19:35 +01:00
parent 9542131e4a
commit c4ab7c3530
9 changed files with 23 additions and 22 deletions

View File

@ -1,6 +1,6 @@
package de.teamteamteam.spacescooter.background.item;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.LivingEntity;
@ -20,7 +20,7 @@ public abstract class Items extends LivingEntity{
this.remove();
};
if(!this.isAlive()){
LinkedList<Entity> entities = Screen.currentScreen.getEntities();
List<Entity> entities = Screen.currentScreen.getEntities();
for (Entity e : entities) {
if(e instanceof Player){
itemCollected((Player) e);

View File

@ -2,7 +2,7 @@ package de.teamteamteam.spacescooter.entity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.screen.Screen;
@ -18,7 +18,7 @@ public class HealthBar extends Entity {
}
public void paint(Graphics2D g) {
LinkedList<Entity> entities = Screen.currentScreen.getEntities();
List<Entity> entities = Screen.currentScreen.getEntities();
for (Entity e : entities) {
if(e instanceof Player){
this.width = ((Player) e).getHealthPoints();

View File

@ -1,7 +1,7 @@
package de.teamteamteam.spacescooter.entity;
import java.awt.Rectangle;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.background.item.Items;
import de.teamteamteam.spacescooter.entity.enemy.Enemy;
@ -25,7 +25,7 @@ public abstract class LivingEntity extends Entity implements Collidable {
public void update() {
if(!(this instanceof ShootingEntity)) return; //Only check collisions for ShootingEntity.
LinkedList<Entity> entities = Screen.currentScreen.getEntities();
List<Entity> entities = Screen.currentScreen.getEntities();
for (Entity e : entities) {
if (e.equals(this)) //Do not collide with myself!
continue;

View File

@ -1,7 +1,7 @@
package de.teamteamteam.spacescooter.entity.enemy;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import de.teamteamteam.spacescooter.background.item.Items;
@ -41,7 +41,7 @@ public class EnemyThree extends Enemy{
if(random.nextInt(10) < 5) Items.create(getX(), getY());
new EnemyThree(0, 0);
}
LinkedList<Entity> list = Screen.currentScreen.getEntities();
List<Entity> list = Screen.currentScreen.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
Entity entity = i.next();

View File

@ -6,7 +6,7 @@ import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Entity;
@ -38,7 +38,7 @@ public class GameOverScreen extends Screen {
@Override
protected void paint(Graphics2D g) {
g.drawImage(this.img, 0, 0, null);
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().paint(g);
@ -54,7 +54,7 @@ public class GameOverScreen extends Screen {
@Override
protected void update() {
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().update();

View File

@ -6,7 +6,7 @@ import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Entity;
@ -38,7 +38,7 @@ public class GamePausedScreen extends Screen {
@Override
protected void paint(Graphics2D g) {
g.drawImage(this.img, 0, 0, null);
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().paint(g);
@ -54,7 +54,7 @@ public class GamePausedScreen extends Screen {
@Override
protected void update() {
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().update();

View File

@ -5,7 +5,7 @@ import java.awt.Point;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.background.StarBackground;
import de.teamteamteam.spacescooter.background.item.ItemChance;
@ -36,7 +36,7 @@ public class GameScreen extends Screen {
@Override
protected void paint(Graphics2D g) {
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().paint(g);
@ -45,7 +45,7 @@ public class GameScreen extends Screen {
@Override
protected void update() {
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().update();

View File

@ -6,7 +6,7 @@ import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.background.StarBackground;
import de.teamteamteam.spacescooter.control.Keyboard;
@ -40,7 +40,7 @@ public class MainMenuScreen extends Screen {
@Override
public void paint(Graphics2D g) {
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().paint(g);
@ -59,7 +59,7 @@ public class MainMenuScreen extends Screen {
@Override
public void update() {
LinkedList<Entity> list = this.getEntities();
List<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().update();

View File

@ -2,6 +2,7 @@ package de.teamteamteam.spacescooter.screen;
import java.awt.Graphics2D;
import java.util.LinkedList;
import java.util.List;
import de.teamteamteam.spacescooter.entity.Entity;
@ -32,7 +33,7 @@ public abstract class Screen {
/**
* List of entities this screen is taking care of
*/
protected LinkedList<Entity> entities;
protected List<Entity> entities;
/**
* Initialize parent, overlay and the Entity list
@ -61,7 +62,7 @@ public abstract class Screen {
this.entities.remove(e);
}
public LinkedList<Entity> getEntities() {
public List<Entity> getEntities() {
return new LinkedList<Entity>(this.entities);
}