A code that is completed in J2SE in ten minutes. What kind of code does it take for an afternoon in J2SE?
[Required] Reading hints stored in text format in the game
[Analysis]
J2's no BufferReader. Use InputStreamReader.
Since there is no BufferReader, do not expect readLine (). Please loop through it slowly.
[Source code]
[Code]
/* Read hint --------------------------------------*/
/**
* This is the hints
**/
String [] [] hintStr;
/**
* This specify the hint's show width
*/
Final int hint_width = 8;
Int hint_num;
Public boolean readHint (int stage ){
If (stage> 0 & stage <4 ){
If (stage = 2 ){
Hint_num = 4;
} Else {
Hint_num = 3;
}
} Else {
System. out. println ("No this stage ");
Return false;
}
Try {
String filename = "hint" + Integer. toString (stage );
InputStreamReader in = new InputStreamReader (getClass ()
. GetResourceAsStream (filename ));
Int num =-1;
Do {
++ Num;
} While (in. read ()! =-1 );
In. reset ();
Char [] hintsdat = new char [num];
System. out. println (num );
In. read (hintsdat );
In. close ();
String hint_temp = new String (hintsdat );
Int j = 0;
Int I = 0;
String hint_num_temp [] = new String [hint_num];
For (int x = 0; x Hint_num_temp [x] = "";
While (true ){
If (I If (hintsdat [I]! = ''){
Hint_num_temp [j] + = hintsdat [I];
I ++;
Continue;
} Else if (j System. out. println (I );
I ++;
J ++;
}
Continue;
}
Break;
}
// System. out. println ("Creating ....");
J = 0;
For (I = 0; I String str = new String (hint_num_temp [I]);