Beispiel #1
0
    IEnumerator GetPlayerResource()
    {
        WWWForm l_form = new WWWForm();

        l_form.AddField("playerId", m_id);

        string l_urlPlayerResource = GetIPAddress.GetAddress() + "GetPlayerResource";
        WWW    l_playerResource    = new WWW(l_urlPlayerResource, l_form);

        JsonData l_resourceData = new JsonData();

        yield return(l_playerResource);

        if (l_playerResource.error != null)
        {
            //TODO handle error.
            Debug.Log(l_playerResource.error);
        }
        else
        {
            l_resourceData = JsonMapper.ToObject(l_playerResource.text);
        }

        m_medalText.text     = l_resourceData["medal"].ToString();
        m_bdiamondsText.text = l_resourceData["bdiamonds"].ToString();
        m_mdiamondsText.text = l_resourceData["mdiamonds"].ToString();
        m_sdiamondsText.text = l_resourceData["sdiamonds"].ToString();
    }
Beispiel #2
0
	IEnumerator GetOtherMap(int p_mapId)
	{
		m_currentMapId = p_mapId;
		WWWForm l_formTemp = new WWWForm();
		l_formTemp.AddField("mapId", p_mapId);
		string l_urlotherMap = GetIPAddress.GetAddress() + "GetOtherMap";
		WWW l_getotherMap = new WWW(l_urlotherMap, l_formTemp);

		yield return l_getotherMap;
		
		JsonData l_jsonMap = new JsonData();
		if (l_getotherMap.error != null)
		{
			Debug.Log(l_getotherMap.error);
		}
		else
		{
			l_jsonMap = JsonMapper.ToObject(l_getotherMap.text);
		}
		
		JsonData l_map =  l_jsonMap["map"];
		m_map = new int[l_map.Count, l_map[0]["row"].Count];
		for (int i = 0; i < l_map.Count; ++i)
		{
			JsonData l_row = l_map[i]["row"];
			for (int j = 0; j < l_row.Count; ++j)  
			{
				m_map [i, j] = (int)l_row[j]["column"];
			}
		}
		PrintMaze ();
		GameObject l_otherPlayer = (GameObject)GameObject.Instantiate(m_otherPlayer, new Vector3 (2, 0, 2), new Quaternion (0, 0, 0, 0));
		GameObject.FindGameObjectWithTag("UICamera").SendMessage("InitUI", SendMessageOptions.DontRequireReceiver);
		l_otherPlayer.transform.parent = m_mazeObject.transform;
	}
Beispiel #3
0
	IEnumerator Upload()
	{
		WWWForm l_form = new WWWForm();

		l_form.AddField("playerId", m_playerId.ToString());
		l_form.AddField ("map", MapToJSON(m_map));
		
		string l_urlUpload = GetIPAddress.GetAddress() + "UploadMap";
		WWW l_upload = new WWW(l_urlUpload, l_form);
		
		JsonData l_uploadReturn = new JsonData();
		
		yield return l_upload;
		
		if (l_upload.error != null)
		{
			//TODO handle error.
			Debug.Log(l_upload.error);
		}
		else
		{
			l_uploadReturn = JsonMapper.ToObject(l_upload.text);
		}
		m_currentMapId = (int)l_uploadReturn["mapId"];
		m_myMapId = m_currentMapId;
	}
Beispiel #4
0
    IEnumerator ScreenShot()
    {
        DontDestroyOnLoad(gameObject);

        string m_urlCheckState = GetIPAddress.GetAddress() + "CheckState";

        WWWForm l_form = new WWWForm();

        l_form.AddField("id", m_id);
        WWW l_getData = new WWW(m_urlCheckState, l_form);

        yield return(l_getData);

        m_jsonResult = JsonMapper.ToObject(l_getData.text);
        int l_isBreak = (int)m_jsonResult ["isBreak"];

        if (l_isBreak != 0)
        {
            m_messageText.text = "玩家闯入中,预计剩余时间:";
            do
            {
                string m_urlCheckStateGetBreakTime = GetIPAddress.GetAddress() + "GetBreakTime";
                l_getData = new WWW(m_urlCheckStateGetBreakTime, l_form);

                yield return(l_getData);

//				while (!l_getData.isDone)
//				{
//					yield return new WaitForSeconds (1);
//				}
                m_jsonResult = JsonMapper.ToObject(l_getData.text);

                int l_second = (int)m_jsonResult ["time"];
                if (l_second > 0)
                {
                    m_breakTimeText.text = l_second + " 秒";
                }
                else
                {
                    break;
                }

                l_getData = new WWW(m_urlCheckState, l_form);

                yield return(l_getData);

//				while (!l_getData.isDone)
//				{
//					yield return new WaitForSeconds (1);
//				}
                m_jsonResult = JsonMapper.ToObject(l_getData.text);
                l_isBreak    = (int)m_jsonResult ["isBreak"];

                yield return(new WaitForSeconds(1));
            }while (l_isBreak != 0);
        }
        Application.LoadLevel("Maze");
    }
