J2ME the text in the game and store it in a string array

Source: Internet
Author: User
Tags array continue return string
An array of code that is completed 10 minutes in the J2SE takes an afternoon in j2me. What kind of code is it?
[Requirements] read in the game hints stored in text form

Analysis
J2ME no bufferreader, use InputStreamReader.
Since there is no bufferreader, also do not expect to have ReadLine (), the cycle of their own slowly

[Source code]
The following is the program 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 + +)
HINT_NUM_TEMP[X] = "";
while (true) {

if (I < hintsdat.length) {
if (hintsdat[i]!= ' \ n ') {
HINT_NUM_TEMP[J] + = Hintsdat[i];
i++;
Continue
else if (J < Hint_num) {
System.out.println (i);
i++;
j + +;
}
Continue
}

Break
}

SYSTEM.OUT.PRINTLN ("Creating ...");

j = 0;
for (i = 0; i < Hint_num; i++) {
String str = new string (Hint_num_temp[i]);
int str_num = Str.length ()/hint_width + 1;
HINTSTR = new String[num][str_num];
for (int z = 0; z < str_num; z++) {
if (Z < str_num-1) {
Hintstr[j][z] = "";
Hintstr[j][z] + = Str.substring (Z * hint_width, (z + 1)
* hint_width);
} else {
Hintstr[j][z] = "";
Hintstr[j][z] + = str.substring ((z-1) * hint_width);
}
System.out.println ("hintstr[" + j + "] [" + z + "]:"
+ hintstr[j][z]);
}
j + +;
}

catch (IOException e) {
System.out.println ("Error");
}
return true;
}

Summary
Program requirements are very simple, there must be a better way to achieve, the results of a large number of information to see nothing.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.