Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / resources / GameStateRest.java
package com.ntlab.irisserver.resources;

import com.ntlab.irisserver.entities.Cell;
import com.ntlab.irisserver.entities.Game;
import com.ntlab.irisserver.entities.Room;
import com.ntlab.irisserver.entities.Turn;
import com.ntlab.irisserver.models.RoomManager;
import org.springframework.stereotype.Component;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;

@Component
@Path("/rooms")

public class GameStateRest {
    @Path("/{rid}/game/opens")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public  List<Boolean> getOpens(@PathParam("rid") String rid){
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        List<Boolean> opens = game.getOpens();
        return opens;
    }

    @Path("/{rid}/game/turn")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String getTeam(@PathParam("rid") String rid) {
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        Turn turn = game.getTurn(game.getNowTurn());
        String team = turn.getTeam();
        return team;
    }
}