package com.ntlab.irisserver.resources; import com.ntlab.irisserver.entities.Drawing; import com.ntlab.irisserver.entities.Game; import com.ntlab.irisserver.entities.Member; import com.ntlab.irisserver.entities.Room; import com.ntlab.irisserver.models.KeywordManager; import com.ntlab.irisserver.models.RoomManager; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import javax.ws.rs.PUT; import javax.ws.rs.Path; import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Random; @Component @Path("/rooms") public class TestRest implements ApplicationContextAware { private org.springframework.context.ApplicationContext applicationContext; public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } public void shafflem(Room room){ List<Member> mem = room.getMembers(); Collections.shuffle(mem); for(int i=0; i < 8; i++){ if(i >= mem.size())break; Member info = mem.get(i); if(i==0){ info.setMaster(true); room.changeTeamAndMaster(info.getNickname(), "r", true); }else if(i==1){ info.setMaster(true); room.changeTeamAndMaster(info.getNickname(), "b", true); }else{ info.setMaster(false); } if(i % 2 == 0){ info.setBelongs("r"); }else{ info.setBelongs("b"); } } } @PUT @Path("/test") public void putTestRoom() throws IOException { KeywordManager km = KeywordManager.getInstance(); RoomManager rm = RoomManager.getInstance(); rm.createTestRoom(); Room tr = rm.getRoom("roomtest"); Room dr = rm.getRoom("drawtest"); Room gr = rm.getRoom("gametest"); //メンバー設定() int length = 0; char[] rch; rch = new char[4]; String rname; while(length < 8){ for(int i = 0; i<4; i++){ Random random = new Random(); rch[i] = (char)(random.nextInt(26) + 'a'); } rname = new String(rch); tr.addMember(rname); dr.addMember(rname); gr.addMember(rname); List<Member> members = dr.getMembers(); length = members.size(); } //チームシャッフル shafflem(tr); shafflem(dr); shafflem(gr); //両部屋:gameインスタンス作成,stateの初期化 String path = null; dr.setState(2); gr.setState(2); try { path = applicationContext.getResource("file:").getFile().getAbsolutePath()+"/apache-tomcat-9.0.10/webapps/irisdata/keywords.txt"; } catch (IOException e) { e.printStackTrace(); } String[] keywords = km.getKeywords(path); Game dgame = new Game(dr, keywords); Game game = new Game(gr, keywords); //gametest部屋:絵の格納 for(int i = 0; i < 16; i++){ Drawing draw = new Drawing(); switch (i) { case 0: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test01.jpg"; break; case 1: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test02.jpg"; break; case 2: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test03.jpg"; break; case 3: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test04.jpg"; break; case 4: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test05.jpg"; break; case 5: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test06.jpg"; break; case 6: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test07.jpg"; break; case 7: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test08.jpg"; break; case 8: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test09.jpg"; break; case 9: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test10.jpg"; break; case 10: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test11.jpg"; break; case 11: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test12.jpg"; break; case 12: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test13.jpg"; break; case 13: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test14.jpg"; break; case 14: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test15.jpg"; break; case 15: path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test16.jpg"; break; default: break; } draw.setDrawing(path); if(i<8){ game.putDrawing(i*2, draw); }else{ game.putDrawing(i*2-15, draw); } } } }