diff --git a/src/main/java/com/ntlab/irisserver/entities/Cell.java b/src/main/java/com/ntlab/irisserver/entities/Cell.java index ac6b408..1e4cdc2 100644 --- a/src/main/java/com/ntlab/irisserver/entities/Cell.java +++ b/src/main/java/com/ntlab/irisserver/entities/Cell.java @@ -5,7 +5,7 @@ public class Cell { @JsonProperty("isOpen") - private boolean isOpen; + private boolean isOpen; //trueが空いてる、falseは空いてない @JsonProperty("color") public String color; diff --git a/src/main/java/com/ntlab/irisserver/entities/Game.java b/src/main/java/com/ntlab/irisserver/entities/Game.java index 1db1401..3ed6f81 100644 --- a/src/main/java/com/ntlab/irisserver/entities/Game.java +++ b/src/main/java/com/ntlab/irisserver/entities/Game.java @@ -1,7 +1,5 @@ package com.ntlab.irisserver.entities; -import com.ntlab.irisserver.models.KeywordManager; - import java.util.*; public class Game { @@ -12,7 +10,7 @@ private Map cellList = new HashMap<>();// private List map = new ArrayList<>();//cno順にdnoを管理 - private List color = new ArrayList<>();//cno順にr,g,b,dを管理 + private List colorList = new ArrayList<>();//cno順にr,g,b,dを管理 private List turnList = new ArrayList<>(); private Turn nowTurn = null;//現在のターン @@ -50,11 +48,11 @@ Collections.shuffle(map);//0~15のdnoをランダムにマップに割り振る System.out.println(map); //r:6 b:5 g:4 d:1 - for(int i=0; i<6; i++) color.add("r"); - for(int i=0; i<5; i++) color.add("b"); - for(int i=0; i<4; i++) color.add("g"); - color.add("d"); - Collections.shuffle(color);//r,b,g,dをランダムにマップに割り振る + for(int i=0; i<6; i++) colorList.add("r"); + for(int i=0; i<5; i++) colorList.add("b"); + for(int i=0; i<4; i++) colorList.add("g"); + colorList.add("d"); + Collections.shuffle(colorList);//r,b,g,dをランダムにマップに割り振る List randKeys = Arrays.asList(keywords);//コンストラクタの引数で受け取ったキーワードをリストに変換 Collections.shuffle(randKeys);//キーワードをシャッフル @@ -64,7 +62,7 @@ Cell c = new Cell(); cellList.put(i, c); c.setCno(i); - c.setColor(color.get(i)); + c.setColor(colorList.get(i)); c.setDno(map.get(i)); //今回のゲームで使用するキーワードを追加 @@ -121,8 +119,8 @@ public List getMap(){ return map; } - public List getColor(){ - return color; + public List getColorList(){ + return colorList; } public Settings getSettings(){ @@ -150,4 +148,6 @@ public Cell getCell(Integer cno){ return cellList.get(cno); } + + public Map getDrawingList() {return drawingList;} } diff --git a/src/main/java/com/ntlab/irisserver/entities/GameJson.java b/src/main/java/com/ntlab/irisserver/entities/GameJson.java new file mode 100644 index 0000000..d236512 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/GameJson.java @@ -0,0 +1,31 @@ +package com.ntlab.irisserver.entities; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GameJson { + + private Map drawingList = new HashMap<>();// + private List map = new ArrayList<>();//cno順にdnoを管理 + private List colorList = new ArrayList<>();//cno順にr,g,b,dを管理 + + //コンストラクタ + public GameJson(Game g){ + this.drawingList = g.getDrawingList(); + this.map = g.getMap(); + this.colorList = g.getColorList(); + } + + //ゲッター + public Map getDrawingList() {return drawingList;} + public List getMap() {return map;} + public List getColorList() {return colorList;} + + //セッター + public void setDrawingList(Map dlist) {drawingList = dlist;} + public void setMap(List map) {this.map = map;} + public void setColorList(List color) {this.colorList = color;} + +} diff --git a/src/main/java/com/ntlab/irisserver/resources/GameRest.java b/src/main/java/com/ntlab/irisserver/resources/GameRest.java index 228aeb0..c0a7873 100644 --- a/src/main/java/com/ntlab/irisserver/resources/GameRest.java +++ b/src/main/java/com/ntlab/irisserver/resources/GameRest.java @@ -1,6 +1,7 @@ package com.ntlab.irisserver.resources; import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.entities.GameJson; import com.ntlab.irisserver.entities.Room; import com.ntlab.irisserver.models.RoomManager; import org.springframework.stereotype.Component; @@ -10,13 +11,23 @@ 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") + @Produces(MediaType.APPLICATION_JSON) + public GameJson getGame(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + GameJson gj = new GameJson(game); + return gj; + } + @GET @Path("/{rid}/game/map") @Produces(MediaType.APPLICATION_JSON) @@ -31,11 +42,11 @@ @GET @Path("/{rid}/game/color") @Produces(MediaType.APPLICATION_JSON) - public List getColor(@PathParam("rid") String rid){ + public List getColorList(@PathParam("rid") String rid){ RoomManager rm = RoomManager.getInstance(); Room room = rm.getRoom(rid); Game game = room.getGame(); - List color = game.getColor(); + List color = game.getColorList(); return color; }