package org.sistema.spring.autowiring.models;

import java.util.Random;

/**
 * Represents a Javamon creature
 * 
 * @author Eugenia Pérez Martínez
 *
 */
public class Javamon {

	private String name;
	private int strength;
	private int defence;
	private int agility;
	private int life;
	private Random random = new Random();

	/**
	 * constructor
	 * 
	 * @param nombre
	 */
	public Javamon(String nombre) {
		this.name = nombre;
		initAttributes();
	}

	/**
	 * intis javamon attributes randomly
	 */
	private void initAttributes() {
		int pointsToDeal = 18;

		// to what attrib we give the points in each loop
		int whatAttrib = 0;

		// points to give at most en each loop
		int max = 0;

		// first they are 0
		strength = defence = agility = 0;
		while (pointsToDeal > 0) {
			whatAttrib = random.nextInt(3);
			switch (whatAttrib) {
			case 0:
				strength++;
				break;
			case 1:
				defence++;
				break;
			case 2:
				agility++;
				break;
			default:
				break;
			}

			pointsToDeal--;
		}

		life = strength + defence + 6;
	}

	/**
	 * an initiative roll
	 * 
	 * @return
	 */
	public int initiative() {
		return agility + random.nextInt(6);
	}

	/**
	 * an attacking roll
	 * 
	 * @return
	 */
	public int attack() {
		return strength + random.nextInt(6);
	}

	/**
	 * a defending roll
	 * 
	 * @return
	 */
	public int defend() {
		return ((agility + defence) / 2) + random.nextInt(6);
	}

	/**
	 * javamon status description
	 * 
	 * @return
	 */
	public String status() {
		return name + "(" + life + ")| S:" + strength + "| D:" + defence
				+ "| A:" + agility;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getStrength() {
		return strength;
	}

	public void setStrength(int strength) {
		this.strength = strength;
	}

	public int getDefence() {
		return defence;
	}

	public void setDefence(int defence) {
		this.defence = defence;
	}

	public int getAgility() {
		return agility;
	}

	public void setAgility(int agility) {
		this.agility = agility;
	}

	public int getLife() {
		return life;
	}

	public void setLife(int life) {
		this.life = life;
	}

	public Random getRandom() {
		return random;
	}

	public void setRandom(Random random) {
		this.random = random;
	}

}
