Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / resources / GameStateRest.java
  1. package com.ntlab.irisserver.resources;
  2.  
  3. import com.ntlab.irisserver.entities.Cell;
  4. import com.ntlab.irisserver.entities.Game;
  5. import com.ntlab.irisserver.entities.Room;
  6. import com.ntlab.irisserver.entities.Turn;
  7. import com.ntlab.irisserver.models.RoomManager;
  8. import org.springframework.stereotype.Component;
  9.  
  10. import javax.ws.rs.*;
  11. import javax.ws.rs.core.MediaType;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. @Component
  16. @Path("/rooms")
  17.  
  18. public class GameStateRest {
  19. @Path("/{rid}/game/opens")
  20. @GET
  21. @Produces(MediaType.APPLICATION_JSON)
  22. public List<Boolean> getOpens(@PathParam("rid") String rid){
  23. List<Boolean> opens= new ArrayList<>();
  24. RoomManager rm = RoomManager.getInstance();
  25. Room room = rm.getRoom(rid);
  26. Game game = room.getGame();
  27. for(int i=0; i<16; i++){
  28. Cell cell = game.getCell(i);
  29. boolean isOpen = cell.getIsOpen();
  30. opens.add(isOpen);
  31. }
  32. return opens;
  33. }
  34.  
  35. @Path("/{rid}/game/turn")
  36. @GET
  37. @Produces(MediaType.APPLICATION_JSON)
  38. public String getTeam(@PathParam("rid") String rid) {
  39. RoomManager rm = RoomManager.getInstance();
  40. Room room = rm.getRoom(rid);
  41. Game game = room.getGame();
  42. Turn turn = game.getTurn(game.getNowTurn());
  43. String team = turn.getTeam();
  44. return team;
  45. }
  46. }