Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / entities / Game.java
  1. package com.ntlab.irisserver.entities;
  2.  
  3. import com.ntlab.irisserver.models.KeywordManager;
  4.  
  5. import java.util.*;
  6.  
  7. public class Game {
  8.  
  9. private Map<Member, List<Integer>> assignments = new HashMap<>();//<Member, List<dno>>
  10. private Map<Integer, Drawing> drawingList = new HashMap<>();//<dno,Drawing>
  11. private Map<Integer, String> keywordList = new HashMap<>();//<dno, keyword>
  12. private Map<Integer, Cell> cellList = new HashMap<>();//<cno, Cell>
  13.  
  14. private List<Integer> map = new ArrayList<>();//cno順にdnoを管理
  15. private List<String> color = new ArrayList<>();//cno順にr,g,b,dを管理
  16. private List<Turn> turnList = new ArrayList<>();
  17.  
  18. private Turn nowTurn = null;//現在のターン
  19. private DrawingController drawingController = null;
  20. private Settings settings = null;
  21.  
  22. public Game(Room room, String[] keywords) {
  23.  
  24. room.setGame(this);
  25. this.settings = room.getSettings();
  26. drawingController = new DrawingController(room, room.getMembers(), this);
  27.  
  28. List<Member> memberList = room.getMembers();
  29. int num = 16/memberList.size();//一人あたりが確実に採用されるイラスト枚数
  30. int cnt = 0;
  31. for(int i=0; i<memberList.size(); i++){
  32. List<Integer> dnoList = new ArrayList<>();//一人が描くイラストのdnoリスト
  33. for(int j=0; j<num; j++){
  34. dnoList.add(cnt);
  35. cnt++;
  36. }
  37. assignments.put(memberList.get(i), dnoList);
  38. }
  39. int remainder = 0;//残りの割り当て枚数
  40. if(16%memberList.size()!=0) remainder = ((num+1)* memberList.size()) - cnt;
  41.  
  42. for(int i=0; i<remainder; i++){
  43. List<Integer> dnoList = assignments.get(memberList.get(i));
  44. dnoList.add(cnt);
  45. cnt++;
  46. assignments.put(memberList.get(i), dnoList);
  47. }
  48.  
  49. for(int i=0; i<16; i++) map.add(i);
  50. Collections.shuffle(map);//0~15のdnoをランダムにマップに割り振る
  51. System.out.println(map);
  52. //r:6 b:5 g:4 d:1
  53. for(int i=0; i<6; i++) color.add("r");
  54. for(int i=0; i<5; i++) color.add("b");
  55. for(int i=0; i<4; i++) color.add("g");
  56. color.add("d");
  57. Collections.shuffle(color);//r,b,g,dをランダムにマップに割り振る
  58.  
  59. List<String> randKeys = Arrays.asList(keywords);//コンストラクタの引数で受け取ったキーワードをリストに変換
  60. Collections.shuffle(randKeys);//キーワードをシャッフル
  61.  
  62. //Cellのインスタンス作成
  63. for(int i=0; i<16; i++){
  64. Cell c = new Cell();
  65. cellList.put(i, c);
  66. c.setCno(i);
  67. c.setColor(color.get(i));
  68. c.setDno(map.get(i));
  69.  
  70. //今回のゲームで使用するキーワードを追加
  71. keywordList.put(i, randKeys.get(i));//(dno, キーワード)
  72. }
  73. }
  74.  
  75. public DrawingController getDrawingController() {
  76. return drawingController;
  77. }
  78.  
  79. public Drawing getDrawing(int dno) {
  80. Drawing d = drawingList.get(dno);
  81. return d;
  82. }
  83.  
  84. public Map<Integer, Drawing> getDrawings(){
  85. return drawingList;
  86. }
  87.  
  88. public Drawing putDrawing(int dno, Drawing drawing) {
  89. Drawing d = drawingList.put(dno, drawing);
  90. drawingController.update();
  91. return d;
  92. }
  93.  
  94. public String getKeyword(int dno) {
  95. String keyword = keywordList.get(dno);
  96. return keyword;
  97. }
  98.  
  99. public List<String> getKeywords() {
  100. List<String> keywords = new ArrayList<>();
  101. for(int i=0; i<16; i++){
  102. keywords.add(keywordList.get(map.get(i)));
  103. }
  104. return keywords;
  105. }
  106.  
  107. public List<Boolean> getOpens(){
  108. List<Boolean> opens= new ArrayList<>();
  109. for(int i=0; i<16; i++){
  110. Cell cell = cellList.get(i);
  111. boolean isOpen = cell.getIsOpen();
  112. opens.add(isOpen);
  113. }
  114. return opens;
  115. }
  116.  
  117. public Map<Member, List<Integer>> getAssignments(){
  118. return assignments;
  119. }
  120.  
  121. public List<Integer> getMap(){
  122. return map;
  123. }
  124. public List<String> getColor(){
  125. return color;
  126. }
  127.  
  128. public Settings getSettings(){
  129. return this.settings;
  130. }
  131.  
  132. public void createTurn(){
  133. nowTurn = new Turn();
  134. if(turnList.size()%2==0){//偶数ターンなら青い色,奇数ターンは赤色
  135. nowTurn.setTeam("b");
  136. }else{
  137. nowTurn.setTeam("r");
  138. }
  139. this.turnList.add(nowTurn);
  140. }
  141.  
  142. public Turn getTurn(Integer num){
  143. return turnList.get(num);
  144. }
  145.  
  146. public Integer getNowTurn(){//現在何ターン目か取得
  147. return turnList.size()-1;
  148. }
  149.  
  150. public Cell getCell(Integer cno){
  151. return cellList.get(cno);
  152. }
  153. }