Exemplo n.º 1
0
 public Game1()
 {
     this.InitializeComponent();
     RankModel = new Common.RankSource();
    
 }
Exemplo n.º 2
0
        /// <summary>
        /// 檢查題目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button1_Click(object sender, RoutedEventArgs e)
        {

            //media.Play();

            //取的使用者輸入的答案
            int ans = Convert.ToInt32(((Button)(sender)).Content);


            if (buttonlock == "open")
            {
                //檢查答案
                if (questions[answers] == ans)//答對
                {
                    answers++;
                    if (answers >= questions.Count)
                    {
                        answers = 0;
                        ClearAnimation();
                        CreateExam();
                        timer_reset();
                    }
                }
                else//答錯
                {
                    //Read Local file
                    var txt = await StorageHelper.ReadTextFromFile("Score.txt");

                    //if local have score.
                    if (!String.IsNullOrEmpty(txt))
                    {
                        RankModel = JsonHelper.Deserizlize<Common.RankSource>(txt);

                        //If score > your local score.
                        if (i - 1 > RankModel.Score)
                        {
                            string Name = await UserInformation.GetDisplayNameAsync();

                            //Save new score to Local.
                            RankModel.Name = Name;
                            RankModel.Score = i - 2;
                            RankModel.Date = DateTime.Now;
                            await StorageHelper.SaveTextToFile
                            ("Score.txt", JsonHelper.Serialize<Common.RankSource>(RankModel));

                            //Check have 50 topic Insert to Db.
                            RankModel.Id = 0;
                            await todoTable.InsertAsync(RankModel);

                        }
                    }
                    else//If local is null
                    {
                        string Name = await UserInformation.GetDisplayNameAsync();

                        //Save score to local
                        RankModel.Name = Name;
                        RankModel.Score = i - 1;
                        RankModel.Date = DateTime.Now;
                        await StorageHelper.SaveTextToFile
                        ("Score.txt", JsonHelper.Serialize<Common.RankSource>(RankModel));
                        await todoTable.InsertAsync(RankModel);
                        //Check have 50 topi Insert to Db
                    }
                    timer_reset();
                    await new MessageDialog("嗚嗚~答錯了 :)", "過" + (i - 1) + "關").ShowAsync();
                    ResetGame();




                }

            }


        }