最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
J2ME游戏中读入文本并存储在String数组中
时间:2022-07-02 17:48:43 编辑:袖梨 来源:一聚教程网
一个在J2SE中十分钟即告完成的代码,在J2ME中花费了一个下午.是什么样的代码呢?
[要求]在游戏中读入文本形式存储的hints
[分析]
J2ME没有BufferReader,用InputStreamReader吧
既然没有BufferReader,也就不要奢望有readLine()了,自己慢慢循环吧
[源代码]
[code]
/* read hint-------------------------------------- */
/**
* This is the hints
* */
String[][] hintStr;
/**
* this specify the hint's show width
*/
final int hint_;
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; x++)
hint_num_temp[x] = "";
while (true) {
if (i < hintsdat.length) {
if (hintsdat[i] != ' ') {
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]);
[要求]在游戏中读入文本形式存储的hints
[分析]
J2ME没有BufferReader,用InputStreamReader吧
既然没有BufferReader,也就不要奢望有readLine()了,自己慢慢循环吧
[源代码]
[code]
/* read hint-------------------------------------- */
/**
* This is the hints
* */
String[][] hintStr;
/**
* this specify the hint's show width
*/
final int hint_;
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; x++)
hint_num_temp[x] = "";
while (true) {
if (i < hintsdat.length) {
if (hintsdat[i] != ' ') {
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]);
相关文章
- myfreemp3音乐网站最新网址链接-myfreemp3在线音乐免费地址入口分享 11-04
- myfreemp3音乐网站网址链接-myfreemp3在线音乐网站地址入口 11-04
- 非主流时尚爱情图片 11-03
- 拼多多商家登录-拼多多商家网页版登录入口 11-03
- DeepSeek-网页版官方入口 11-03
- qq邮箱网页版登录入口-qq邮箱官网直接访问地址 11-03