-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadFile.java
executable file
·98 lines (80 loc) · 2.89 KB
/
ReadFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.io.*;
import java.awt.Font;
public class ReadFile
{
public static void score(char c,double rx,boolean scorek,int track)
{
try
{
FileReader file=new FileReader("highscore.txt");
BufferedReader buffer=new BufferedReader(file);
String textline = buffer.readLine();
while((c != 'a')){
StdDraw.show(50);
StdDraw.setPenColor(StdDraw.GRAY);
StdDraw.filledSquare(0, 0, 15.0);
StdDraw.setPenColor(StdDraw.YELLOW);
Font f = new Font(Font.SERIF,Font.BOLD, 60);
StdDraw.setFont(f);
StdDraw.text((rx + 5) ,8 , "Highscore: " + textline);
StdDraw.text((rx + 5) ,3 , "Your score: " + track);
scorek = StdDraw.hasNextKeyTyped();
if(track < 10){
StdDraw.text((rx + 5) ,-2 , "No medal received: ");
Font g = new Font(Font.SERIF,Font.BOLD, 50);
StdDraw.setFont(g);
StdDraw.text((rx + 5) ,-8 , "Press a to continue: ");
}
if(track >= 10 && track <20){
StdDraw.text((rx + 5) ,-2 , "Medal received: ");
StdDraw.picture((rx + 5), -5, "bronze.png");
Font g = new Font(Font.SERIF,Font.BOLD, 50);
StdDraw.setFont(g);
StdDraw.text((rx + 5) ,-8 , "Press a to continue: ");
}
if(track >= 20 && track <30){
StdDraw.text((rx + 5) ,-2 , "Medal received: ");
StdDraw.picture((rx + 5), -5, "silver.png");
Font g = new Font(Font.SERIF,Font.BOLD, 50);
StdDraw.setFont(g);
StdDraw.text((rx + 5) ,-8 , "Press a to continue: ");
}
if(track >= 30 && track < 40){
StdDraw.text((rx + 5) ,-2 , "Medal received: ");
StdDraw.picture((rx + 5), -5, "gold.png");
Font g = new Font(Font.SERIF,Font.BOLD, 50);
StdDraw.setFont(g);
StdDraw.text((rx + 5) ,-8 , "Press a to continue: ");
}
if(track >= 40){
StdDraw.text((rx + 5) ,-2 , "Medal received: ");
StdDraw.picture((rx + 5), -5, "gold.png");
Font g = new Font(Font.SERIF,Font.BOLD, 50);
StdDraw.setFont(g);
StdDraw.text((rx + 5) ,-8 , "Press a to continue: ");
}
if(scorek == true){
c = StdDraw.nextKeyTyped();
}
}
buffer.close();
}
catch( IOException e ){}
}
public static int check()
{
int i = 0;
try
{
FileReader file=new FileReader("highscore.txt");
BufferedReader buffer=new BufferedReader(file);
String textline = null;
while((textline = buffer.readLine()) != null){
i = Integer.parseInt(textline);
buffer.close();
}
}
catch( IOException e ){}
return i;
}
}