/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tetris2;

/**
 *
 * @author Fmunch
 */
public class TetrisGameType implements GameType {

  String name;
  int start;
  int blockpts;
  int linepts;
  int speed;

  TetrisGameType() {
  }

  TetrisGameType(String str) {
    initialize(str);
  }

  public boolean initialize(String type) {
    String[] res = type.split(":");
    if (res.length != 5) {
      return false;
    }
    try {
      start = Integer.parseInt(res[1]);
      speed = Integer.parseInt(res[2]);
      linepts = Integer.parseInt(res[3]);
      blockpts = Integer.parseInt(res[4]);
      name = res[0];
    } catch (NumberFormatException nfe) {
      System.err.println("NFE on inializing a TetrisGameType object");
      return false;
    }
    return true;
  }

  public int getStart() {
    return start;
  }

  public int getSpeed() {
    return speed;
  }

  public int getLinePoints() {
    return linepts;
  }

  public int getBlockPoints() {
    return blockpts;
  }

  public String getName() {
    return name;
  }

  public boolean isEmpty() {
    return name == null;
  }

  public void setStart(int i) {
    start = i;
  }

  public void setSpeed(int i) {
    speed = i;
  }

  public void setLinePoints(int i) {
    linepts = i;
  }

  public void setBlockPoints(int i) {
    blockpts = i;
  }

  public String getInitFormat() {
    return String.format("start:speed:linepoints:blockpoints");
  }

  public int compareTo(Object o) {
    if (!(o instanceof TetrisGameType)) {
      return -1;
    }
    int res = start - ((TetrisGameType) (o)).start;
    if (res == 0) {
      return name.compareTo(((TetrisGameType) (o)).name);
    }
    return res;
  }

  @Override
  public String toString() {
    return name + ":" + start + ":" + speed + ":" + linepts + ":" + blockpts;
  }
}

