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

import java.util.*;

public class Game {

    private Map<Member, List<Integer>> assignments = new HashMap<>();//<Member, List<dno>>
    private Map<Integer, Drawing> drawingList = new HashMap<>();//<dno,Drawing>
    private Map<Integer, String> keywordList = new HashMap<>();//<dno, keyword>
    private Map<Integer, Cell> cellList = new HashMap<>();//<cno, Cell>

    private List<Integer> map = new ArrayList<>();//cno順にdnoを管理
    private List<String> color = new ArrayList<>();//cno順にr,g,b,dを管理
    private List<Boolean> opens = new ArrayList<>();//cno順にカードの開閉状態を管理
    private List<Turn> turnList = new ArrayList<>();

    private Turn nowTurn = null;//現在のターン
    private DrawingController drawingController = null;
    private Settings settings = null;

    public Game(Room room) {
        List<Member> memberList = room.getMembers();
        int num = 16/memberList.size();//一人あたりが確実に採用されるイラスト枚数
        int cnt = 0;
        for(int i=0; i<memberList.size(); i++){
            List<Integer> dnoList = new ArrayList<>();//一人が描くイラストのdnoリスト
            for(int j=0; j<num; j++){
                dnoList.add(cnt);
                cnt++;
            }
            assignments.put(memberList.get(i), dnoList);
        }
        int remainder = 0;//残りの割り当て枚数
        if(16%memberList.size()!=0) remainder = ((num+1)* memberList.size()) - cnt;

        for(int i=0; i<remainder; i++){
            List<Integer> dnoList =  assignments.get(memberList.get(i));
            dnoList.add(cnt);
            cnt++;
            assignments.put(memberList.get(i), dnoList);
        }

        for(int i=0; i<16; i++) map.add(i);
        Collections.shuffle(map);//0~15のdnoをランダムにマップに割り振る
        //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をランダムにマップに割り振る

        this.settings = room.getSettings();
        drawingController = new DrawingController(room, room.getMembers(), this);

        //Cellのインスタンス作成
        for(int i=0; i<16; i++){
            Cell c = new Cell();
            cellList.put(i, c);
            c.setCno(i);
            c.setColor(color.get(i));
            c.setDno(map.get(i));
        }

    }

    public DrawingController getDrawingController() {
        return drawingController;
    }

    public Drawing getDrawing(int dno) {
        Drawing d = drawingList.get(dno);
        return d;
    }

    public Map<Integer, Drawing> getDrawings(){
        return drawingList;
    }

    public Drawing putDrawing(int dno, Drawing drawing) {
        Drawing d = drawingList.put(dno, drawing);
        drawingController.update();
        return d;
    }

    public String getKeyword(int dno) {
        String keyword = keywordList.get(dno);
        return keyword;
    }

    public List<String> getKeywords() {
        List<String> keywords = new ArrayList<>(keywordList.values());
        return keywords;
    }

    public Map<Member, List<Integer>> getAssignments(){
        return assignments;
    }

    public List<Integer> getMap(){
        return map;
    }
    public List<String> getColor(){
        return color;
    }

    public String getTeam(){
        String team = nowTurn.getTeam();
        return team;
    }

    public List<Boolean> getOpens(){
        return opens;
    }

    public Settings getSettings(){
        return this.settings;
    }

    public void createTurn(){
        nowTurn = new Turn();
        if(turnList.size()%2==0){//偶数ターンなら青い色,奇数ターンは赤色
            nowTurn.setTeam("b");
        }else{
            nowTurn.setTeam("r");
        }
        this.turnList.add(nowTurn);
    }

    public Turn getTurn(Integer num){
        return turnList.get(num);
    }

    public Integer getNowTurn(){//現在何ターン目か取得
        return turnList.size()-1;
    }
}