diff --git a/src/main/java/com/ntlab/irisserver/entities/Room.java b/src/main/java/com/ntlab/irisserver/entities/Room.java index b0c6d02..8ff70e3 100644 --- a/src/main/java/com/ntlab/irisserver/entities/Room.java +++ b/src/main/java/com/ntlab/irisserver/entities/Room.java @@ -40,12 +40,25 @@ public int gameTimerFirstThinkingTimes; //int gameTimerFirstThinkingTimes; - - + @JsonProperty("redMaster") + private Member redMaster; + @JsonProperty("blueMaster") + private Member blueMaster; Map members= new HashMap<>(); Map drawings = new HashMap<>(); + + public Room(String rid, String owner) { + this.rid=rid; + ownerName=owner; + drawingTimer = false; + drawingTimerTimes = 0; + gameTimer = true; + gameTimerTimes = 30; + gameTimerFirstThinkingTimes = 10; + } + public List getMembers() { List memberslist = new ArrayList(members.values()) ; @@ -53,8 +66,69 @@ } + public List getDrawings() { + + List drawingslist = new ArrayList(drawings.values()) ; + return drawingslist; + + } + + //プレイヤーの情報を変更する public void changeTeamAndMaster(String nick, String belongs, boolean isMaster) { + + //変更対象の情報を取得 + Member m = members.get(nick); + + //変更先のチームに既に所属している場合は変更なし + if(!(m.getBelongs().equals(belongs))) { + + //1チームの最大人数は8人 + //変更先のチームの人数を数える + int memberscount = 0; + List membersList = new ArrayList(members.values()) ; + + for(Member mem :membersList) { + if(mem.getBelongs().equals(belongs)) { + memberscount++; + } + } + + //変更先のチームが満員であれば変更不可 + if(memberscount >= 8) { + return; + }else{ + m.setBelongs(belongs); + } + + } + + //マスターを変更 + if(belongs.equals("r")) { + + //赤チームのマスターをメンバーに変更 + if(redMaster != null) { + redMaster.setMaster(false); + } + + //変更対象を赤チームのマスターに変更 + m.setMaster(true); + redMaster = m; + } + + if(belongs.equals("b")) { + + //青チームのマスターをメンバーに変更 + if(blueMaster != null) { + blueMaster.setMaster(false); + } + + //変更対象を赤チームのマスターに変更 + m.setMaster(true); + blueMaster = m; + } + + } public Member getMember(String nick) { @@ -62,27 +136,16 @@ return m; } - public void addMember(String nick){ + public void addMember(String nick) { Member m=new Member(nick); m.setNickname(nick); members.put(nick,m); } - public int getStateRest(){ + public int getStateRest() { return 0; } - public Room(){ - drawingTimer = false; - drawingTimerTimes = 0; - gameTimer = true; - gameTimerTimes = 30; - gameTimerFirstThinkingTimes = 10; - } - public Room(String rid, String owner) { - this.rid=rid; - ownerName=owner; - } public Drawing getDrawing(int dno) { return drawings.get(dno); } @@ -132,4 +195,5 @@ } + }