Skip to content
Snippets Groups Projects
Select Git revision
  • 837734af5fe7ea736b23f1ec4e652bc3f80b7e6c
  • main default protected
  • 39-retour-utilisateur-sur-le-compteur
3 results

Level.java

Blame
  • Level.java 5.04 KiB
    package bitFight;
    
    import java.io.IOException;
    import java.util.Scanner;
    
    public class Level{
    
        int nbLevel;
        Player player;
        Enemy ennemy;
    
        public Level(int nbLevel, Player player, Enemy ennemy){
            this.nbLevel=nbLevel;
            this.player = player;
            this.ennemy = ennemy;
        }
        
        // accesseurs 
        public int getNbLevel() {
            return nbLevel;
        }
        public Enemy getEnnemy() {
            return ennemy;
        }
        public Player getPlayer() {
            return player;
        }
    
        // mutateurs
        public void setNbLevel(int nbLevel) {
            this.nbLevel = nbLevel;
        }
        
        public void setEnnemy(Enemy ennemy) {
            this.ennemy = ennemy;
        }
        public void setPlayer(Player player) {
            this.player = player;
        }
    
        // sert seulement à laisser l'utilisateur appuyer sur entrée pour passer
        public boolean check() {
            Scanner sc = new Scanner(System.in);
            String c = sc.nextLine();
            if (c == null) {
                sc.close();
                return false;
            }
            sc.close();
            return true;
        }
    
        // méthodes d'affichage
        // affiche le numéro de niveau
        public void displayLevelInfos() {
            System.out.println("Level " + this.nbLevel);
        }
    
        // annonce un nouvel ennemi
        public void ennemyShowing() {
            System.out.println("An ennemy just appeared : " + this.ennemy.toString());
        }
    
        public void ennemyFaster(Attack attack) {
            System.out.println("The ennemy attacks before you can !");
            player.setCurrentHealth(player.getCurrentHealth() - attack.getDamage() * this.ennemy.getAttackMultiplier()); //Récupère une attaque aléatoire dans l'enum
            System.out.println(attack.getName() + "!! You're getting " + (int) attack.getDamage() * this.ennemy.getAttackMultiplier() + " of damage!");
            System.out.println(this.player.getName() + "'s life' : " + this.displayPlayerHealth());
        }
    
        // affiche la jauge de vie de l'ennemi
        public String displayEnnemyHealth() {
            return this.ennemy.toString() + " - " + (int)this.ennemy.getCurrentHealth() +"/" + (int)this.ennemy.getMaxHealth();
        }
        
        // affiche la jauge de vie du joueur
        public String displayPlayerHealth() {
            return (int)this.player.getCurrentHealth() +"/" + (int)this.player.getMaxHealth();
        }
    
        // annonce la mort de l'ennemi
        public void ennemyDying() {
            System.out.println("The ennemy is dead!");
        }
    
        // annonce la mort du joueur
        public void playerDying() {
            System.out.println(this.player.getName() + " is dead!");   
        }
    
    // action quand le joueur n'est pas épuisé
        public void playerHasEnergy(Attack attack) {
            this.ennemy.damage(attack.getDamage() * player.getAttackMultiplier());
            player.exhaust(attack.getEnergyCost());
            System.out.println("You're using " + attack.getName() + "! You lose " + attack.getEnergyCost() + " energy points");
        }
    
        // affiche les règles du jeu
        public void displayGameRules() {
            System.out.println("To fight, type 'a' and press Enter.");
            System.out.println("To exit the game at any moment, type 'q' and press Enter.");
        }
    
        // plus petit rappel des commandes (reste statique sur l'écran pour le joueur)
        public void commandsReminder() {
            System.out.println("Commands : \n \t a - attack \n\t q - exit");
        }
    
        // méthodes de combats
        // liste des attaques et défenses possibles pour le joueur
        public void possibleActions() {
            System.out.println("Possible attacks are : \n \t punch, kick, double kick, supermanpunch. \"");
            System.out.println("Possible defenses are : \n \t lowblock, highblock\"");
        }
    
        // quand l'utilisateur choisit une action qui n'existe pas
        public void invalidActionChoice() {
            System.out.println("This action is not available.");
            possibleActions();
        }
    
        // méthodes de paramètrages
        // vérification de victoire du joueur
        public boolean playerWon() {
            return !this.player.isDead() && this.ennemy.isDead();
        }
    
        // augmenter le niveau
        public void levelGoingUp() {
            if (playerWon()) {
                System.out.println(">>> Levelling up! <<<");
                this.setNbLevel(nbLevel++);
                System.out.println("                            Congrats!       "+'\n');
                System.out.println("      you won your fight! + \n \t let's see what you can do with your next ennemy...   Good luck! \n\t your currrent enemy level is "+this.ennemy.level );
        
            System.out.println(" \n this time your enemy's health is "+ (int) this.ennemy.currentHealth+ "\n ... ");
            }
        }
    
        public void victory(){
            System.out.println("                            FINAL VICTORY       "+'\n');
            System.out.println("You won! ");
        }
    
        //Affichage ascii
    
        public  void fightScene() throws IOException{
            Image image=new Image("res/fight.ini", 12);
            image.imageGenerator();
        }
    
        public  void bigFightScene() throws IOException{
            Image image=new Image("res/mouvement.ini", 16);
            image.imageGenerator();
        }
    }