package example;

import java.util.Iterator;

import xooga.*;
import xooga.model.level.Level;
import xooga.model.physicalObjects.GamePiece;

/**
 * 
 * @author Jadrian Miles
 * @version Nov 15, 2004
 */
public class TestLevel extends Level {
    public void initialize()
    {
        myGravity = new Vector2D(0,-9);
        Wall bot = new Wall(new Vector2D(-5,0), new Vector2D(25,5));
        Wall left = new Wall(new Vector2D(-5,15), new Vector2D(5,15));
        Wall right = new Wall(new Vector2D(15,15), new Vector2D(5,15));
        Ball ball1 = new Ball(new Vector2D(2,11), new Vector2D(1,1), 6);
        Ball ball2 = new Ball(new Vector2D(11,8), new Vector2D(1,1), 3);
        ball1.myVel = new Vector2D(5,0);
        ball2.myVel = new Vector2D(-3,2);
        addToGameState(bot);
        addToGameState(left);
        addToGameState(right);
        addToGameState(ball1);
        addToGameState(ball2);
    }
    
    public boolean won() {
        return isDynamicStateEmpty();
    }
    
    public boolean lost() {
        return false;
    }
    
    /**
     * Called at the end of the innermost game loop, this maintains the dynamic
     * game state and does other miscellaneous upkeep functions.
     * @param dt
     *            The amount of time, in seconds, that has passed since the
     *            last cleanup call.
     * @see xooga.model.game.Game#update()
     */
    public void cleanup(double dt)
    {
    	// waste a little time; this would ordinarily be taken up by rendering
        int j = 2;
        for(int i = 1; i < 300000; i++) {
            j = j * j * j / i;
        }
        GamePiece cur = null;
        Iterator it = getDynamicStateIterator();
        while(it.hasNext()) {
            cur = (GamePiece) it.next();
            if(! cur.cleanup()) {
                it.remove();
            } else {
                System.out.print(cur.getPos().toString() + "\t" +
                        cur.myVel.toString() + "\t");
            }
        }
        System.out.println();
        updateViewframe(dt);
    }
}
