package ie.gmit.sw.ai;

import javax.imageio.*;
import java.awt.image.*;

public class Sprite {
	private String name; //The name of this sprite
	private BufferedImage[] frames; //The set of image frames to animate
 	private int index = 0; //Initial starting index in array

	//private double lifeForce = 500;

	/*

	Sprite will contain the movement code.
	Added vars to keep track of row and col in Maze.
	Change maze to AtomicReferenceArray (it's concurrent)
	Make Maze.java Singleton? so the reference can be obtained
    Thread movement stuff.

    To move, search maze array to decide where to move.
    Once a spot is picked, take self out of Maze array and place self into new spot.
    Sprite can't move while attacking or when attacked.

	 */
 	
	public Sprite(String name, String... images) throws Exception{
		this.name = name;
		this.index = 0; //Initialise the starting index to zero
		this.frames = new BufferedImage[images.length]; //Initialise the image frames
		
		for (int i = 0; i < images.length; i++){
			frames[i] = ImageIO.read(new java.io.File(images[i])); //Read in each image as a BufferedImage
		}
	}

	// public double engage(double weapon, double anger){

	// 	NeuralNetwork nn = NeuralNetworkFactory.getInstance().getNetwork("engage");
	// 	double[] inputs = {weapon, anger};
	// 	double result = nn.process(inputs);
	// 	lifeForce += result;

	// 	FIS fis = FuzzyLogicFactory.getInstance().getFIS("engage");
	// 	double result = fis.evaluate(weapon, anger);
	// 	lifeForce += result;

	// }

	// public boolean isAlive(){

	// 	return lifeForce > 0;
	// }
	
	public BufferedImage getNext(){ //Returns the next image frame
		int idx = index;
		if (index < frames.length - 1){
			index++;
		}else{
			index = 0; //Circle back to the start of the array
		}
		return frames[idx]; 
	}
	
	public String getName(){
		return this.name;
	}
}

@@ -270,1319 +270,381 @@
 ray%0A
-%0A%09//private double lifeForce = 500;%0A%0A%09/*%0A%0A%09Sprite will contain the movement code.%0A%09Added vars to keep track of row and col in Maze.%0A%09Change maze to AtomicReferenceArray (it's concurrent)%0A%09Make Maze.java Singleton? so the reference can be obtained%0A    Thread movement stuff.%0A%0A    To move, search maze array to decide where to move.%0A    Once a spot is picked, take self out of Maze array and place self into new spot.%0A    Sprite can't move while attacking or when attacked.%0A%0A%09 */%0A %09%0A%09public Sprite(String name, String... images) throws Exception%7B%0A%09%09this.name = name;%0A%09%09this.index = 0; //Initialise the starting index to zero%0A%09%09this.frames = new BufferedImage%5Bimages.length%5D; //Initialise the image frames%0A%09%09%0A%09%09for (int i = 0; i %3C images.length; i++)%7B%0A%09%09%09frames%5Bi%5D = ImageIO.read(new java.io.File(images%5Bi%5D)); //Read in each image as a BufferedImage%0A%09%09%7D%0A%09%7D%0A%0A%09// public double engage(double weapon, double anger)%7B%0A%0A%09// %09NeuralNetwork nn = NeuralNetworkFactory.getInstance().getNetwork(%22engage%22);%0A%09// %09double%5B%5D inputs = %7Bweapon, anger%7D;%0A%09// %09double result = nn.process(inputs);%0A%09// %09lifeForce += result;%0A%0A%09// %09FIS fis = FuzzyLogicFactory.getInstance().getFIS(%22engage%22);%0A%09// %09double result = fis.evaluate(weapon, anger);%0A%09// %09lifeForce += result;%0A%0A%09// %7D%0A%0A%09// public boolean isAlive()%7B%0A%0A%09// %09return lifeForce %3E 0;%0A%09// 
+%09%0A%09public Sprite(String name, String... images) throws Exception%7B%0A%09%09this.name = name;%0A%09%09this.index = 0; //Initialise the starting index to zero%0A%09%09this.frames = new BufferedImage%5Bimages.length%5D; //Initialise the image frames%0A%09%09%0A%09%09for (int i = 0; i %3C images.length; i++)%7B%0A%09%09%09frames%5Bi%5D = ImageIO.read(new java.io.File(images%5Bi%5D)); //Read in each image as a BufferedImage%0A%09%09%7D%0A%09
 %7D%0A%09%0A

Update Sprite.java