Exemplo n.º 1
0
    public void addRecord(string w, float error)
    {
        print("save score:" + Word.getScore(error));
        database.addRecord(new writeRecord(w, Word.getScore(error), database.getTime()));

        if (_wordRecord != null)
        {
            foreach (wordRecord word in _wordRecord)
            {
                if (word.word == w)
                {
                    word.addRecord(Word.getScore(error), database.getTime());
                    print(word.records.Count);
                    return;
                }
            }
            wordRecord wr = new wordRecord(w);
            wr.addRecord(Word.getScore(error), database.getTime());

            wordRecord[] nRecords = new wordRecord[_wordRecord.Length + 1];
            _wordRecord.CopyTo(nRecords, 0);
            nRecords[_wordRecord.Length] = wr;
            _wordRecord = nRecords;
        }
    }
Exemplo n.º 2
0
    public wordRecord getOrderedRecords(string r, int limit)
    {
        if (r == null)
        {
            return(null);
        }

        string query = "SELECT * FROM history WHERE word='" + r + "' ORDER BY time DESC";

        if (limit != 0)
        {
            query += " LIMIT " + limit;
        }

        try {
            dbcmd             = dbcon.CreateCommand();
            dbcmd.CommandText = query;
            reader            = dbcmd.ExecuteReader();
        } catch (Exception e) {
            Debug.Log(e);
            errMsg = e.ToString();
            return(null);
        }

        wordRecord record = new wordRecord(r);

        while (reader.Read())
        {
            float           score = reader.GetFloat(1);
            System.DateTime time  = (System.DateTime)reader.GetValue(2);
            record.addRecord(score, time);
        }
        return(record);
    }
Exemplo n.º 3
0
 //get 5 latest write records of input word order by time
 public wordRecord getOrderedRecords(Word r)
 {
     if (db != null)
     {
         wordRecord records = db.getOrderedRecords(r.wordName, 5);
         if (records == null)
         {
             description = db.errMsg;
             toggle      = true;
         }
         return(records);
     }
     return(null);
 }
