Commit 0a36a8ee authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Cleaning up.

parent c9b092e2
Loading
Loading
Loading
Loading
+19 −19
Original line number Diff line number Diff line
package edu.bu.ec504.spr19.highScores;
package edu.bu.ec504.spr24.highScores;

import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -25,8 +25,8 @@ public class highScore {
	/*
	 * where the high score database is kept
	 */
	private final String dataFile;
	private final TreeSet<HSdata> db;
	private final String _dataFile;
	private final TreeSet<HSdata> _db;

	// SUBCLASSES
	/**
@@ -72,9 +72,9 @@ public class highScore {
	 * @param fileName The name of the file to use for high score information.
	 */
	public highScore(String fileName) {
		dataFile = fileName;
		db = new TreeSet<>(new hsComp());
		loadScores();
		_dataFile = fileName;
		_db = new TreeSet<>(new hsComp());
		_loadScores();
	}


@@ -85,10 +85,10 @@ public class highScore {
	 */
	public boolean putScore(HSdata foo) {
		if (newRecordQ(foo.score)) {
			db.add(foo);
			while (db.size()>maxScores)
				db.remove(db.last());
			saveScores();
			_db.add(foo);
			while (_db.size()>maxScores)
				_db.remove(_db.last());
			_saveScores();
			return true;
		}
		else
@@ -100,10 +100,10 @@ public class highScore {
	 * @return true iff score is a new record on the high score list.
	 */
	public boolean newRecordQ(int score) {
		if (db.isEmpty()) // nothing in the db so far
		if (_db.isEmpty()) // nothing in the db so far
			return true;
		else
			return (db.size()<maxScores-1 || score > db.last().score);
			return (_db.size()<maxScores-1 || score > _db.last().score);
	}


@@ -112,7 +112,7 @@ public class highScore {
	 */
	public String display() {
		StringBuilder temp= new StringBuilder();
		for (HSdata foo: db) {
		for (HSdata foo: _db) {
			temp.append(hsComp.weightedScore(foo)).append(" [weighted]: ").append(foo.score).append("[actual] (").append(foo.name).append(" on ").append(foo.boardSizeX).append("x").append(foo.boardSizeY).append(")\n");

		}
@@ -123,10 +123,10 @@ public class highScore {
	/**
	 * Load high scores from the associated file.
	 */
	private void loadScores() {
	private void _loadScores() {
		FileInputStream fis;
		try {
			fis = new FileInputStream(dataFile);
			fis = new FileInputStream(_dataFile);
			DataInputStream in = new DataInputStream(fis);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
@@ -134,7 +134,7 @@ public class highScore {
			while ((strLine = br.readLine()) != null) {
				String[] res = strLine.split("\t");
				HSdata temp = new HSdata(res[0],new Integer(res[1]),new Integer(res[2]), new Integer(res[3]));
				db.add(temp);
				_db.add(temp);
			}
		} catch (FileNotFoundException e) {
			System.err.println("High score file not found - Starting fresh!");
@@ -146,14 +146,14 @@ public class highScore {
	/**
	 * Save current database to the associated file.
	 */
	private void saveScores() {
	private void _saveScores() {
		FileOutputStream fos;
		try {
			fos = new FileOutputStream(dataFile);
			fos = new FileOutputStream(_dataFile);
			DataOutputStream out = new DataOutputStream(fos);
			BufferedWriter br = new BufferedWriter(new OutputStreamWriter(out));

			for (HSdata foo: db) {
			for (HSdata foo: _db) {
				br.write(foo.name+"\t"+foo.boardSizeX+"\t"+foo.boardSizeY+"\t"+foo.score+"\n");
			}

Loading