Skip to content
Snippets Groups Projects
Select Git revision
  • babdabe6d7e96ed0b301c73ac5994dfaa80790bc
  • main default protected
  • v5.2
  • v5.1
  • v7.1
  • v7
  • v6.2
  • v6.1
  • v6
  • v5.9
  • v5.8
  • v5.7
  • v5.6
  • v5.5
  • v5
  • v5.3
  • v4.6
  • v4.6-problem
  • v4.5
  • v4
  • v3.2
  • v3.1
22 results

README.md

Blame
  • Main.java 5.18 KiB
    package bitFight;
    
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.time.LocalDateTime;
    import java.util.ArrayList;
    import java.util.Random;
    
    class Main {
    
        public static void main(String[] args) throws IOException, InterruptedException{
    
            Display.clearScreen();
    
            Menu menu= new Menu("name");
            menu.display();
            menu.validate();
    
            Display.clearScreen();
            menu.displayGameRules();
            menu.validate();
    
            Display.clearScreen();
            Display.setCursorPos(50,0);
            Display.printDialogBox();
    
            Display.goToDialogBox();
    
            Display.newPrintln(Terminal.RED_BACKGROUND + "ATTAQUEZ" + Terminal.RESET + " ou " + Terminal.PURPLE_BACKGROUND + "QUITTEZ" + Terminal.RESET);
    
            Display.goToUserInput();
    
            // Récupère le nom de cahque attaque dans une ArrayList
            ArrayList<String> actionNames = new ArrayList<>();
            for (Attack a : Attack.values()) actionNames.add(a.getName());
            for (Defense d : Defense.values()) actionNames.add(d.getName());
    
            BufferedReader in= new BufferedReader( new InputStreamReader(System.in));
    
            Random rand = new Random();
    
            Input input = new Input();
            input.newInput();
            Display.goToDialogBox();
    
            Enemy enemy = new Enemy("BAD PAUL", 2); 
    
            Player player = new Player("play");        
    
            
    
            while (!input.getInput().equals("q") && !enemy.isDead() && !player.isDead()) {
    
                //A garder au début de la boucle, mesure le temps que le joueur à pris d'écrire
                LocalDateTime timeBeforeAttack = LocalDateTime.now();
                int attackTime = 5 - (int)(5 * rand.nextDouble());
    
                // Affiche un message lors d'un input non répertorié
                if(!input.validInput()){
                    Display.newPrintln("Error input invalid");
                    input.newInput();;
                }
                
                if (input.getInput().equals("a")) {
    
                    Display.newPrintln("les attaques disponible sont : \n \t - punch \n \t - kick \n \t - doublekick \n \t - supermanpunch");
                    input.newInput();
                    
                    // Boucle tant que le joueur n'a pas taper de nom d'une attaque valide
                    while (!actionNames.contains(input.getInput()) || Attack.attackInTime(timeBeforeAttack, attackTime)) {
    
                        //Si le joueur est trop lent, l'ennemi fait une attaque aléatoire
                        if(Attack.attackInTime(timeBeforeAttack, attackTime)){
                            Display.clearDialogBox();
                            System.out.println("L'ennemi attaque avant que vous en ayez le temps!");
    
                            Attack randomEnemyAttack = Attack.values()[(int) rand.nextDouble()*Attack.values().length];
                            player.setCurrentHealth(player.getCurrentHealth() - randomEnemyAttack.getDamage() * enemy.getAttackMultiplier()); //Récupère une attaque aléatoire dans l'enum
    
                            System.out.println(randomEnemyAttack.getName() + "!! Le joueur prend " + randomEnemyAttack.getDamage() * enemy.getAttackMultiplier() + " de dégat!");
                            timeBeforeAttack = LocalDateTime.now();
                            input.newInput();;
                            
                        } 
    
                        if (!actionNames.contains(input.getInput())){
                            Display.clearDialogBox();
                            Display.newPrintln("Cette actions n'est pas disponible :(\nLes actions disponible sont: \n\tAttaque: punch, kick, doublekick, supermanpunch.\n\tDéfense: lowblock, highblock");
                            
                            input.newInput();;
                        }
                    }
                    
                    
                    if(!player.isExhausted()){
                        Attack attack = Attack.valueOf(actionNames.get(actionNames.indexOf(input.getInput())).toUpperCase());
                        enemy.damage(attack.getDamage() * player.getAttackMultiplier());
                        player.exhaust(attack.getEnergyCost());
                        Display.newPrintln("Vous utilisez " + attack.getName() + "! Vous perdez " + attack.getEnergyCost() + " points d'énergie");
                    } else {} //TODO ajouter display trop fatigué
                    
    
                    //Display.clearDialogBox();
    
                    Display.newPrintln(enemy.toString());
    
                    //Display.clearDialogBox();
    
                    input.newInput();;
                    if (enemy.isDead()){
                        player.revive();
                        enemy.revive();
                        enemy.levelUp();
                        Display.clearDialogBox();
                            System.out.println('\n');
                            System.out.println("                            Congrats!       "+'\n');
                            System.out.println("      you won your first fight! + \n \t let's see what you can do with your second ennemy...   Good luck! \n\t your currrent enemy level is "+enemy.level );
                    
                        System.out.println(" \n this time your enemy health is "+ (int) enemy.currentHealth+ "\n ... ");
                     
                    }
    
                }
            }
            
            in.close();
        }
    }