game.ExperienceManager = Object.extend({
	init: function(x, y, settings){
		this.alwaysUpdate = true;
		//makes it that you will not gain extra exp from destroying a tower.
		this.gameOver = false;
	},

	update: function(){
		if(game.data.win === true && !this.gameover){
			this.gameOver(true);
			alert("win");
		}
		else if(game.data.win === false && !this.gameover){
			this.gameOver(false);
			alert("lost");
		}
		return true;
	},

	gameOver: function(win){
		if(win){
			game.data.exp += 10;
		}	
		else{
			game.data.exp += 1;
		}
		this.gameover = true;
		me.save.exp = game.data.exp;

		$.ajax({
				type: "POST",
				url: "php/controller/save-user.php",
				data: {
					exp: game.data.exp,
					exp1: game.data.exp1,
					exp2: game.data.exp2,
					exp3: game.data.exp3,
					exp4: game.data.exp4,
				},
				dataType: "text"
			})
			.success(function(response){
				if(response===true){
					me.state.change(me.state.MENU);
				}
				else{
					alert(response);
				}
			})
			.fail(function(response){
				alert("fail");
			});

	},
});
