Esempio n. 1
0
    public void OnClickedLoginButton()
    {
        if (string.IsNullOrEmpty(UserName.text))
        {
            ShowTip("请输入用户名");
            return;
        }
        if (!string.IsNullOrEmpty(Password.text))
        {
            SqliteDataReader UsernameReader = sql.ReadTable("Game", new string[] { "UserName" }, new string[] { "`" + "UserName" + "`", "`" + "Password" + "`" }, new string[] { "=", "=" }, new string[] { ("'" + UserName.text.ToString() + "'").ToString(), ("'" + Password.text.ToString() + "'").ToString() });

            if (UsernameReader.HasRows)
            {
                ShowTip("登陆成功!!!");
                LoginPanel.SetActive(false);
                RegisterPanel.SetActive(false);
                //关闭数据库连接
                sql.CloseConnection();
                return;
            }
            else
            {
                ShowTip("登陆失败!!!");
                return;
            }
        }
        else
        {
            ShowTip("请输入密码!!!");
            return;
        }

        //关闭数据库连接
        sql.CloseConnection();
    }
Esempio n. 2
0
    public void OnClickedRegisterButton()
    {
        if (string.IsNullOrEmpty(UserName.text))
        {
            ShowTip("请输入用户名");
            return;
        }
        else
        {
            SqliteDataReader UsernameReader = sql.ReadTable("Game", new string[] { "UserName" }, new string[] { "`" + "UserName" + "`" }, new string[] { "=" }, new string[] { ("'" + UserName.text.ToString() + "'").ToString() });

            if (UsernameReader.HasRows)
            {
                ShowTip("用户名已存在!!!");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(Password.text))
                {
                    ShowTip("请输入密码!!!");
                    return;
                }
                else
                {
                    sql.InsertValues("Game", new string[] { ("'" + UserName.text.ToString() + "'").ToString(), ("'" + Password.text.ToString() + "'").ToString(), "6000000", "true", "true", "false", "false", "false", "false", "0" });

                    ShowTip("注册成功!!!");
                }
            }
        }
        //关闭数据库连接
        sql.CloseConnection();
    }
Esempio n. 3
0
        // Update is called once per frame
        void Update()
        {
            transform.Translate(-speed * Time.deltaTime, 0, 0);
            if (transform.position.x < -11)
            {
                Destroy(gameObject);
            }
            timer += Time.deltaTime;
            if (timer >= updateTimer)
            {
                Vector3 position = transform.position;
                //实例化子弹并设置初始位置
                Instantiate(enemyBullet, new Vector3(position.x - 0.8f, position.y, position.z), Quaternion.identity);
                timer = 0;
            }
            if (this.health <= 0)                                                                                                                                                     //敌机生命值小于0时
            {
                Destroy(gameObject);                                                                                                                                                  //飞机爆炸
                Instantiate(boom, transform.position, Quaternion.identity);                                                                                                           //显示敌机爆炸动画
                StartGame.selfPlane.score += score;                                                                                                                                   //得分增加

                Sql = new SqliteHelper("data source=sqlite4unity.db");                                                                                                                //连接数据库
                float Score = StartGame.selfPlane.score;
                Sql.UpdateValues("Game", new string[] { "Score" }, new string[] { ("'" + Score.ToString() + "'").ToString() }, "UserName", "=", ("'" + Login.Name + "'").ToString()); //更新分数
                Sql.CloseConnection();                                                                                                                                                //关闭数据库连接
            }
        }
        public static void CreateDataBaseBySql()
        {
            string tempSqlPath = EditorUtility.OpenFilePanel("Load sql of Directory", Application.dataPath, "sql");

            try
            {
                string       tempSql    = File.ReadAllText(tempSqlPath);
                SqliteHelper tempHelper = new SqliteHelper(DbPath);
                Debug.Log(tempSql);
                tempHelper.ExecuteQuery(tempSql);
                tempHelper.CloseConnection();
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.Message);
            }
        }
Esempio n. 5
0
        //更新数据库
        public void FreshData()
        {
            float Gold;
            float Score;

            SqliteDataReader GoldReader = Sql.ReadTable("Game", new string[] { "Gold" }, new string[] { "UserName" }, new string[] { "=" }, new string[] { ("'" + Login.Name + "'").ToString() });

            SqliteDataReader ScoreReader = Sql.ReadTable("Game", new string[] { "Score" }, new string[] { "UserName" }, new string[] { "=" }, new string[] { ("'" + Login.Name + "'").ToString() });


            Gold  = float.Parse(GoldReader[0].ToString());
            Score = float.Parse(ScoreReader[0].ToString());
            Gold += Score;
            Sql.UpdateValues("Game", new string[] { "Gold" }, new string[] { ("'" + Gold.ToString() + "'").ToString() }, "UserName", "=", ("'" + Login.Name + "'").ToString());

            Sql.CloseConnection();
        }
