-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoringSystem.java
83 lines (69 loc) · 2.17 KB
/
ScoringSystem.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
import java.io.*;
public class ScoringSystem {
final private String fileName = "history.log";
private String winnerName = "";
private int winnerScore = 10000;
private String playerName = "";
private int playerScore = 0;
private double rate = 1;
private void newLogFile(){
try {
FileWriter f = new FileWriter(this.fileName);
BufferedWriter buf = new BufferedWriter(f);
buf.write(this.winnerName + "\n" + this.winnerScore);
buf.close();
} catch (Exception ex) {
this.winnerName = this.playerName;
this.winnerScore = this.playerScore;
}
}
private void readLogFile(){
try {
FileReader f = new FileReader(this.fileName);
BufferedReader buf = new BufferedReader(f);
this.winnerName = buf.readLine();
this.winnerScore = Integer.valueOf(buf.readLine());
buf.close();
//System.out.println("Found: " + this.winnerName + ": " + this.winnerScore);
} catch (Exception ex) {
//System.out.println("None found");
this.winnerName = this.playerName;
this.winnerScore = this.playerScore;
this.newLogFile();
}
}
public ScoringSystem(String playerName) {
this.playerName = playerName;
this.playerScore = 0;
readLogFile();
}
public String getPlayerName(){
return this.playerName;
}
public int getPlayerScore(){
return this.playerScore;
}
public String getWinnerName(){
return this.winnerName;
}
public int getWinnerScore(){
return this.winnerScore;
}
public void rateBonus(double r){
this.rate += r;
}
public void ratePenalty(double m){
this.rate *= m;
}
public void updatePlayerScore(int score){
this.playerScore += this.rate * score;
this.rate = 0;
if(this.playerScore >= this.winnerScore){
this.winnerScore = this.playerScore;
this.winnerName = this.playerName;
}
}
public void updateLogFile(){
newLogFile();
}
}