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

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

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
@Path("/rooms")
public class GameRest {
    @GET
    @Path("/{rid}/game/map")
    @Produces(MediaType.APPLICATION_JSON)
    public List<Integer> getMap(@PathParam("rid") String rid){
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        List<Integer> map = game.getMap();
        return map;
    }

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

    @GET
    @Path("/{rid}/game/keywords")
    @Produces(MediaType.APPLICATION_JSON)
    public List<String> getKeywords(@PathParam("rid") String rid){
        RoomManager rm = RoomManager.getInstance();
        Room room = rm.getRoom(rid);
        Game game = room.getGame();
        Map<Integer, String> keywordList = game.getKeywords();
        List<Integer> map = game.getMap();
        List<String> keywords = new ArrayList<>();
        for(int i=0; i<16; i++){
            keywords.add(keywordList.get(map.get(i)));
        }
        return keywords;
    }

}