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<>();
    private Map<Integer, Drawing> drawingList = new HashMap<>();
    private Map<Integer, String> keywordList = new HashMap<>();
    private List<Integer> map = new ArrayList<>();
    private List<String> color = new ArrayList<>();
    //private String turn = "none";
    private List<Boolean> opens = new ArrayList<>();
    private DrawingController drawingController = null;
    private Settings settings = null;
    private List<Turn> turnList = new ArrayList<>();
    private Turn nowTurn = null;

    public Game(Room room) {

        this.settings = room.getSettings();
        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をランダムにマップに割り振る

        List<Member> memberList = room.getMembers();
        //デバッグ用に値を追加
        int cnt = 0;
        for (int i=0; i<memberList.size(); i++){
            List<Integer> dnos = new ArrayList<>();
            for(int j=0; j<3; j++){
                dnos.add(cnt);
                cnt++;
            }
            assignments.put(memberList.get(i), dnos);
        }
        //
        drawingController = new DrawingController(room, room.getMembers(), this);
    }

    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);
    }
}