-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameLog.java
121 lines (100 loc) · 2.94 KB
/
GameLog.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.util.ArrayList;
import java.util.Date;
public class GameLog {
public class Entry implements Comparable<Entry> {
//TODO:Halbzeiten
Integer logTime;
Game.Colors logTeam;
Integer logPlayer;
Game.GameAction logAction;
String logComment;
int exchangeIn;
int exchangeOut;
/*
* For any incident except exchanges
*/
public Entry(Integer logTime, Game.Colors logTeam, Integer logPlayer,
Game.GameAction logAction, String logComment) {
this.logTime = logTime;
this.logTeam = logTeam;
this.logPlayer = logPlayer;
this.logAction = logAction;
this.logComment = logComment;
}
/*
* For exchanges
*/
public Entry(Integer logTime, Game.Colors logTeam, int exchangeIn,
int exchangeOut) {
this.logTime = logTime;
this.logTeam = logTeam;
this.exchangeIn = exchangeIn;
this.exchangeOut = exchangeOut;
}
/*
* For when the incident cannot yet be determined
*/
public Entry(Integer logTime) {
this.logTime = logTime;
this.logTeam = Game.Colors.UNDEFINED;
this.logAction = Game.GameAction.UNDEFINED;
}
@Override
public int compareTo(Entry o) {
return logTime.compareTo(o.logTime);
}
public String toString() {
if (logAction != Game.GameAction.EXCHANGE) {
return logTime + ": " + logAction + " fuer/von Spieler Nummer "
+ logPlayer + " vom Team " + logTeam + "; "
+ logComment;
} else {
return logTime + ": Wechsel bei Team " + logTeam + ": Spieler "
+ exchangeIn + " wechselt ein fuer Spieler "
+ exchangeOut;
}
}
}
ArrayList<Entry> logList = new ArrayList<Entry>();
private int insertNewLogEntry(Entry newEntry) {
// TODO: Eventuell sortierung hier?
logList.add(newEntry);
System.err.println(new Date()+" new log entry created");
return logList.size();
}
public int createNewLogEntry(int gameTime) {
return insertNewLogEntry(new Entry(gameTime));
}
public int createNewLogEntry(int gameTime, Game.Colors team, int player,
Game.GameAction incident, String comment) {
return insertNewLogEntry(new Entry(gameTime, team, player, incident,
comment));
}
public void logNewestIncident(Game.Colors team, int player,
Game.GameAction incident, String comment) {
logIncident(logList.size() - 1, team, player, incident, comment);
}
public void logIncident(int logNumber, Game.Colors team, int player,
Game.GameAction incident, String comment) {
Entry e = logList.get(logNumber);
e.logTeam = team;
e.logPlayer = player;
e.logAction = incident;
e.logComment = comment;
}
public int createNewExchange(int gameTime, Game.Colors team, int playerIn,
int playerOut, String comment) {
return insertNewLogEntry(new Entry(gameTime, team, playerIn, playerOut));
}
public void deleteNewestIncident(){
logList.remove(logList.size()-1);
}
public void deleteIncident(int logNumber){
logList.remove(logNumber);
}
public void printToConsole(){
for(Entry e: logList){
System.out.println(e.toString());
}
}
}