Newer
Older
SproutServerMicro / src / main / java / org / ntlab / SproutServer / rooms / Room.java
s-bekki on 30 Nov 2017 5 KB initial commit
package org.ntlab.SproutServer.rooms;

import java.awt.List;
import java.security.KeyStore.TrustedCertificateEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.ntlab.SproutServer.battles.Battle;
import org.ntlab.SproutServer.battles.Team;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
import org.omg.PortableServer.ThreadPolicyOperations;
import org.w3c.dom.html.HTMLIsIndexElement;

import net.arnx.jsonic.JSONHint;


/**
 * Root resource (exposed at "Rooms" path)
 */
public class Room {
	
	public String roomName;             //ルーム名
	private String roomKey;              //ルームキー(ルームパスワード)
	public int roomId;                  //ルームID
	public String hostName;             //ホストネーム
	public boolean keyCheck = false;
	public HashMap<Integer,Member> memberList = new HashMap<Integer,Member>();
	public boolean readyToFight = false;    //全員準備完了したか判定	
	private int memberId=0;
	public boolean startFrag;
	public boolean battleState = false;
	public int battleId = -1;
	

	public Room(String roomName,int roomId,String roomKey,Member member){
		this.roomId = roomId;
		this.roomName = roomName;
		this.roomKey = roomKey;
		this.memberList.put(this.memberId,member);
		memberList.get(this.memberId).setMemberId(this.memberId);
		this.memberList.get(memberId).setHostState(true);
		this.hostName = member.getUserName();
		this.memberId++;
		
		if(roomKey != null){
			this.keyCheck = true;
		}
		
	}
	
	public Room(int roomId){
		this.roomId = roomId;
	}
	
	public Room() {
		// TODO Auto-generated constructor stub
	}


	/**
	 * 入室処理
	 */
	public void enterRoom(int memberId,Member member){
		getMemberList().put(memberId, member);
		this.memberList.get(this.memberId).setMemberId(this.memberId);
		this.memberId++;
	}

	/**
	 * パスワードのチェック
	 */
	public boolean keyCheck(String key,int memberId){
		if(this.keyCheck == false){
			return true;
		}
		
		boolean counts = false;
		if(key.equals(this.getRoomKey())){
			counts = true;
		}
		System.out.println("key chek = " + counts);
		return counts;
	}


	/**
	 * バトル終了時のルームの状態の初期化
	 */
	public void roomInitialize(){
		this.battleState = false;
		this.readyToFight = false;
		this.startFrag = false;
		this.battleId = -1;
		for(int value : this.memberList.keySet()){
			if(this.memberList.get(value) != null){
				this.memberList.get(value).setReady(false);
			}
		}
	}


	/**
	 * ホストの次に入った人のメンバーIDを返す
	 */
	public int minimumMemberCount(int memberId){
		int count = 0;
		for(int i = 0;i<this.memberId;i++){
			if(memberList.get(i) != null && memberList.get(i) != memberList.get(memberId)){
				count = i;
				break;
			}
		}	
		System.out.println(count);
		
		return count;
	}


	/**
	 * 部屋を抜けるメソッド
	 */
	public void deleteMember(int memberId){
		int a = 0;
		Member member = this.memberList.get(memberId);
		
		if(member.isReady() == false 
				&& !(member.getUserName().equals(this.hostName))){
			this.memberList.remove(memberId);
		}else if(member.isReady() == false 
				&& member.getUserName().equals(this.hostName)){
			this.memberList.remove(memberId);
			if(this.memberList.size() != 0){
				a = minimumMemberCount(memberId);
				this.hostName = memberList.get(a).getUserName();
				memberList.get(a).setHostState(true);
				member.setHostState(false);
			}
		}		

	}
	
    //メンバーリスト
	@JSONHint(ignore=true)
	public HashMap<Integer,Member> getMemberList() {
		return memberList;
	}

	public void setMemberList(HashMap<Integer,Member> memberList) {
		this.memberList = memberList;
	}
	
	
	//ルームID
	@JSONHint(ignore=true)
	public int getRoomId() {
		return roomId;
	}

	public void setId(int id) {
		this.roomId = id;
	}
	
	
	//ルーム名
	@JSONHint(ignore=true)
	public String getRoomName() {
		return roomName;
	}

	public void setRoomName(String roomName) {
		this.roomName = roomName;
	}
	
	
	//ホストネーム
	@JSONHint(ignore=true)
	public String getHostName() {
		return hostName;
	}

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	
	
	//キーのチェック
	@JSONHint(ignore=true)
	public boolean isKeyCheck() {
		return keyCheck;
	}

	public void setKeyCheck(boolean keyCheck) {
		this.keyCheck = keyCheck;
	}
	
	
	//準備完了判定
	@JSONHint(ignore=true)
	public boolean isReadyToFight() {
		return readyToFight;
	}

	public void setReadyToFight(boolean allReady) {
		this.readyToFight = allReady;
	}
	
	
	//ルームキー(ルームパスワード)
	@JSONHint(ignore=true)
	public String getRoomKey() {
		return roomKey;
	}

	public void setRoomKey(String roomKey) {
		this.roomKey = roomKey;
	}

	//メンバーID(入った順番)
	@JSONHint(ignore=true)
	public int getMemberId() {
		return memberId;
	}

	public void setMemberId(int memberId) {
		this.memberId = memberId;
	}

	//全員準備
	public boolean isStartFrag() {
		return startFrag;
	}

	public void setStartFrag(boolean startFrag) {
		this.startFrag = startFrag;
	}

	//バトル中か否か
	public boolean isBattleState() {
		return battleState;
	}

	public void setBattleState(boolean battleState) {
		this.battleState = battleState;
	}

	
	//バトルID
	public int getBattleId() {
		return battleId;
	}

	public void setBattleId(int battleId) {
		this.battleId = battleId;
	}
	
	
	

	

	
	

	
	
	



}