Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #233

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/ch/uzh/ifi/hase/soprafs24/service/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ public void startGame(Room room) {
socketService.broadcastGameinfo(game.getRoomId(), "gameover");
socketService.broadcastPlayerInfo(game.getRoomId(), "gameover");
socketService.broadcastLobbyInfo();
try {
Thread.sleep(30000);//20000
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
System.out.println("End Revealing:"+ LocalDateTime.now());
// try {
// Thread.sleep(30000);//20000
// } catch (InterruptedException e) {
// Thread.currentThread().interrupt();
// throw new RuntimeException(e);
// }
// System.out.println("End Revealing:"+ LocalDateTime.now());
// Display the leaderboard for 2 minutes, and dismiss the room in advance if all
// players leave
if (gameRepository.findByRoomId(game.getRoomId()).isPresent()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public boolean checkRoomExists(String roomId) {
// Here we create a new room, and we need to set the room property and theme
// according to the input from client
public Room createRoom(Room newRoom) {
if (roomRepository.findAll().size() >= 10){
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Only 10 rooms are allowed to exist at the same time!");
}
Optional<Room> existingRoom = roomRepository.findByRoomId(newRoom.getRoomId());
if (existingRoom.isPresent()) {
throw new ResponseStatusException(HttpStatus.CONFLICT, "Room already exists");
Expand Down Expand Up @@ -163,7 +166,7 @@ public List<String> getWords(String theme) throws IOException {
" \"messages\": [\n" +
" {\n" +
" \"role\": \"user\",\n" +
" \"content\": \"Generate a JSON list of noun words with the theme '" + theme
" \"content\": \"Generate a JSON list of noun words within the theme '" + theme
+ "' and ensure each word has no more than four syllables and all in lowercase in the following format: {\\\"words\\\": [\\\"word1\\\", \\\"word2\\\", \\\"word3\\\", ...]}\"\n"
+
" }\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ void createRoom_EmptyTheme_ThrowsException() {
assertThrows(ResponseStatusException.class, () -> roomService.createRoom(newRoom));
}

@Test
void createRoom_tooManyRoom(){
Room room = new Room();
List<Room> roomList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
roomList.add(room);
}
when(roomRepository.findAll()).thenReturn(roomList);
assertThrows(ResponseStatusException.class, () -> roomService.createRoom(room));
}

@Test
void enterRoom_RoomIsFull_ThrowsException() {
Room room = new Room();
Expand Down
Loading