私はコードを実行することができましたが、最高得点のコードに問題があります。私は理解していない何らかの理由で、彼らが動作していないので、bufferedreaderとprintwriter関数を使用することができません。プログラムでスコアを最高スコアと比較し、スコアが最高スコアよりも大きい場合、最高スコアはtxtファイルで更新されます。 txtファイルが必要な理由は、いったんプログラムが終了すると、以前の最高得点をチェックする方法が必要になるからです。私は本当にプログラムを使って処理と書き込みと読み取りtxtファイルを使用することに新しいですし、他のサイトやフォーラムではハイスコア変数をtxtファイルに書き込まないために助けになったことはありません。私のコンピュータを壊す準備をしてください。 EM1.score =プログラムの過程で蓄積されたスコア。私の処理の難しさPrintWriterとBufferedReaderの動作
class High_Score {
int highscore = 0;
PrintWriter output; //imports the writer
BufferedReader reader; //imports the reader
int state = 0; //sets the varoable for the keyboard
void scoring() {
int score = EM1.score;
if (score > highscore) {
highscore = score;
}
textSize(30);
text("Your score is "+ score, 150, height/4);
text("The current highscore is "+highscore+".", 75, height/2);
text("Try to beat it.", 200, 450);
textSize(12);
text("Press esc to exit this page.", 225, 550);
}
void reader() {
importHS();
updateHS();
}
void updateHS() {
int score = EM1.score;
output = createWriter("highscore.txt"); //creates the file that will be
if (highscore < score) {
highscore = score;
output.print(highscore);
output.close();
}
}
void importHS() {
reader = createReader("highscore.txt"); //reads the current highscore
if (reader == null) {
highscore = 0;
return;
}
String line;
try {
line = reader.readLine();
}
catch (IOException e) {
e.printStackTrace();
line = null;
}
if (line != null) {
highscore = int(line);
println(highscore);
}
try {
reader.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
void type() { //allows the screen to close is esc is pressed on the keyboard
state = key;
if (key == ESC) {
exit();
}
}
}