Example #1
0
        void Start()
        {
            name = PlayerPrefs.GetString("player");
            mode = PlayerPrefs.GetString("temp");
            if (mode.Equals("default"))
            {
                //判断本地储存是否已经存在当前用户
                XmlPlayerInformation xml   = new XmlPlayerInformation();
                PlayerInfromation    local = xml.selectUser("default");
                if (local == null)
                {
                    local.name      = "default";
                    local.id        = "default";
                    local.money     = 0.0;
                    local.score     = 0.0;
                    local.level     = 0;
                    local.castle    = 0;
                    local.defence   = 0;
                    local.propone   = 0;
                    local.proptwo   = 0;
                    local.propthree = 0;
                    xml.addUser(local);
                }
                curScore = local.score.ToString();
            }
            else
            {
                string parameter = "";
                parameter += "UserName=" + name;
                StartCoroutine(getData(Url + parameter));
            }

            StartCoroutine(getRank(getUrl));
        }
Example #2
0
        //访问JSP服务器获得玩家数据
        IEnumerator getData(string path)
        {
            WWW www = new WWW(path);

            yield return(www);

            //如果发生错误,打印这个错误
            if (www.error != null)
            {
                Debug.Log(www.error);
            }
            else
            {
                //如果服务器返回的是true

                //提取数据
                char[]        chars  = www.text.ToCharArray();
                List <string> dbData = new List <string>();
                StringBuilder data   = new StringBuilder();
                for (int i = 0; i < chars.Length; i++)
                {
                    if (chars[i] != ';')
                    {
                        data.Append(chars[i]);
                    }
                    else
                    {
                        dbData.Add(data.ToString());
                        data.Length = 0;
                    }
                }
                local           = new PlayerInfromation();
                local.id        = Username.text + "id";
                local.name      = dbData[0];
                local.score     = System.Convert.ToDouble(dbData[1]);
                local.money     = System.Convert.ToDouble(dbData[2]);
                local.level     = System.Convert.ToInt32(dbData[3]);
                local.castle    = System.Convert.ToInt32(dbData[4]);
                local.defence   = System.Convert.ToInt32(dbData[5]);
                local.propone   = System.Convert.ToInt32(dbData[6]);
                local.proptwo   = System.Convert.ToInt32(dbData[7]);
                local.propthree = System.Convert.ToInt32(dbData[8]);
                xml.addUser(local);
                Application.LoadLevel("Test");
            }
        }
Example #3
0
        void Start()
        {
            string score = PlayerPrefs.GetString("score");
            string money = PlayerPrefs.GetString("money");

            Score.text = score;
            Money.text = money;
            xml        = new XmlPlayerInformation();
            string mode = PlayerPrefs.GetString("temp");

            if (mode.Equals("default"))
            {
                local = xml.selectUser("default");
                if (local == null)
                {
                    local           = new PlayerInfromation();
                    local.name      = "default";
                    local.id        = "default";
                    local.money     = 0.0;
                    local.score     = 0.0;
                    local.level     = 0;
                    local.castle    = 0;
                    local.defence   = 0;
                    local.propone   = 0;
                    local.proptwo   = 0;
                    local.propthree = 0;
                    xml.addUser(local);
                }

                //当前分数
                double curscore = System.Convert.ToDouble(PlayerPrefs.GetString("score"));
                //当前钱数
                double curmoney = System.Convert.ToDouble(PlayerPrefs.GetString("money"));
                local.score += curscore;
                local.money += curmoney;
                xml.changePlayer(local);
            }
            else
            {
                string player = PlayerPrefs.GetString("player");
                string id     = player + "id";
                local = xml.selectUser(id);
                string parameter = "";
                if (local == null)
                {
                    parameter += "UserName="******"score"));
                //当前钱数
                double curmoney = System.Convert.ToDouble(PlayerPrefs.GetString("money"));
                local.score += curscore;
                local.money += curmoney;
                xml.changePlayer(local);
                string s         = local.score.ToString();
                string m         = local.money.ToString();
                string level     = local.level.ToString();
                string castle    = local.castle.ToString();
                string defence   = local.defence.ToString();
                string propone   = local.propone.ToString();
                string proptwo   = local.proptwo.ToString();
                string propthree = local.propthree.ToString();
                parameter += "UserName="******"&";
                parameter += "Score=" + s + "&";
                parameter += "Money=" + m + "&";
                parameter += "Level=" + level + "&";
                parameter += "Castle=" + castle + "&";
                parameter += "Defence=" + defence + "&";
                parameter += "Propone=" + propone + "&";
                parameter += "Proptwo=" + proptwo + "&";
                parameter += "Propthree=" + propthree;
                StartCoroutine(subData(subUrl + parameter));
            }
        }
Example #4
0
        void Start()
        {
            xml = new XmlPlayerInformation();
            string mode = PlayerPrefs.GetString("temp");

            if (mode.Equals("default"))
            {
                local = xml.selectUser("default");
                if (local == null)
                {
                    local           = new PlayerInfromation();
                    local.name      = "default";
                    local.id        = "default";
                    local.money     = 0.0;
                    local.score     = 0.0;
                    local.level     = 0;
                    local.castle    = 0;
                    local.defence   = 0;
                    local.propone   = 0;
                    local.proptwo   = 0;
                    local.propthree = 0;
                    xml.addUser(local);
                }
                money.text = local.money.ToString();
                int tag = PlayerPrefs.GetInt("Tag");
                switch (tag)
                {
                case 0:
                    changeCharater(local.level);
                    break;

                case 1:
                    changeCasetle(local.castle);
                    break;

                case 2:
                    changeDefence(local.defence);
                    break;

                case 3:
                    changeOne(local.propone);
                    break;

                case 4:
                    changeTwo(local.proptwo);
                    break;

                case 5:
                    changeThree(local.propthree);
                    break;
                }
            }
            else
            {
                string user = PlayerPrefs.GetString("player");
                string id   = user + "id";
                local = xml.selectUser(id);
                string parameter = "";
                if (local == null)
                {
                    parameter += "UserName="******"Tag");
                switch (tag)
                {
                case 0:
                    changeCharater(local.level);
                    break;

                case 1:
                    changeCasetle(local.castle);
                    break;

                case 2:
                    changeDefence(local.defence);
                    break;

                case 3:
                    changeOne(local.propone);
                    break;

                case 4:
                    changeTwo(local.proptwo);
                    break;

                case 5:
                    changeThree(local.propthree);
                    break;
                }
                string score     = local.score.ToString();
                string m         = local.money.ToString();
                string level     = local.level.ToString();
                string castle    = local.castle.ToString();
                string defence   = local.defence.ToString();
                string propone   = local.propone.ToString();
                string proptwo   = local.proptwo.ToString();
                string propthree = local.propthree.ToString();
                parameter += "UserName="******"&";
                parameter += "Score=" + score + "&";
                parameter += "Money=" + m + "&";
                parameter += "Level=" + level + "&";
                parameter += "Castle=" + castle + "&";
                parameter += "Defence=" + defence + "&";
                parameter += "Propone=" + propone + "&";
                parameter += "Proptwo=" + proptwo + "&";
                parameter += "Propthree=" + propthree;
                StartCoroutine(subData(subUrl + parameter));
            }
        }