1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-26 11:03:28 +00:00

Merge pull request #43 from Klagarge:end-game

finsh text end
This commit is contained in:
Fastium 2022-06-16 19:15:25 +02:00 committed by GitHub
commit ab3292314d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import Entity.Enemy;
import Entity.Entity; import Entity.Entity;
import Game.Battle; import Game.Battle;
import Screen.ScreenBattle; import Screen.ScreenBattle;
import Screen.ScreenEnd;
import Screen.ScreenMap; import Screen.ScreenMap;
import Screen.ScreenPlayer; import Screen.ScreenPlayer;
import ch.hevs.gdx2d.desktop.PortableApplication; import ch.hevs.gdx2d.desktop.PortableApplication;
@ -66,15 +67,22 @@ public class PokeMudry extends PortableApplication {
g.clear(); g.clear();
boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class); boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class);
boolean onBattleScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenBattle.class); boolean onBattleScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenBattle.class);
boolean onEndScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenEnd.class);
long timeNow = System.currentTimeMillis(); long timeNow = System.currentTimeMillis();
if((timeNow-lastMesure) >= 1000){ // one second if((timeNow-lastMesure) >= 1000 && !onEndScreen){ // one second
lastMesure = timeNow; lastMesure = timeNow;
sp.p.removedPv(1); sp.p.removedPv(1);
for (Enemy enemy : enemies) { enemy.recoveredTime++; } 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); if(onMapScreen) sp.p.manageEntity(sp.sm, controller);
@ -89,8 +97,6 @@ public class PokeMudry extends PortableApplication {
if (pv>0 && recovered) { if (pv>0 && recovered) {
sp.sb = sp.screenManager.getScreenBattle();
sp.b = new Battle(sp.e); sp.b = new Battle(sp.e);
sp.sb = sp.screenManager.getScreenBattle(); sp.sb = sp.screenManager.getScreenBattle();

View File

@ -4,7 +4,7 @@ public class Settings {
public static final boolean ANDROID = false; public static final boolean ANDROID = false;
public static final int PLAYERS = 1; 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 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 public static final int SWITCHMAPTIME = 250; // Number of milliseconds the player wait for switch map

View File

@ -15,4 +15,9 @@ public class ManagerOfScreen extends ScreenManager{
this.activateScreen(1); this.activateScreen(1);
return (ScreenBattle)this.getActiveScreen(); return (ScreenBattle)this.getActiveScreen();
} }
public ScreenEnd getScreenEnd(){
this.activateScreen(2);
return (ScreenEnd) this.getActiveScreen();
}
} }

View File

@ -9,11 +9,10 @@ import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import Control.Controller; import Control.Controller;
import Entity.Enemy;
import Entity.Player;
import Game.Battle; import Game.Battle;
import Main.PokeMudry; import Main.PokeMudry;
import Main.Settings; import Main.Settings;
import ch.hevs.gdx2d.components.bitmaps.BitmapImage; import ch.hevs.gdx2d.components.bitmaps.BitmapImage;
import ch.hevs.gdx2d.components.screen_management.RenderingScreen; import ch.hevs.gdx2d.components.screen_management.RenderingScreen;
import ch.hevs.gdx2d.lib.GdxGraphics; import ch.hevs.gdx2d.lib.GdxGraphics;
@ -31,7 +30,6 @@ public class ScreenBattle extends RenderingScreen{
private Battle b = null; private Battle b = null;
private Enemy enemy;
@Override @Override
public void onInit() { public void onInit() {

69
src/Screen/ScreenEnd.java Normal file
View File

@ -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;
}
}

View File

@ -13,6 +13,7 @@ public class ScreenPlayer {
public Battle b = null; public Battle b = null;
public ScreenMap sm = null; public ScreenMap sm = null;
public ScreenBattle sb = null; public ScreenBattle sb = null;
public ScreenEnd se = null;
public void init(){ public void init(){
@ -26,8 +27,11 @@ public class ScreenPlayer {
// Create both type of screen and record for reuse // Create both type of screen and record for reuse
screenManager.registerScreen(ScreenMap.class); screenManager.registerScreen(ScreenMap.class);
screenManager.registerScreen(ScreenBattle.class); screenManager.registerScreen(ScreenBattle.class);
screenManager.registerScreen(ScreenEnd.class);
sb = screenManager.getScreenBattle(); sb = screenManager.getScreenBattle();
se = screenManager.getScreenEnd();
sm = screenManager.getScreenMap(); sm = screenManager.getScreenMap();
} }
@ -42,6 +46,10 @@ public class ScreenPlayer {
b.setPlayer(p); b.setPlayer(p);
sb.setImg(); sb.setImg();
} }
if(se != null){
se.setText(p);
}
screenManager.render(g); screenManager.render(g);
} }

View File

@ -31,10 +31,8 @@ public class FightData {
//add the line in the vector attacks of attack //add the line in the vector attacks of attack
line = bf.readLine(); line = bf.readLine();
System.out.println(line);
while(line != null){ while(line != null){
String[] a = line.split(regex);//change the regex if it is another 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])); attack = new Attack(a[0], a[1], a[2], a[3], a[4], Integer.valueOf(a[5]));
attacks.add(attack); attacks.add(attack);
line = bf.readLine(); line = bf.readLine();