Skip to content

Commit

Permalink
cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
uo288061 committed Apr 25, 2024
1 parent c85ee32 commit af999eb
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 74 deletions.
59 changes: 3 additions & 56 deletions src/main/java/com/uniovi/controllers/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public String getGame(HttpSession session, Model model, Principal principal) {
return "game/basicGame";
}




@GetMapping("/multiplayerGame")
public String getMultiplayerGame() {
return "game/multiplayerGame";
Expand Down Expand Up @@ -121,50 +118,10 @@ public String startMultiplayerGame(HttpSession session, Model model, Principal p
return "game/basicGame";
}

// @GetMapping("/games/multiFinished")
// public String createFinishedLobby( HttpSession session, Model model) {
// int code = Integer.parseInt((String)session.getAttribute("multiplayerCode"));
// List<Player> players=playerService.getUsersByMultiplayerCode(code);
// model.addAttribute("players",players);
// model.addAttribute("code",session.getAttribute("multiplayerCode"));
// session.removeAttribute("gameSession");
// return "/game/multiFinished";
// }


// @GetMapping("/multiplayerGame/finishedGame")
// public String goToFinishedLobby(HttpSession session,Principal principal) {
// Optional<Player> player = playerService.getUserByUsername(principal.getName());
// Player p = player.orElse(null);
// GameSession gameSession = (GameSession) session.getAttribute("gameSession");
// playerService.setScoreMultiplayerCode(p.getId(),""+gameSession.getScore());
// return "redirect:/game/multiFinished";
// }
//


// @GetMapping("/game/multiFinished/{code}")
// @ResponseBody
// public Map<String,String> updateFinishedGame(@PathVariable String code) {
// List<Player> players = playerService.getUsersByMultiplayerCode(Integer.parseInt(code));
// Map<String, String> playerInfo = new HashMap<>();
// for (Player player : players) {
// String playerName = player.getUsername();
// String playerScore = player.getScoreMultiplayerCode();
// if(playerScore==null){
// playerScore="N/A";
// }
// playerInfo.put(playerName, playerScore);
// }
// return playerInfo;
// }

@GetMapping("/multiplayerGame/endGame/{code}")
public String endMultiplayerGame(Model model,@PathVariable String code) {
// List<Object[]> playersWithScores =multiplayerSessionService.getPlayersWithScores(Integer.parseInt(code));
// model.addAttribute("MultiplayerRanking", playersWithScores);
model.addAttribute("code",code);
return "ranking/multiplayerRanking";
model.addAttribute("code",code);
return "ranking/multiplayerRanking";
}
@GetMapping("/endGameList/{code}")
@ResponseBody
Expand All @@ -175,7 +132,7 @@ public Map<String, String> endMultiplayerGameTable(@PathVariable String code) {
String playerName = player.getKey().getUsername();
String playerScoreValue;
if(player.getValue()==-1){
playerScoreValue="N/A"; //estaria bien q pusiese jugagando pero internazionalizadp
playerScoreValue="N/A";
}else{
playerScoreValue=""+player.getValue();
}
Expand All @@ -184,8 +141,6 @@ public Map<String, String> endMultiplayerGameTable(@PathVariable String code) {
return playersNameWithScore;
}



@GetMapping("/game/lobby/{code}")
@ResponseBody
public List<String> updatePlayerList(@PathVariable String code) {
Expand All @@ -208,14 +163,9 @@ public String createLobby( HttpSession session, Model model) {

@GetMapping("/game/startMultiplayerGame")
public String startMultiplayerGame( HttpSession session, Model model) {
//La idea seria q dando uno al boton de empezar empezasen todos
return "/game/lobby";
}





/**
* This method is used to check the answer for a specific question
* @param idQuestion The id of the question.
Expand Down Expand Up @@ -286,9 +236,6 @@ public String updateGame(Model model, HttpSession session, Principal principal)
playerService.setScoreMultiplayerCode(p.getId(),""+gameSession.getScore());
multiplayerSessionService.changeScore(p.getMultiplayerCode()+"",p.getId(),gameSession.getScore());
isMultiPlayer=false;
//return "game/multiplayerGame/endGame/"+p.getMultiplayerCode();
//return "redirect:multiplayerGame/endGame/"+p.getMultiplayerCode();
//return "redirect:multiplayerGame/endGame/"+p.getMultiplayerCode();
return "game/multiFinished";
}
if (nextQuestion == null) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/uniovi/entities/MultiplayerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class MultiplayerSession {
private Long id;
@Column
private String multiplayerCode;
//@ManyToMany
//private Set<Player> players =new HashSet<>();

@ElementCollection
@Column
private Map<Player, Integer> playerScores = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
import java.util.List;

public interface MultiplayerSessionRepository extends CrudRepository<MultiplayerSession, Long> {
//List<MultiplayerSession> findAll();

// @Query("SELECT m FROM MultiplayerSession m JOIN FETCH m.playerScores p WHERE m.multiplayerCode = :multiplayerCode ORDER BY p.scoreMultiplayerCode")
// Page<MultiplayerSession> findPlayersByMultiplayerCode(Pageable pageable, String multiplayerCode);

MultiplayerSession findByMultiplayerCode(String code);
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@

@Service
public class MultiplayerSessionImpl implements MultiplayerSessionService {
private PlayerRepository playerRepository;
private MultiplayerSessionRepository multiplayerSessionRepository;
private final PlayerRepository playerRepository;
private final MultiplayerSessionRepository multiplayerSessionRepository;


public MultiplayerSessionImpl(PlayerRepository playerRepository, MultiplayerSessionRepository multiplayerSessionRepository) {
this.playerRepository = playerRepository;
this.multiplayerSessionRepository = multiplayerSessionRepository;
}

// @Override
// public Page<MultiplayerSession> getMultiplayerPlayerRanking(Pageable pageable, int multiplayerCode) {
// return multiplayerSessionRepository.findPlayersByMultiplayerCode(pageable, ""+multiplayerCode);
// }

@Override
public Map<Player, Integer> getPlayersWithScores(int multiplayerCode) {
MultiplayerSession session = multiplayerSessionRepository.findByMultiplayerCode(String.valueOf(multiplayerCode));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ multi.results =Ver resultados
# -------------------Statements for the multiFinished.html file---------------------
multi.finished= Partida finalizada
multi.points = Puntuaciones

multi.menu = Ir a la página de inicio
# -------------------Statements for the apiHome.html file---------------------
api.doc.title=Documentación de la API
api.doc.description=Esta es la documentación de la API de WIQ. Aquí puedes encontrar información sobre los recursos disponibles, los parámetros que aceptan y los ejemplos de uso.
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ multi.results = See results
# -------------------Statements for the multiFinished.html file---------------------
multi.finished= Finished game
multi.points = Points
multi.menu =Go to home page


# -------------------Statements for the apiHome.html file---------------------
api.doc.title=API Documentation
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ multi.results =Ver resultados
# -------------------Statements for the multiFinished.html file---------------------
multi.finished= Partida finalizada
multi.points = Puntuaciones
multi.menu = Ir a la página de inicio


# -------------------Statements for the apiHome.html file---------------------
api.doc.title=Documentación de la API
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ multi.results=Voir les résultats
# -------------------Statements for the multiFinished.html file---------------------
multi.finished= Jeu terminé
multi.points = Points
multi.menu =aller à la page d'accueil


# -------------------Statements for the apiHome.html file---------------------
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/templates/game/multiplayerGame.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
<div class="form-group col-sm-8 mx-auto">
<input type="text" class="form-control w-80 mx-auto" id="code" name="code"
th:placeholder="#{multi.placeholder}" oninput="toggleJoinButton()" style="text-align: center"/>
<!--<span class="text-danger" th:if="${#fields.hasErrors('code')}" th:errors="*{email}"></span>-->
<p id="error-msg" class="text-danger" style="display: none;" th:text="#{multi.onlyNumber}"></p>

</div>
<button id="joinBtn" type="submit" class="btn btn-custom btn-block mb-2" th:text="#{multi.join}" onclick="joinGame()" disabled></button>
<!--Hay q comprobar q el codigo exista y demás
<span class="text-danger" th:if="${#fields.hasErrors('username')}" th:errors="*{username}"></span>-->

<p class="display-5 text-center">
<span th:text="#{multi.text}"></span>
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/templates/ranking/multiplayerRanking.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ <h3 th:text="${code}"></h3>
</ul>
</div>
</div>
<div class="text-center">
<a th:href="@{'/'}">
<button id="createBtn" type="button" class="btn btn-custom" th:text="#{multi.menu}"></button>
</a>
</div>

<footer th:replace="~{fragments/footer}"/>
</body>
</html>
Expand Down

0 comments on commit af999eb

Please sign in to comment.