EnZiMa
19-06-2008, 01:17
Sto sviluppando il gioco "ruota della fortuna", ho problemi nell'inserimento della frase misteriosa nel tabellone.
Il mio tabellone è un array bidimensionale di char, con dimensioni 4x12. Sono riuscito tramite l'interfaccia CharacterIterator ad iterare la frase ed inserirla nell'array, ma sorge il problema dello spezzamento delle parole...come posso risolverlo? vorrei anche posizionare le parole della frase al centro del tabellone se la frase lo permette.
private void inserisciFrase() {
if (fraseMisteriosa.length() <= LIMITE) {
CharacterIterator it = new StringCharacterIterator(" "+fraseMisteriosa.getTesto());
for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) {
for (int r = 0; r < tabellone.length; r++) {
for (int c = 0; c < tabellone[r].length; c++) {
if(it.current()!= CharacterIterator.DONE){
tabellone[r][c]=it.next();
}
}
}
}
}
else {
System.out
.println("Errore : non sono ammesse frasi che hanno più di 48 catteri");
}
}
la frase misteriosa è
Questo è solo un esempio
l'output prodotto
|Q| |u| |e| |s| |t| |o| | | |è| | | |s| |o| |l|
|o| | | |u| |n| | | |e| |s| |e| |m| |p| |i| |o|
|\uffff| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.|
|.| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.|
inoltre CharacterIterator mi aggiunge un carattere strano nell'array.
Grazie! :)
Il mio tabellone è un array bidimensionale di char, con dimensioni 4x12. Sono riuscito tramite l'interfaccia CharacterIterator ad iterare la frase ed inserirla nell'array, ma sorge il problema dello spezzamento delle parole...come posso risolverlo? vorrei anche posizionare le parole della frase al centro del tabellone se la frase lo permette.
private void inserisciFrase() {
if (fraseMisteriosa.length() <= LIMITE) {
CharacterIterator it = new StringCharacterIterator(" "+fraseMisteriosa.getTesto());
for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) {
for (int r = 0; r < tabellone.length; r++) {
for (int c = 0; c < tabellone[r].length; c++) {
if(it.current()!= CharacterIterator.DONE){
tabellone[r][c]=it.next();
}
}
}
}
}
else {
System.out
.println("Errore : non sono ammesse frasi che hanno più di 48 catteri");
}
}
la frase misteriosa è
Questo è solo un esempio
l'output prodotto
|Q| |u| |e| |s| |t| |o| | | |è| | | |s| |o| |l|
|o| | | |u| |n| | | |e| |s| |e| |m| |p| |i| |o|
|\uffff| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.|
|.| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.| |.|
inoltre CharacterIterator mi aggiunge un carattere strano nell'array.
Grazie! :)