Exemplo n.º 4
0
 //get all write records of input word
 public wordRecord getWordRecords(string w)
 {
     if (db != null)
     {
         wordRecord wrecord = db.getWordRecords(w);
         if (wrecord == null)
         {
             description = db.errMsg;
             toggle      = true;
             return(null);
         }
         return(wrecord);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 5
0
 /*get all write records*/
 public wordRecord[] getRecords()
 {
     if (db != null)
     {
         string[] words = db.getRecordWords();
         if (words == null)
         {
             description = db.errMsg;
             toggle      = true;
             return(null);
         }
         wordRecord[] records = new wordRecord[words.Length];
         for (int i = 0; i < words.Length; i++)
         {
             records[i] = db.getWordRecords(words[i]);
         }
         return(records);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (!loaded)
        {
            if (isRecord() == true)
            {
                Word word = rcd.database.getWord(wordList[recordNow]);
                wordView.texture = word.image;

                wordRecord wrcd = rcd.getRecord(word.wordName);
                avgView.text = "精準度:" + wrcd.avgScore().ToString();

                wrcd             = rcd.database.getOrderedRecords(word);
                recordsView.text = wrcd.records[0].score.ToString("000.00");
                timeView.text    = wrcd.records[0].time.ToString("MM-dd HH:mm");
                int i;
                for (i = 1; i < wrcd.records.Count; i++)
                {
                    recordsView.text += "\n" + wrcd.records[i].score.ToString("000.00");
                    timeView.text    += "\n" + wrcd.records[i].time.ToString("MM-dd HH:mm");
                }
                while (i < 5)
                {
                    recordsView.text += "\n----.--";
                    timeView.text    += "\n-";
                    i++;
                }
            }
            else
            {
                wordView.texture = unknowT;
                avgView.text     = "精準度:0.0";
                recordsView.text = "----.--\n----.--\n----.--\n----.--\n----.--";
                timeView.text    = "-\n-\n-\n-\n-";
            }
        }
        loaded = true;

        //shift
        if (shiftRate != Vector3.zero)
        {
            Vector3 fpos = wordView.transform.position;
            wordView.transform.Translate(shiftRate * Time.deltaTime);
            recordsView.transform.Translate(shiftRate * Time.deltaTime);
            timeView.transform.Translate(shiftRate * Time.deltaTime);
            avgView.transform.Translate(shiftRate * Time.deltaTime);

            if (wordView.transform.position.x > 1 + wordViewNW.x * 0.5)
            {
                loaded = false;
                float delta = -wordViewNW.x - 1;
                wordView.transform.Translate(delta, 0.0f, 0.0f);
                recordsView.transform.Translate(delta, 0.0f, 0.0f);
                timeView.transform.Translate(delta, 0.0f, 0.0f);
                avgView.transform.Translate(delta, 0.0f, 0.0f);
            }
            else if (wordView.transform.position.x < -wordViewNW.x * 0.5f)
            {
                loaded = false;
                float delta = wordViewNW.x + 1;
                wordView.transform.Translate(delta, 0.0f, 0.0f);
                recordsView.transform.Translate(delta, 0.0f, 0.0f);
                timeView.transform.Translate(delta, 0.0f, 0.0f);;
                avgView.transform.Translate(delta, 0.0f, 0.0f);
            }
            //y direction shift
            else
            {
                Vector3 deltaf = fpos - wordViewPos;
                Vector3 deltab = (wordView.transform.position - wordViewPos);
                if (deltaf.x * deltab.x < 0)
                {
                    wordView.transform.position    = wordViewPos;
                    recordsView.transform.position = recordsViewPos;
                    timeView.transform.position    = timeViewPos;
                    avgView.transform.position     = avgViewPos;
                    shiftRate = Vector3.zero;
                }
                //y?
            }
        }

        //input
        if (Input.multiTouchEnabled)        //for multiTouch
        {
            if (isdown)
            {
                if (Input.touchCount < 0)
                {
                    isdown = false;
                }
                else
                {
                    Touch t = Input.GetTouch(0);
                    //finger cross half(0.5) screen width in 0.2 sec than change page
                    if (t.deltaPosition.x / Time.deltaTime > Screen.width * 0.5f / 0.2f)
                    {
                        shiftRight();
                    }
                    else if (t.deltaPosition.x / Time.deltaTime < -Screen.width * 0.5f / 0.2f)
                    {
                        shiftLeft();
                    }
                    else if (t.deltaPosition.y / Time.deltaTime > Screen.width * 0.5f / 0.2f)
                    {
                        shiftUp();
                    }
                    else if (t.deltaPosition.y / Time.deltaTime < -Screen.width * 0.5f / 0.2f)
                    {
                        shiftDown();
                    }
                }
            }
            else if (Input.touchCount > 0 && !istouch)
            {
                isdown  = true;
                istouch = true;
            }

            if (Input.touchCount == 0)
            {
                istouch = false;
                isdown  = false;
            }
        }
        else         //for mouse
        {
            if (isdown)
            {
                Vector2 d = Input.mousePosition - frontPos;
                if (d.x / Time.deltaTime > Screen.width * 0.5f / 0.2f)
                {
                    shiftRight();
                }
                else if (d.x / Time.deltaTime < -Screen.width * 0.5f / 0.2f)
                {
                    shiftLeft();
                }
                else if (d.y / Time.deltaTime > Screen.width * 0.5f / 0.2f)
                {
                    shiftUp();
                }
                else if (d.y / Time.deltaTime < -Screen.width * 0.5f / 0.2f)
                {
                    shiftDown();
                }
                else
                {
                    frontPos = Input.mousePosition;
                }

                if (isdown && Input.GetMouseButtonUp(0))
                {
                    isdown = false;
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    frontPos = Input.mousePosition;
                    isdown   = true;
                }
            }
        }
    }