Skip to content
Snippets Groups Projects
Commit 7595166d authored by Haakon Gunleiksrud's avatar Haakon Gunleiksrud
Browse files

#55 Sorted the list of high scores and added name to the table. Minor...

#55 Sorted the list of high scores and added name to the table. Minor adjustments to stage for better visibility.
parent 82c6e106
Branches
No related tags found
1 merge request!52Resolve "Playername and sort for viewhs4game"
......@@ -26,7 +26,7 @@ import java.util.NoSuchElementException;
public class QueryIntermediate {
private static String baseUrl = "http://localhost:3002/api/";
private static String baseUrl = "http://192.168.0.195:3002/api/";
private static Json json = new Json();
private static JsonReader jsonReader = new JsonReader();
......
......@@ -2,6 +2,8 @@ package com.gameware.game.models;
import com.badlogic.gdx.utils.Json;
import java.util.Comparator;
public class Highscore {
private String _id;
private String gameId;
......@@ -57,4 +59,9 @@ public class Highscore {
return report();
}
public static Comparator<Highscore> hsValueComparator = new Comparator<Highscore>() {
public int compare(Highscore hs1, Highscore hs2) {
return (int) (hs2.getValue() - hs1.getValue());
}};
}
......@@ -65,7 +65,7 @@ public abstract class PlayStateTemplate extends State {
if(round==null) {
QueryIntermediate.postHighscore(GameWare.getInstance().getPlayer().getId(), gameId, this.score);
} else{
QueryIntermediate.putRoundScore(round.get_id(), this.score);
QueryIntermediate.putRoundScore(tournament.get_id(),round.get_id(), this.score);
}
}
}
......
......@@ -15,8 +15,11 @@ import com.gameware.game.models.Highscore;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.gameware.game.models.Highscore.hsValueComparator;
public class ViewHighScoreForGameState extends State {
private Table outerTable;
private Table innerTable;
......@@ -33,17 +36,9 @@ public class ViewHighScoreForGameState extends State {
super(gsm);
this.game = game;
playerId = "5e5f61751113b81a1821b0e1"; //Temporary
/*
try{
playerId = GameWare.getInstance().getPlayer().getId();
}
catch(IOException e){
e.printStackTrace();
}
*/
highscores = getHighscores(game.getId());
Collections.sort(highscores,hsValueComparator);
makeStage();
}
......@@ -132,18 +127,21 @@ public class ViewHighScoreForGameState extends State {
for (int i = 0; i < length; i++){
Highscore hs = highscores.get(i);
Label placementLabel = new Label(String.valueOf(i+1)+". place: ",skin);
Label nameLabel = new Label(hs.getName()+" ",skin);
Label scoreLabel = new Label(String.valueOf(hs.getValue()),skin);
innerTable.add(placementLabel);
innerTable.add(nameLabel);
innerTable.add(scoreLabel);
innerTable.row();
}
Label playerLabel = new Label(playerLabelText,skin);
Label playerScoreLabel = new Label(String.valueOf(playerHS),skin);
innerTable.add(playerLabel);
innerTable.add(playerScoreLabel);
innerTable.add(playerLabel).spaceTop(spacingOnBottom);
innerTable.add(playerScoreLabel).spaceTop(spacingOnBottom);
innerTable.row();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment