Package ch.bfh.ti.kybernetik.gui.slick.components

Source Code of ch.bfh.ti.kybernetik.gui.slick.components.RoboterMoveListComponent

/**
* Copyright (C) BFH www.bfh.ch 2011
* Code written by: Patrick Dobler, Marc Folly
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package ch.bfh.ti.kybernetik.gui.slick.components;

import java.util.Iterator;
import java.util.List;

import javax.vecmath.Point2d;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import ch.bfh.ti.kybernetik.engine.model.Roboter;
import ch.bfh.ti.kybernetik.engine.model.RoboterMove;

/**
* This Class renders the a {@link List} of {@link RoboterMove} instances
*
*/
public class RoboterMoveListComponent implements SlickComponent<List<RoboterMove>> {

  private List<RoboterMove> moves;

  private Color color;

  private final Roboter roboter;

  /**
   * Creates a new {@link RoboterMoveListComponent}
   *
   * @param roboter
   *            instance to identify to which {@link Roboter} the
   *            {@link RoboterMove} belong to
   */
  public RoboterMoveListComponent(Roboter roboter) {
    super();
    this.roboter = roboter;
  }

  @Override
  public void render(GameContainer gc, Graphics g) throws SlickException {
    renderRoboterTrack(g);
  }

  private void renderRoboterTrack(final Graphics g) {
    g.setColor(this.getColor());
    final Point2d oldPoint = new Point2d(-1, -1);
    Iterator<RoboterMove> it = moves.iterator();
    while (it.hasNext()) {
      RoboterMove roboterMoveState = it.next();
      if (oldPoint.getX() != -1) {
        g.drawLine((float) roboterMoveState.getNewRoboterPoint().getX(), (float) roboterMoveState.getNewRoboterPoint().getY(),
            (float) oldPoint.getX(), (float) oldPoint.getY());
      }
      oldPoint.setX(roboterMoveState.getNewRoboterPoint().getX());
      oldPoint.setY(roboterMoveState.getNewRoboterPoint().getY());
    }
  }

  public void setMoves(List<RoboterMove> moves) {
    this.moves = moves;
  }

  @Override
  public List<RoboterMove> getModelObject() {
    return this.moves;
  }

  public void setColor(Color color) {
    this.color = color;
  }

  public Color getColor() {
    return color;
  }

  public Roboter getRoboter() {
    return roboter;
  }
}
TOP

Related Classes of ch.bfh.ti.kybernetik.gui.slick.components.RoboterMoveListComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.