diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index 50a1398..2fcc00b 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -8,6 +8,7 @@ import Entity.Enemy; import Entity.Entity; import Game.Battle; import Screen.ScreenBattle; +import Screen.ScreenEnd; import Screen.ScreenMap; import Screen.ScreenPlayer; import ch.hevs.gdx2d.desktop.PortableApplication; @@ -66,15 +67,22 @@ public class PokeMudry extends PortableApplication { g.clear(); boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class); boolean onBattleScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenBattle.class); + boolean onEndScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenEnd.class); long timeNow = System.currentTimeMillis(); - if((timeNow-lastMesure) >= 1000){ // one second + if((timeNow-lastMesure) >= 1000 && !onEndScreen){ // one second lastMesure = timeNow; sp.p.removedPv(1); for (Enemy enemy : enemies) { enemy.recoveredTime++; } } - if((timeNow-beginTime)/1000 >= 60 * Settings.TIME) System.out.println("Game finished"); + //end of the game + if(sp.p.getPv() <= 0 && !onEndScreen) { + g.zoom(1); + g.resetCamera(); + sp.se = sp.screenManager.getScreenEnd(); + System.out.println("Game finished"); + } if(onMapScreen) sp.p.manageEntity(sp.sm, controller); @@ -89,8 +97,6 @@ public class PokeMudry extends PortableApplication { if (pv>0 && recovered) { - sp.sb = sp.screenManager.getScreenBattle(); - sp.b = new Battle(sp.e); sp.sb = sp.screenManager.getScreenBattle(); diff --git a/src/Main/Settings.java b/src/Main/Settings.java index c12d489..0c89c76 100644 --- a/src/Main/Settings.java +++ b/src/Main/Settings.java @@ -4,7 +4,7 @@ public class Settings { public static final boolean ANDROID = false; public static final int PLAYERS = 1; - public static final int TIME = 10; // number of minutes for kill all enemy + public static final int TIME = 10; // number of minutes for kill all enemy // should be 10 public static final int RECOVERED = 30; // number of seconds an enemy need for recovered public static final int SWITCHMAPTIME = 250; // Number of milliseconds the player wait for switch map diff --git a/src/Screen/ManagerOfScreen.java b/src/Screen/ManagerOfScreen.java index 0d5e92a..a63e4b0 100644 --- a/src/Screen/ManagerOfScreen.java +++ b/src/Screen/ManagerOfScreen.java @@ -15,4 +15,9 @@ public class ManagerOfScreen extends ScreenManager{ this.activateScreen(1); return (ScreenBattle)this.getActiveScreen(); } + + public ScreenEnd getScreenEnd(){ + this.activateScreen(2); + return (ScreenEnd) this.getActiveScreen(); + } } \ No newline at end of file diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index 959e653..3fb10d9 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -9,11 +9,10 @@ import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import Control.Controller; -import Entity.Enemy; -import Entity.Player; import Game.Battle; import Main.PokeMudry; import Main.Settings; + import ch.hevs.gdx2d.components.bitmaps.BitmapImage; import ch.hevs.gdx2d.components.screen_management.RenderingScreen; import ch.hevs.gdx2d.lib.GdxGraphics; @@ -31,7 +30,6 @@ public class ScreenBattle extends RenderingScreen{ private Battle b = null; - private Enemy enemy; @Override public void onInit() { diff --git a/src/Screen/ScreenEnd.java b/src/Screen/ScreenEnd.java new file mode 100644 index 0000000..8627ab6 --- /dev/null +++ b/src/Screen/ScreenEnd.java @@ -0,0 +1,69 @@ +package Screen; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; + +import Control.Controller; +import Entity.Player; +import Game.Battle; +import Main.PokeMudry; +import Main.Settings; + +import ch.hevs.gdx2d.components.bitmaps.BitmapImage; +import ch.hevs.gdx2d.components.screen_management.RenderingScreen; +import ch.hevs.gdx2d.lib.GdxGraphics; + +public class ScreenEnd extends RenderingScreen{ + + private String textEnd = null; + private BitmapFont unbuntuRegularWhite; + + + @Override + public void onInit() { + unbuntuRegularWhite = generateFont("./Data/font/Ubuntu-Regular.ttf", 30, Color.WHITE); + + } + + @Override + protected void onGraphicRender(GdxGraphics g) { + g.clear(Color.BLACK); + if(textEnd != null) g.drawStringCentered(Settings.SIDE/2, textEnd, unbuntuRegularWhite); + + } + + @Override + public void dispose() { + unbuntuRegularWhite.dispose(); + } + + public void setText(Player p){ + if(p.getXp() >= p.getXpMax()){ + textEnd = "Bravo, tu as réussi ton année avec " + p.getXp()/100.0 + " crédits en " + (Settings.TIME*60-p.getPv()) + " secondes.\n\nMais, seras-tu près pour le prochain...."; + } + else{ + textEnd = "L'année est terminée et tu as obtenu " + p.getXp()/100.0 + " crédits.\n\nA l'année prochaine..."; + } + } + + + public BitmapFont generateFont(String file, int height, Color c ){ + //Generate font with the file .ttf + BitmapFont font; + FileHandle fileHandle = Gdx.files.internal(file); + FreeTypeFontParameter parameter = new FreeTypeFontParameter(); + FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle); + parameter.size = generator.scaleForPixelHeight(height); + parameter.color = c; + font = generator.generateFont(parameter); + generator.dispose(); + return font; + + } + +} diff --git a/src/Screen/ScreenPlayer.java b/src/Screen/ScreenPlayer.java index 6835a64..828eacf 100644 --- a/src/Screen/ScreenPlayer.java +++ b/src/Screen/ScreenPlayer.java @@ -13,6 +13,7 @@ public class ScreenPlayer { public Battle b = null; public ScreenMap sm = null; public ScreenBattle sb = null; + public ScreenEnd se = null; public void init(){ @@ -26,8 +27,11 @@ public class ScreenPlayer { // Create both type of screen and record for reuse screenManager.registerScreen(ScreenMap.class); screenManager.registerScreen(ScreenBattle.class); + screenManager.registerScreen(ScreenEnd.class); sb = screenManager.getScreenBattle(); + se = screenManager.getScreenEnd(); sm = screenManager.getScreenMap(); + } @@ -42,6 +46,10 @@ public class ScreenPlayer { b.setPlayer(p); sb.setImg(); } + + if(se != null){ + se.setText(p); + } screenManager.render(g); } diff --git a/src/Text/FightData.java b/src/Text/FightData.java index 3a2840e..43fec5e 100644 --- a/src/Text/FightData.java +++ b/src/Text/FightData.java @@ -30,10 +30,8 @@ public class FightData { //add the line in the vector attacks of attack line = bf.readLine(); - System.out.println(line); while(line != null){ String[] a = line.split(regex);//change the regex if it is another - System.out.println(a.length); attack = new Attack(a[0], a[1], a[2], a[3], a[4], Integer.valueOf(a[5])); attacks.add(attack); line = bf.readLine();