Beispiel #5
0
    void OnApplicationQuit()
    {
        string m_url = GetIPAddress.GetAddress() + "Logout";

        WWWForm form = new WWWForm();

        form.AddField("playerId", m_id);
        new WWW(m_url, form);
    }
Beispiel #6
0
	void UpdateResource(int p_resourceType)
	{
		WWWForm l_form = new WWWForm();
		
		l_form.AddField("mapId", m_currentMapId);
		l_form.AddField("playerId", m_playerId);
		l_form.AddField ("map", MapToJSON(m_map));
		l_form.AddField ("resourceType", p_resourceType);
		
		string l_urlUpdate = GetIPAddress.GetAddress() + "UpdateResource";
		new WWW(l_urlUpdate, l_form);
	}
Beispiel #7
0
	void ExitOtherPlayer()
	{
		foreach(Transform child in m_mazeObject.transform)
		{
			Destroy(child.gameObject);
		}

		string l_urlGetState = GetIPAddress.GetAddress() + "QuitOtherMap ";
		WWWForm l_formTemp = new WWWForm();
		l_formTemp.AddField("targetPlayerId", m_targetPlayerId);
		new WWW(l_urlGetState, l_formTemp);

		StartCoroutine(GetMap(m_myMapId));
	}
Beispiel #8
0
	IEnumerator TryEnterOtherPlayer(int p_playerId)
	{
		m_targetPlayerId = p_playerId;
		string l_urlGetState = GetIPAddress.GetAddress() + "GetOtherState";
		WWWForm l_formTemp = new WWWForm();
		l_formTemp.AddField("targetPlayerId", p_playerId);
		l_formTemp.AddField("playerId", m_playerId);
		l_formTemp.AddField("longitude", m_longitude.ToString());
		l_formTemp.AddField("latitude", m_latitude.ToString());

		WWW l_getState = new WWW(l_urlGetState, l_formTemp);

		yield return l_getState;

		JsonData l_jsonResult = new JsonData();
		if (l_getState.error != null)
		{
			Debug.Log(l_getState.error);
		}
		else
		{
			l_jsonResult = JsonMapper.ToObject(l_getState.text);
		}

		GameObject l_mainPlayer = GameObject.FindGameObjectWithTag("MainPlayerObject");

		switch ((int)l_jsonResult["result"])
		{
		case 2:
			foreach(Transform child in m_mazeObject.transform)
			{
				Destroy(child.gameObject);
			}
			StartCoroutine(GetOtherMap((int)l_jsonResult["mapId"]));
			break;
		case 1:
			l_mainPlayer.SendMessage("FinishEnter", SendMessageOptions.DontRequireReceiver);
			l_mainPlayer.SendMessage("OnlineState", SendMessageOptions.DontRequireReceiver);
			break;
		case 0:
			l_mainPlayer.SendMessage("FinishEnter", SendMessageOptions.DontRequireReceiver);
			l_mainPlayer.SendMessage("WrongArea", SendMessageOptions.DontRequireReceiver);
			break;
		default:
			l_mainPlayer.SendMessage("FinishEnter", SendMessageOptions.DontRequireReceiver);
			l_mainPlayer.SendMessage("FailToEnter", SendMessageOptions.DontRequireReceiver);
			break;
		}
	}
Beispiel #9
0
    IEnumerator ScreenShot()
    {
        string l_account  = this.m_account.value;
        string l_password = this.m_password.value;

        if (l_account != null)
        {
            //Gets all information of player by account.
            string m_url = GetIPAddress.GetAddress() + "Login";

            WWWForm l_form = new WWWForm();
            l_form.AddField("account", l_account);
            l_form.AddField("password", l_password);
            WWW l_getData = new WWW(m_url, l_form);

            yield return(l_getData);

            if (l_getData.error != null)
            {
                m_showMessage.text = l_getData.error;
            }
            else
            {
                m_jsonValue = JsonMapper.ToObject(l_getData.text);
                int l_result = (int)m_jsonValue["result"];

                if (l_result == 1)
                {
                    DontDestroyOnLoad(gameObject);
                    Application.LoadLevel("Menu");
                }
                else if (l_result == -1)
                {
                    m_showMessage.text = "account is alreay online";
                }
                else
                {
                    m_showMessage.text = "account or password is not right!";
                }
            }
        }
        else
        {
            m_showMessage.text = "Please input account";
        }
    }
