/* 
----------------------------------------------------------------
high scores
----------------------------------------------------------------
when a game is over, see if score is higher than lowest.
let's be generous + bump if equal.
insert new score at correct point
snip score array down to limit 
*/

var high_score = [];
var high_score_table_length = 12;
var last_score_index = 0;

// to be called once when the program initializes
function initialize_high_scores() {
	load_high_scores();
}


function score_data(score, player, wave) {
	this.score = score;
	this.player = player;
	this.wave = wave;
	// add name data?
}


function clear_scores() {
	for (var i = 0; i < high_score_table_length; i ++) {
		high_score[i] = new score_data(0, 0, 0);
	}
}

// to be called on game over
function evaluate_score(data) {
	// start assuming we don't place among the highest scores
	var place = high_score_table_length;

	for (var i = high_score_table_length - 1; i >= 0; i --) {
		var current = high_score[i];
		if (data.score >= current.score) {
			place = i;
		}
	}

	console.log("score = " + data.score + ". ranked place = " + place);

	// insert into array
	high_score.splice(place, 0, data);
	// remember which is is + highlight it
	last_score_index = place;
}


function file_high_score() {
	var data = new score_data(score, 0, wave - 1);
	evaluate_score(data);
}

