diff --git a/resources/Battle/Speech/mudry.txt b/resources/Battle/Speech/mudry.txt index 5202573..bdf5913 100644 --- a/resources/Battle/Speech/mudry.txt +++ b/resources/Battle/Speech/mudry.txt @@ -1,4 +1,4 @@ -Un mudry sauvage se balade dans les salles de classe. Il va te tester pour savoir si tu a traviallé cette année +Un mudry sauvage se balade dans les salles de classe. Il va te tester pour savoir si tu a travaillé cette année Une question pour commencer : Encore une autre : Est ce que tu est vraiment chaud pour diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index 512a609..f6c1755 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -70,7 +70,7 @@ public class ScreenBattle extends RenderingScreen{ //dialog if(b == null) return; if(b.getLine() == null) return; - g.drawString(15, 245 ,b.getLine() , optimus40); + g.drawString(15, 260 ,b.getLine() , optimus40); } diff --git a/src/Text/TextEnemy.java b/src/Text/TextEnemy.java index eb43dd2..18ab012 100644 --- a/src/Text/TextEnemy.java +++ b/src/Text/TextEnemy.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.Random; public class TextEnemy { + private static final int CUT = 60; public FightData fightData; public SpeechData speechData; @@ -82,28 +83,31 @@ public class TextEnemy { //introduction line - lines.add(new Line(speechData.getSpeechs(0), false)); + String introduction = formatLine(speechData.getSpeechs(0), CUT); + lines.add(new Line(introduction, 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); + //attack and answer (number on vector : 1-4) - 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)); + lines.add(new Line(attack + "\n" +answer1 + "\n" + answer2 + "\n" + answer3 + "\n" + answer4, true)); currentData.add(currentRandom); @@ -114,8 +118,11 @@ public class TextEnemy { } //finish (win and death) - lines.add(new Line(speechData.getSpeechs(5), false)); - lines.add(new Line(speechData.getSpeechs(6), false)); + 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)); } public Vector getCurrentData() { @@ -123,5 +130,67 @@ public class TextEnemy { } + public String formatLine(String line, int cut){ + + String cutLine = ""; + String newLine = ""; + + int startC = 0; + int stoppC = cut; + + + if(cut>line.length()-1){ + newLine =line; + } + else{ + + 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){ + break; + } + else if(c.length-1-stoppC <= cut){ + stoppC = c.length-1; + } + else{ + stoppC += cut; + } + } + } + + + return newLine; + } + + } diff --git a/src/testYann.java b/src/testYann.java index b63ea5e..70cf8a4 100644 --- a/src/testYann.java +++ b/src/testYann.java @@ -14,57 +14,69 @@ import java.util.RandomAccess; class testYann{ public static void main(String[] args) { + System.out.println(111); - String line = "Je vais te manger tout cru, dans le creux de ma main et tu verra rien du tout."; + String line = " Je vais te manger tout cru asdnkajsdh asl "; String cutLine = ""; String newLine = ""; - int cut = 25; + int cut = 12; int startC = 0; int stoppC = cut; + + if(cut>line.length()-1){ + newLine =line; + } + else{ + + 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){ + break; + } + else if(c.length-1-stoppC <= cut){ + stoppC = c.length-1; + } + else{ + stoppC += cut; + } + } + } - 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 += "\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; - } - } System.out.println(newLine);