mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-07 18:49:34 +01:00
Laster listen av brett fra en fil og forbedrer visning av brettlisten
This commit is contained in:
parent
85c24fa136
commit
1dc09eb45e
@ -15,8 +15,10 @@ import inf112.fiasko.roborally.networking.containers.GameStartInfoResponse;
|
||||
import inf112.fiasko.roborally.objects.Player;
|
||||
import inf112.fiasko.roborally.ui.RoboRallyWrapper;
|
||||
import inf112.fiasko.roborally.ui.SimpleButton;
|
||||
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
||||
import inf112.fiasko.roborally.utility.IOUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -45,8 +47,11 @@ public class LobbyScreen extends InteractiveScreen {
|
||||
Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
|
||||
|
||||
selectBox = new SelectBox<>(skin);
|
||||
selectBox.setItems("Dizzy_Dash", "Checkmate", "Risky_Exchange", "Twister", "Bloodbath_Chess", "Vault_Assault",
|
||||
"Island_Hop", "Chop_Shop_Challenge", "Around_The_World", "Death_Trap", "Whirlwind_Tour");
|
||||
try {
|
||||
selectBox.setItems(BoardLoaderUtil.getBoardListHumanReadable());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
selectBox.setSize(200, 50);
|
||||
selectBox.setPosition((applicationWidth - selectBox.getWidth()) / 2f, applicationHeight / 2f - 120);
|
||||
|
||||
@ -77,7 +82,7 @@ public class LobbyScreen extends InteractiveScreen {
|
||||
roboRallyWrapper.server.getRobotID());
|
||||
for (Connection connection : playerNames.keySet()) {
|
||||
roboRallyWrapper.server.sendToClient(connection, new GameStartInfoResponse(
|
||||
selectBox.getSelected() + ".txt", playerList, playerNames.get(connection)));
|
||||
BoardLoaderUtil.getRealBoardName(selectBox.getSelected()), playerList, playerNames.get(connection)));
|
||||
}
|
||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
|
||||
}
|
||||
|
@ -27,6 +27,48 @@ public final class BoardLoaderUtil {
|
||||
private BoardLoaderUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the actual file name of a board given its human-readable name
|
||||
*
|
||||
* @param boardName The human-readable name of a board
|
||||
* @return The file name of the board
|
||||
*/
|
||||
public static String getRealBoardName(String boardName) {
|
||||
return boardName.replace(" ", "_") + ".txt";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all available boards with human-readable names
|
||||
*
|
||||
* @return A list of all available boards
|
||||
* @throws IOException If the board list cannot be read
|
||||
*/
|
||||
public static String[] getBoardListHumanReadable() throws IOException {
|
||||
String[] boards = getBoardList();
|
||||
for (int i = 0; i < boards.length; i++) {
|
||||
boards[i] = boards[i].replace("_", " ").replace(".txt", "");
|
||||
}
|
||||
return boards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all available boards
|
||||
*
|
||||
* @return A list of all available boards
|
||||
* @throws IOException If the board list cannot be read
|
||||
*/
|
||||
private static String[] getBoardList() throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
ResourceUtil.getResourceAsInputStream("boards.txt")));
|
||||
int numberOfBoards = Integer.parseInt(reader.readLine());
|
||||
String[] boardList = new String[numberOfBoards];
|
||||
for (int i = 0; i < numberOfBoards; i++) {
|
||||
String board = reader.readLine();
|
||||
boardList[i] = board;
|
||||
}
|
||||
return boardList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and rotates a board described in a file
|
||||
*
|
||||
|
13
src/main/resources/boards.txt
Normal file
13
src/main/resources/boards.txt
Normal file
@ -0,0 +1,13 @@
|
||||
12
|
||||
Around_The_World.txt
|
||||
Bloodbath_Chess.txt
|
||||
Checkmate.txt
|
||||
Chop_Shop_Challenge.txt
|
||||
Death_Trap.txt
|
||||
Dizzy_Dash.txt
|
||||
Island_Hop.txt
|
||||
Lost_Bearings.txt
|
||||
Risky_Exchange.txt
|
||||
Twister.txt
|
||||
Vault_Assault.txt
|
||||
Whirlwind_Tour.txt
|
Loading…
x
Reference in New Issue
Block a user