Beispiel #10
0
	IEnumerator InitMap() 
	{
		WWWForm l_form = new WWWForm();

		l_form.AddField("longitude", m_longitude.ToString());
		l_form.AddField("latitude", m_latitude.ToString());
		l_form.AddField("id", m_playerId);

		string l_urlPosition = GetIPAddress.GetAddress() + "CheckPosition";
		WWW l_checkPosition = new WWW(l_urlPosition, l_form);

		yield return l_checkPosition;

		if (l_checkPosition.error != null)
		{
			//TODO handle error.
			Debug.Log(l_checkPosition.error);
		}
		else
		{
			JsonData l_json = JsonMapper.ToObject(l_checkPosition.text);
			if ((int)l_json["result"] == 0)
			{
				StartCoroutine(MakeMaze());
			}
			if ((int)l_json["result"] == 1)
			{
				if ((int)l_json["mapId"] !=0)
				{
					StartCoroutine(GetMap((int)l_json["mapId"]));
				}
				else
				{
					StartCoroutine(MakeMaze());
				}
			}
		}
	}
Beispiel #11
0
	IEnumerator MakeMaze()  
	{
		WWWForm l_form = new WWWForm();
		
		l_form.AddField("longitude", m_longitude.ToString());
		l_form.AddField("latitude", m_latitude.ToString());
		l_form.AddField("playerId", m_playerId.ToString());
		
		string l_urlResources = GetIPAddress.GetAddress() + "GetMapResource";
		WWW l_getResources = new WWW(l_urlResources, l_form);

		JsonData l_jsonResources = new JsonData();
		
		yield return l_getResources;
		
		if (l_getResources.error != null)
		{
			//TODO handle error.
			Debug.Log(l_getResources.error);
		}
		else
		{
			l_jsonResources = JsonMapper.ToObject(l_getResources.text);
		}

		m_x = (int)l_jsonResources["sizeX"];
		m_y = (int)l_jsonResources["sizeY"];
		m_gemBigCount = (int)l_jsonResources["bdiamonds"];
		m_gemMidCount = (int)l_jsonResources["mdiamonds"];
		m_gemSmallCount = (int)l_jsonResources["sdiamonds"];
		m_medalCount = (int)l_jsonResources["medal"];
		m_trapCount = (int)l_jsonResources["trapNumb"];
		m_enemyCount = (int)l_jsonResources["playerNumb"];
		//TODO room.

		if (m_enemyCount > 0)
		{
			m_otherPlayerId = new int[m_enemyCount];
			for (int i = 0; i < l_jsonResources["player"].Count; i++)
			{
				m_otherPlayerId[i] = (int)l_jsonResources["player"][i]["playerId"];
			}
		}

		m_map = new int[m_x * 2 + 3, m_y * 2 + 3];
		for (int i = 0; i < m_x * 2 + 3; ++i)
		{
			for (int j = 0; j < m_y * 2 + 3; ++j)
			{
				m_map [i, j] = 1;  
			}
		}

		for(m_loopX = 0, m_loopY = 2 * m_y + 2; m_loopX <= 2 * m_x + 2; ++m_loopX)  
		{  
			m_map[m_loopX, 0] = 0;  
			m_map[m_loopX, m_loopY] = 0;  
		}  
		for(m_loopX = 0, m_loopY = 2 * m_x + 2; m_loopX <= 2 * m_y + 2; ++m_loopX)  
		{  
			m_map[0, m_loopX] = 0;  
			m_map[m_loopY, m_loopX] = 0;  
		}

		SearchPath(Random.Range(0, m_x) + 1, Random.Range(0, m_y) + 1);  

		EditMaze();
		PrintMaze();
		GameObject l_player = (GameObject)GameObject.Instantiate(m_player, new Vector3 (2, 0, 2), new Quaternion (0, 0, 0, 0));
		l_player.transform.parent = m_mazeObject.transform;
		
		if (GameObject.FindGameObjectWithTag("Respawn"))
		{
			GameObject l_spawn = GameObject.FindGameObjectWithTag ("Respawn");
			l_player.transform.position = l_spawn.transform.position;
		}
		else
		{
			GameObject l_newSpawn;
			l_newSpawn = (GameObject)Instantiate (m_spawn, new Vector3 (2, 0, 2), new Quaternion (0, 0, 0, 0));
			l_newSpawn.transform.parent = m_mazeObject.transform;
			m_spawnPosition[0] = 2;
			m_spawnPosition[1] = 2;
		}
		GameObject.FindGameObjectWithTag("UICamera").SendMessage("InitUI", SendMessageOptions.DontRequireReceiver);
		StartCoroutine(Upload());
	}