This commit is contained in:
Woosle Park
2019-03-25 22:39:21 -04:00
parent c50cc8c364
commit 5b019b3e63
11 changed files with 248 additions and 1 deletions

View File

@@ -43,6 +43,14 @@ public abstract class GameObject implements JSONSerializable, MongoSerializable
* Current World of the object
*/
private World world;
/**
* Counter for user stats
*/
private int counter;
/**
* Execution Time
*/
private double time;
public GameObject() {
@@ -63,6 +71,9 @@ public abstract class GameObject implements JSONSerializable, MongoSerializable
int newX = getX() + direction.dX;
int newY = getY() + direction.dY;
counter = 0;
time = 0;
if (newX < 0 || newY < 0 || newX >= world.getWorldSize() || newY >= world.getWorldSize()) {
//Next tile is out of world bounds, move to next world
World nextWorld = GameServer.INSTANCE.getGameUniverse().getWorld(
@@ -230,6 +241,22 @@ public abstract class GameObject implements JSONSerializable, MongoSerializable
this.world = world;
}
public void setCounter(int c){
counter=c;
}
public int getCounter(){
return counter;
}
public void setTime(double t){
time=t;
}
public double getTime(){
return time;
}
@Override
public JSONObject jsonSerialise() {
JSONObject json = new JSONObject();

View File

@@ -61,6 +61,27 @@ public class UserStats implements MongoSerializable {
return stats.getInteger(name, 0);
}
/**
* Set the value of a stat
*
* @param name Name of the stat
* @param value new value
*/
public void setDouble(String name, double value) {
stats.put(name, value);
}
/**
* Get the value of at stat
*
* @param name Name of the value
* @return The value of the stat. Returns 0 if not found
*/
public double getDouble(String name) {
return stats.getDouble(name);
}
/**
* Add an string item to a set
*

View File

@@ -13,9 +13,12 @@ public class LeaderBoardPage implements TemplateViewRoute {
@Override
public ModelAndView handle(Request request, Response response) {
Map<String, Object> model = new HashMap<>(2);
Map<String, Object> model = new HashMap<>(5);
model.put("session", request.session());
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("completedVaults", 25));
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("deathCount", 25));
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("totalExecutionTime", 25));
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("walkDistance", 25));
return new ModelAndView(model, "leaderboard.vm");
}
}

View File

@@ -16,6 +16,9 @@
<tr>
<th>Player</th>
<th>Completed vaults</th>
<th>Death counts</th>
<th>Total execution time (ms)</th>
<th>Walk distance</th>
</tr>
</thead>
<tbody>
@@ -23,6 +26,9 @@
<tr>
<td>$row.getKey().getUsername()</td>
<td>$row.getValue().size()</td>
<td>$row.getValue().size()</td>
<td>$row.getValue().size()</td>
<td>$row.getValue().size()</td>
</tr>
#end
</tbody>