From f15d40d62aa9a17cb80b09fa81a001d34caef501 Mon Sep 17 00:00:00 2001 From: Fastium <79766552+Fastium@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:57:05 +0200 Subject: [PATCH] modif text enemy --- src/Text/TextEnemy.java | 104 +++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 59 deletions(-) diff --git a/src/Text/TextEnemy.java b/src/Text/TextEnemy.java index 56cf6c9..edb2ce9 100644 --- a/src/Text/TextEnemy.java +++ b/src/Text/TextEnemy.java @@ -3,13 +3,12 @@ package Text; import java.util.Vector; import Entity.Enemy; -import Entity.Character.Direction; import java.util.Arrays; import java.util.Random; public class TextEnemy { - private static final int CUT = 60; + private static final int CUT = 40; public FightData fightData; public SpeechData speechData; @@ -22,7 +21,7 @@ public class TextEnemy { public static void main(String[] args) { - TextEnemy t = new TextEnemy(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert", 25, "informatique",Direction.NULL)); + TextEnemy t = new TextEnemy(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert", 25, "informatique")); t.generateText(); @@ -84,31 +83,30 @@ public class TextEnemy { //introduction line - String introduction = formatLine(speechData.getSpeechs(0), CUT); - lines.add(new Line(introduction, false)); - + lines.add(new Line(speechData.getSpeechs(0), false)); orderAttack = randomGenerate(0, fightData.nbre_line-1, 4); - for(int j=0; j<4;j++){ int[] currentRandom = new int[5]; currentRandom[0] = orderAttack[j]; //generate the order of the answer orderAnswer = randomGenerate(0, 3, 4); + System.out.println("\n attaque " + j + " : " + Arrays.toString(orderAnswer) + "\n"); //save the order of answer and attack for(int k=1;k<5;k++){ currentRandom[k] = orderAnswer[k-1]; } - String attack = formatLine( speechData.getSpeechs(i++) + fightData.getAttack(orderAttack[j]).attack + " ? ("+fightData.getAttack(orderAttack[j]).getXp()+ ") ", CUT); - String answer1 = formatLine("1. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[0]), CUT); - String answer2 = formatLine("2. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[1]), CUT); - String answer3 = formatLine("3. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[2]), CUT); - String answer4 = formatLine("4. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[3]), CUT); + String attack = formatLine( speechData.getSpeechs(i++) + fightData.getAttack(orderAttack[j]).attack + " ? ("+fightData.getAttack(orderAttack[j]).getXp()+ ") ", cut) //attack and answer (number on vector : 1-4) - lines.add(new Line(attack + "\n" +answer1 + "\n" + answer2 + "\n" + answer3 + "\n" + answer4, true)); + lines.add(new Line( + speechData.getSpeechs(i++) + fightData.getAttack(orderAttack[j]).attack + " ? ("+fightData.getAttack(orderAttack[j]).getXp()+ ") " + "\n" + + "1. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[0]) + "\n" + + "2. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[1]) + "\n" + + "3. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[2]) + "\n" + + "4. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[3]), true)); currentData.add(currentRandom); @@ -119,11 +117,8 @@ public class TextEnemy { } //finish (win and death) - String alive = formatLine(speechData.getSpeechs(5), CUT); - String death = formatLine(speechData.getSpeechs(6), CUT); - - lines.add(new Line(alive, false)); - lines.add(new Line(death, false)); + lines.add(new Line(speechData.getSpeechs(5), false)); + lines.add(new Line(speechData.getSpeechs(6), false)); } public Vector getCurrentData() { @@ -140,55 +135,46 @@ public class TextEnemy { int stoppC = cut; - if(cut>line.length()-1){ - newLine =line; + char[] c = new char[line.length()]; + + for(int i=0; i=startC; i--){ - if(c[i] == ' '){ - stoppC = i; - break; - } - else if(stoppC == c.length-1){ - break; - } - } - - //découper le mot - for(int i=startC;i<=stoppC;i++){ - cutLine += c[i]; - } - - newLine += cutLine + "\n"; - cutLine = ""; - - startC = stoppC + 1; - - - if(c.length-1-stoppC <=0){ + for(int i =stoppC; i>=startC; i--){ + if(c[i] == ' '){ + stoppC = i; break; } - else if(c.length-1-stoppC <= cut){ - stoppC = c.length-1; - } - else{ - stoppC += cut; + else if(stoppC == c.length-1){ + break; } } + + //découper le mot + for(int i=startC;i<=stoppC;i++){ + cutLine += c[i]; + } + + newLine += "\n" + cutLine; + cutLine = ""; + + startC = stoppC + 1; + + + if(c.length-1-stoppC <=0){ + break; + } + else if(c.length-1-stoppC <= 10){ + stoppC = c.length-1; + } + else{ + stoppC += cut; + } } - - return newLine; }