Esempio n. 6
0
    public void entryGame(GameObject sender)
    {
        Sql = new SqliteHelper("data source=sqlite4unity.db");                                                                                                   //连接数据库
        Sql.UpdateValues("Game", new string[] { "Score" }, new string[] { ("'" + "0" + "'").ToString() }, "UserName", "=", ("'" + Login.Name + "'").ToString()); //将分数置0
        Sql.CloseConnection();                                                                                                                                   //关闭数据库连接

        describedText.text = "";
        menu.SetActive(false);
        modeUI.SetActive(false);
        ChoosePlanes.SetActive(false);
        SingleGame.SetActive(true);
        UICamera.SetActive(true);
        //myPlane.SetActive(true);
        bgMusic.SetActive(true);
        lifebarBG.SetActive(true);
        //lifeBar.SetActive(true);
        pausebtn.SetActive(true);
        pauseUI.SetActive(false);
        WinUI.SetActive(false);
        DefeatUI.SetActive(false);
        //刷新时间和生命值
        GameObject.Find("SingleGame").GetComponent <GameManager>().lifeBar.fillAmount = 1f;
        GameObject.Find("SingleGame").GetComponent <GameManager>().survivalTime       = 0;

        switch (sender.name)
        {
        case "ButtonEasy":
            GameManager.successTime     = 10f;
            EnemyController.updateTimer = 1.5f; //飞机生成频率
            EnemyPlane.updateTimer      = 1.5f; //子弹更新频率
            //GameManager.map = "bg1";
            GameObject.Find("SingleGame").GetComponent <GameManager>().bgImage1.sprite = Resources.Load("bgImage/bg1", typeof(Sprite)) as Sprite;
            GameObject.Find("SingleGame").GetComponent <GameManager>().bgImage2.sprite = Resources.Load("bgImage/bg1", typeof(Sprite)) as Sprite;
            break;

        case "ButtonUsual":
            GameManager.successTime     = 20f;
            EnemyController.updateTimer = 1.0f; //飞机生成频率
            EnemyPlane.updateTimer      = 1.0f; //子弹更新频率
            //GameManager.map = "bg2";
            //加载地图
            GameObject.Find("SingleGame").GetComponent <GameManager>().bgImage1.sprite = Resources.Load("bgImage/bg2", typeof(Sprite)) as Sprite;
            GameObject.Find("SingleGame").GetComponent <GameManager>().bgImage2.sprite = Resources.Load("bgImage/bg2", typeof(Sprite)) as Sprite;
            break;

        case "ButtonHard":
            GameManager.successTime     = 30f;
            EnemyController.updateTimer = 0.5f; //飞机生成频率
            EnemyPlane.updateTimer      = 0.5f; //子弹更新频率
            //GameManager.map = "bg3";
            GameObject.Find("SingleGame").GetComponent <GameManager>().bgImage1.sprite = Resources.Load("bgImage/bg3", typeof(Sprite)) as Sprite;
            GameObject.Find("SingleGame").GetComponent <GameManager>().bgImage2.sprite = Resources.Load("bgImage/bg3", typeof(Sprite)) as Sprite;
            break;

        default:
            break;
        }
        //transform.GetComponent<GameManager>().pauseMenu.SetActive(false);
        Time.timeScale = 1f;
        if (selfPlane == null)
        {
            if (SelectPlane.IsdefaultplaneChosen == true)
            {
                selfPlane = Instantiate(Plane[0], new Vector3(-8f, 0f, 0f), Quaternion.identity);
            }
            else if (SelectPlane.IsheliChosen == true)
            {
                selfPlane = Instantiate(Plane[1], new Vector3(-8f, 0f, 0f), Quaternion.identity);
            }
            else
            {
                selfPlane = Instantiate(Plane[2], new Vector3(-8f, 0f, 0f), Quaternion.identity);
            }
        }
    }
Esempio n. 7
0
 private void ChildPage_Unloaded(object sender, RoutedEventArgs e)
 {
     sqlite.CloseConnection();
 }