<commit_before>package edu.oswego.tiltandtumble.levels;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Disposable;

import edu.oswego.tiltandtumble.collisionListener.OurCollisionListener;
import edu.oswego.tiltandtumble.worldObjects.Ball;

public class Level implements Disposable {

	private static enum State {
		NOT_STARTED,
		STARTED,
		FINISHED
	};

	private final World world = new World(new Vector2(0, 0), true);
	private final ContactListener contactListener;
	private final TiledMap map;
	private final Ball ball;
	private final BallController ballController;

	private final UnitScale scale = new UnitScale(1f/64f);

	private final int level;
	private State currentState;
	//times are in seconds
	private double startTime;
	private double endTime;
	public double totalTime;
	public int score;

	public Level(int level, BallController ballController, WorldPopulator populator) {
		this.level = level;
		this.ballController = ballController;
		
		//Setting default score to 1000
		score = 1000;
		
		currentState = State.NOT_STARTED;

		// TODO: allow for map properties to be used to customize the level
		//       behavior if needed...
		map = loadMap(level);

		ball = populator.populateWorldFromMap(this, map, world, scale);
		this.ballController.setBall(ball);

		contactListener = new OurCollisionListener();
		world.setContactListener(contactListener);
	}

	public TiledMap getMap() {
		return map;
	}

	public World getWorld() {
		return world;
	}

	public UnitScale getScale() {
		return scale;
	}

	public Ball getBall() {
		return ball;
	}

	public boolean hasNotStarted() {
		return currentState == State.NOT_STARTED;
	}

	public void start() {
		if (currentState == State.NOT_STARTED) {
			currentState = State.STARTED;
		}
		recordStartTime();
	}

	public boolean isStarted() {
		return currentState == State.STARTED;
	}
	
	private void recordStartTime(){
		if(isStarted()){
			startTime = System.nanoTime()*Math.pow(10.0, -9.0);
		}
	}

	public void finish() {
		if (currentState == State.STARTED) {
			currentState = State.FINISHED;
		}
		recordEndTime();
	}

	public boolean hasFinished() {
		return currentState == State.FINISHED;
	}
	
	private void recordEndTime(){
		if(hasFinished()){
			endTime = System.nanoTime()*Math.pow(10.0, -9.0);
		}
	}
	
	private double getCurrentTime(){
		
		double currentTime = System.nanoTime()*Math.pow(10.0, -9.0);
		return currentTime;
		
	}
	public double getTotalScore(){
		
		totalTime = endTime - startTime;
		return totalTime;
	}
	
	private void decrementScore(){
		
		//the "difference" is the difference in seconds and for every 1 second the time elapses, 10 points will be taken off
		int difference = (int)(getCurrentTime() - startTime);			
		score = 1000-10*difference;		
	}

	private TiledMap loadMap(int level) {
		if (Gdx.files.internal("data/level" + level + ".tmx").exists()) {
			return new TmxMapLoader().load("data/level" + level + ".tmx");
		}
		throw new RuntimeException("data/level" + level + ".tmx does not exist");
	}

	public int getLevelNumber() {
		return level;
	}

	public void draw(SpriteBatch batch) {
		ball.draw(batch);
	}

	public void update() {
		if (currentState == State.STARTED) {
			ballController.update();
			
			//calling to update the score
			decrementScore();
			
			// world.step(1/60f, 6, 2);
			world.step(1 / 45f, 10, 8);
		}
	}

	@Override
	public void dispose() {
		world.dispose();
		ball.dispose();
	}<commit_msg>added back in removed function used by the rest of the code for scoring. made the added scoring code work with the previously stubbed out function.<commit_after>package edu.oswego.tiltandtumble.levels;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.TimeUtils;

import edu.oswego.tiltandtumble.collisionListener.OurCollisionListener;
import edu.oswego.tiltandtumble.data.Score;
import edu.oswego.tiltandtumble.worldObjects.Ball;

public class Level implements Disposable {

	private static enum State {
		NOT_STARTED,
		STARTED,
		FINISHED
	};

	private final World world = new World(new Vector2(0, 0), true);
	private final ContactListener contactListener;
	private final TiledMap map;
	private final Ball ball;
	private final BallController ballController;

	private final UnitScale scale = new UnitScale(1f/64f);

	private final int level;
	private State currentState;

	private final Score score;
	//times are in milliseconds
	private long startTime;

	public Level(int level, BallController ballController, WorldPopulator populator) {
		this.level = level;
		this.ballController = ballController;

		// TODO: Setting default score to 1000, figure out a good value for this...
		score = new Score(1000, 0);

		currentState = State.NOT_STARTED;

		// TODO: allow for map properties to be used to customize the level
		//       behavior if needed...
		map = loadMap(level);

		ball = populator.populateWorldFromMap(this, map, world, scale);
		this.ballController.setBall(ball);

		contactListener = new OurCollisionListener();
		world.setContactListener(contactListener);
	}

	public TiledMap getMap() {
		return map;
	}

	public World getWorld() {
		return world;
	}

	public UnitScale getScale() {
		return scale;
	}

	public Ball getBall() {
		return ball;
	}

	public Score getScore() {
		return score;
	}

	public boolean hasNotStarted() {
		return currentState == State.NOT_STARTED;
	}

	public void start() {
		if (currentState == State.NOT_STARTED) {
			currentState = State.STARTED;
		}
		startTime = TimeUtils.millis();
	}

	public boolean isStarted() {
		return currentState == State.STARTED;
	}

	public void finish() {
		if (currentState == State.STARTED) {
			currentState = State.FINISHED;
			decrementScore();
		}
	}

	public boolean hasFinished() {
		return currentState == State.FINISHED;
	}

	private void decrementScore() {
		// the "difference" is the difference in seconds and for every 1 second the time elapses, 10 points will be taken off
		long difference = (TimeUtils.millis() - startTime) / 1000;
		score.setPoints((int)(1000 - difference));
		score.setTime((int)difference);
	}

	private TiledMap loadMap(int level) {
		if (Gdx.files.internal("data/level" + level + ".tmx").exists()) {
			return new TmxMapLoader().load("data/level" + level + ".tmx");
		}
		throw new RuntimeException("data/level" + level + ".tmx does not exist");
	}

	public int getLevelNumber() {
		return level;
	}

	public void draw(SpriteBatch batch) {
		ball.draw(batch);
	}

	public void update() {
		if (currentState == State.STARTED) {
			ballController.update();

			decrementScore();

			// world.step(1/60f, 6, 2);
			world.step(1 / 45f, 10, 8);
		}
	}

	@Override
	public void dispose() {
		world.dispose();
		ball.dispose();
	}
{'fraction_non_alphanumeric': 0.11150684931506849, 'fraction_numerical': 0.012876712328767123, 'mean_word_length': 3.997262149212868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1791705', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2355, 'n_words': 624}