Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / entities / Room.java
package com.ntlab.irisserver.entities;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Room {
        @JsonProperty("rid")
        public String rid;
        //String rid = null;

        @JsonProperty("state")
        public int state;
        //int state;

        @JsonProperty("ownerName")
        public String ownerName;
        //String ownerName = null;

        @JsonProperty("drawingTimer")
        public boolean drawingTimer;
        //boolean drawingTimer;

        @JsonProperty("drawingTimerTimes")
        public int drawingTimerTimes;
        //int drawingTimerTimes;

        @JsonProperty("gameTimer")
        public boolean gameTimer;
        //boolean gameTimer;

        @JsonProperty("gameTimerTimes")
        public int gameTimerTimes;
        //int gameTimerTimes;

        @JsonProperty("gameTimerFirstThinkingTimes")
        public int gameTimerFirstThinkingTimes;
        //int gameTimerFirstThinkingTimes;

        @JsonProperty("RedMaster")
        private Member RedMaster;
        @JsonProperty("BlueMaster")
        private Member BlueMaster;
        Map<String,Member> members= new HashMap<>();
        Map<Integer, Drawing> drawings = new HashMap<>();


        public List<Member> getMembers() {

            return new ArrayList<Member>(members.values());

        }

        public List<Drawing> getDrawings() {

                List<Drawing> drawingslist = new ArrayList<Drawing>(drawings.values()) ;
                return drawingslist;

        }

        //プレイヤーの情報を変更する
        public void changeTeamAndMaster(String nick, String belongs, boolean isMaster) {


                //変更対象の情報を取得
                Member m = members.get(nick);

                //変更先のチームに既に所属している場合は変更なし
                if(m.getBelongs() != belongs){

                        //1チームの最大人数は8人
                        //変更先のチームの人数を数える
                        int memberscount = 0;
                        List<Member> membersList = new ArrayList<Member>(members.values()) ;

                        for(Member mem :membersList){
                                if(mem.getBelongs() == belongs){
                                        memberscount++;
                                }
                        }

                        //変更先のチームが満員であれば変更不可
                        if(memberscount >= 8) {
                                return;
                        }else{
                                m.setBelongs(belongs);
                        }

                }

                //マスターを変更
                if(belongs == "r"){

                        //赤チームのマスターをメンバーに変更
                        if(RedMaster != null){
                                RedMaster.setMaster(false);
                        }

                        //変更対象を赤チームのマスターに変更
                        m.setMaster(true);
                        RedMaster = m;
                }

                if(belongs == "b"){

                        //青チームのマスターをメンバーに変更
                        if(BlueMaster != null){
                                BlueMaster.setMaster(false);
                        }

                        //変更対象を赤チームのマスターに変更
                        m.setMaster(true);
                        BlueMaster = m;
                }


        }

        public Member getMember(String nick) {
            return members.get(nick);
        }

        public void addMember(String nick){
                Member m=new Member(nick);
                m.setNickname(nick);
                members.put(nick,m);
        }
        public int getStateRest(){
                return 0;
        }


        public Room(String rid, String owner) {
            drawingTimer = false;
            drawingTimerTimes = 0;
            gameTimer = true;
            gameTimerTimes = 30;
            gameTimerFirstThinkingTimes = 10;
                this.rid=rid;
                ownerName=owner;
        }
        public Drawing getDrawing(int dno) {
                return drawings.get(dno);
        }

        public void putDrawing(int dno, Drawing d) {
                drawings.put(dno, d);
        }

        public void setDrawingTimer(boolean drawingTimer) {
                this.drawingTimer = drawingTimer;
        }

        public void setDrawingTimerTimes(int drawingTimerTimes) {
                this.drawingTimerTimes = drawingTimerTimes;
        }

        public void setGameTimer(boolean gameTimer) {
                this.gameTimer = gameTimer;
        }

        public void setGameTimerTimes(int gameTimerTimes) {
                this.gameTimerTimes = gameTimerTimes;
        }

        public void setGameTimerFirstThinkingTimes(int gameTimerFirstThinkingTimes) {
                this.gameTimerFirstThinkingTimes = gameTimerFirstThinkingTimes;
        }

        public boolean isDrawingTimer() {
                return drawingTimer;
        }

        public int getDrawingTimerTimes() {
                return drawingTimerTimes;
        }

        public boolean isGameTimer() {
                return gameTimer;
        }

        public int getGameTimerTimes() {
                return gameTimerTimes;
        }

        public int getGameTimerFirstThinkingTimes() {
                return gameTimerFirstThinkingTimes;
        }



}