package slimpleslickgame;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Vector2f;

import util.Logger;

public class Stats {
	
	private float x, y;
	private int credits = 0;
	private int level = 1;
	private int time = 0;
	private boolean tryUpgrade = false;
	private int hp = 100;
	private int incomeRate = 1000;
	
	public Stats(Vector2f scoreBoardPos) {
		this.x = scoreBoardPos.x;
		this.y = scoreBoardPos.y;
	}

	public void render(Graphics graphics){
		graphics.drawString("Credits: " + credits , x, y-graphics.getFont().getLineHeight());
		graphics.drawString("HP: "+ hp , x, y);
	}
	
	public boolean update(int delta, int score){
		credits = score;
		return this.update(delta);
	}
	
	public boolean update(int delta){
		int levelCredits = 350;
		if(this.credits >= levelCredits && this.tryUpgrade){
			level++;
			this.credits -= levelCredits;
			Logger.log("Upgraded player!");
			return true;
		}
		this.tryUpgrade = false;
		return false;
	}

	public void putUpgradePressed() {
		this.tryUpgrade = true;
	}

	public int calcCredits(int delta, int scoreDiff) {
		int creditsDiff = scoreDiff;
		this.time += delta;
		while(time > incomeRate){
			time -= incomeRate;
			creditsDiff += level;
		}
		this.credits += creditsDiff;
		return this.credits;
	}

	private static final int CREEP_PRICE_1 = 100;
	private static final int CREEP_PRICE_5 = 250;
	private static final int CREEP_PRICE_10 = 250;
	
	public int buyCreeps(int key) {
		switch(key){
			case 1:
				if(this.credits >= CREEP_PRICE_1){
					credits -= CREEP_PRICE_1;
					this.incomeRate--;
					return 1;
				}
				break;
			case 2:
				if(this.credits >= CREEP_PRICE_5){
					credits -= CREEP_PRICE_5;
					this.incomeRate -= 6;
					return 5;
				}
				break;
			case 3:
				if(this.credits >= CREEP_PRICE_10){
					credits -= CREEP_PRICE_10;
					this.incomeRate -= 25;
					return 10;
				}
				break;
		}
		return 0;
	}
	
	public int damaged() {
		hp--;
		return hp;
	}

	public void setHP(int playerHp) {
		this.hp = playerHp;
	}

}

@@ -1315,18 +1315,17 @@
 ICE_1 = 
-10
+5
 0;%0A%09priv
@@ -1358,25 +1358,25 @@
 _PRICE_5 = 2
-5
+0
 0;%0A%09private 
@@ -1413,11 +1413,150 @@
 0 = 
-250
+400;%0A%09%0A%09private static final int INCOME_RATE_1 = 1;%0A%09private static final int INCOME_RATE_5 = 6;%0A%09private static final int INCOME_RATE_10 = 15
 ;%0A%09%0A
@@ -1704,18 +1704,33 @@
 comeRate
---
+ -= INCOME_RATE_1
 ;%0A%09%09%09%09%09r
@@ -1860,17 +1860,29 @@
 Rate -= 
-6
+INCOME_RATE_5
 ;%0A%09%09%09%09%09r
@@ -2018,10 +2018,22 @@
  -= 
-25
+INCOME_RATE_10
 ;%0A%09%09

fix creep prices