コード例 #1
0
 private void newWord()
 {
     try
     {
         String sentenceNext = "";
         for (int i = 0; i < words.Length; i++)
         {
             if (i == words.Length - 1 && i == currentWord)
             {
                 lblSentenceCurrent.Text = words[i];
             }
             else if (i == words.Length - 1)
             {
                 sentenceNext += words[i];
             }
             else if (i == currentWord)
             {
                 lblSentenceCurrent.Text = words[i];
             }
             else if (i > currentWord)
             {
                 sentenceNext += words[i] + " ";
             }
         }
         lblSentenceNext.Text = sentenceNext;
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "newWord");
     }
 }
コード例 #2
0
 private void txtRacer_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (!txtRacer.Text.Equals(""))
         {
             if (lastChar(txtRacer.Text.ToString()).Equals(' ') && txtRacer.Text.Length - 1 == words[currentWord].Length)
             {
                 spacePressed();
             }
             else if (currentWord == words.Length - 1 && wordControl(txtRacer.Text.Substring(0, txtRacer.Text.Length)) && lastChar(txtRacer.Text.ToString()).Equals(lastChar(words[words.Length - 1])))
             {
                 endGame(true);
             }
             else
             {
                 accuracyControl();
             }
         }
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "txtRacer_TextChanged");
     }
 }
コード例 #3
0
 private void accuracyControl()
 {
     try
     {
         if (txtRacer.Text.Length <= words[currentWord].Length)
         {
             if (txtRacer.Text.Substring(0, txtRacer.Text.Length).Equals(words[currentWord].Substring(0, txtRacer.Text.Length)))
             {
                 errorSafe          = false;
                 txtRacer.BackColor = Color.Green;
             }
             else
             {
                 wrongChar();
             }
         }
         else
         {
             wrongChar();
         }
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "accuracyControl");
     }
 }
コード例 #4
0
 private void restart()
 {
     try
     {
         currentSentence   = new Random().Next(sentences.Count());
         currentWord       = 0;
         raceTimeInSeconds = 0;
         passedSeconds     = 0;
         WPM                   = 0;
         wordCount             = 0;
         accuracy              = 0;
         gainingXP             = 0;
         totalWrongCharacter   = 0;
         totalCharacter        = 0;
         lblWPM.Text           = "0WPM";
         lblRemainingTime.Text = "3 : 00";
         car1.Left             = 0;
         txtRacer.Text         = String.Empty;
         startForm frmStart = new startForm();
         frmStart.ShowDialog();
         txtRacer.Enabled = true;
         txtRacer.Focus();
         timerRace.Enabled = true;
         timerWPM.Enabled  = true;
         errorSafe         = false;
         words             = sentences[currentSentence].Split(' ');
         findTotalCharacter();
         newWord();
         btnBaslat.Visible = false;
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "restart");
     }
 }
コード例 #5
0
 private void goCar()    //Grafik ekrandaki arabanın hareket etmesini sağlayan metod.
 {
     try
     {
         car1.Left = (pnlRace.Size.Width - car1.Size.Width - 3) * wordCount / words.Length;
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "goCar");
     }
 }
コード例 #6
0
 private void findTotalCharacter()
 {
     try
     {
         for (int i = 0; i < words.Length; i++)
         {
             totalCharacter += words[i].ToString().Length;
         }
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "findTotalCharacter");
     }
 }
コード例 #7
0
 private void timerRace_Tick(object sender, EventArgs e)
 {
     try
     {
         raceTimeInSeconds++;
         lblRemainingTime.Text = calculateRemainingTime(raceTimeInSeconds);
         if (raceTimeInSeconds == 180)
         {
             endGame(false);
         }
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "timerRace_Tick");
     }
 }
コード例 #8
0
        private void endGame(Boolean flag)  //Oyun bittiğinde çalışacak kodlar.
        {
            /////////////Oyun bittikten sonra da son kez WPM kontrolü yapılması gerekiyor.

            /*
             * Yazılan kelime sayısı 1 arttırılır.
             * Grafik ekranda arabanın hareket etmesi için goCar metodu çağırılır.
             * timerlar kapatılır.
             * Kullanıcının yazı yazdığı alan temizlenip disable hale getiriliyor.
             * Accuracy değerinin hesablanabilmesi için calculateAccuracy metodu çağırılır ve ekrana bilgiler getirilir.
             */
            try
            {
                if (!flag)
                {
                    accuracy  = 0;
                    gainingXP = 0;
                    WPM       = 0;
                }
                else
                {
                    wordCount++;
                    goCar();
                    calculateAccuracy();
                    calculateXP();
                }
                timerRace.Enabled       = false;
                timerWPM.Enabled        = false;
                txtRacer.Text           = "";
                lblSentenceCurrent.Text = "";
                lblSentenceNext.Text    = "";
                txtRacer.Enabled        = false;
                txtRacer.BackColor      = System.Drawing.SystemColors.Window;
                lastGameForm lastGame = new lastGameForm(WPM, accuracy, gainingXP, flag);
                lastGame.ShowDialog();
                updateXP();
                btnBaslat.Visible = true;
            }
            catch (Exception ex)
            {
                CatchExLinqToApi.myCatchException(ex, "endGame");
            }
        }
コード例 #9
0
 private void spacePressed() //Space tuşu kontrolü.
 {
     /*
      * Space tuşuna basıldığında bu metod çalışır.
      * Yazılan kelimenin doğru olup olmadığı kontrol edilir.
      * Yazılan kelimenin "txtRacer.Text.Length - 1" e kadar olan kısmı alınır ve wordControl fonksiyonuna gönderilir.
      * wordControl metodu true döndürürse, kelimenin doğru olduğu anlaşılır ve correctWord metodu çalıştırılır.
      */
     try
     {
         if (wordControl(txtRacer.Text.Substring(0, txtRacer.Text.Length - 1)))
         {
             correctWord();
         }
     }
     catch (Exception ex)
     {
         CatchExLinqToApi.myCatchException(ex, "spacePressed");
     }
 }
コード例 #10
0
        private void createAcc()
        {
            try
            {
                Boolean _gender;
                if (rbMale.Checked)
                {
                    _gender = true;
                }
                else
                {
                    _gender = false;
                }

                User newUser = new User();
                newUser.UserID           = Guid.NewGuid();
                newUser.UserName         = txtName.Text;
                newUser.UserSurname      = txtSurname.Text;
                newUser.UserGender       = _gender;
                newUser.UserBirthDate    = dateBirthdate.Value;
                newUser.UserNickname     = txtNickname.Text;
                newUser.UserEmail        = txtEmail.Text;
                newUser.UserPassword     = txtPassword.Text;
                newUser.UserCreationDate = DateTime.Now;

                int result = ApiCreateUser.pyCreateUser(newUser);
                if (result == 1)
                {
                    MessageBox.Show("Account created. You can Login now.");
                    this.Dispose();
                }
                else
                {
                    MessageBox.Show("Please try again!");
                }
            }
            catch (Exception ex)
            {
                CatchExLinqToApi.myCatchException(ex, "createAcc");
            }
        }
コード例 #11
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                pyApiLogin ApiLogin  = new pyApiLogin();
                User       existUser = ApiLogin.pyLogin(txtEmail.Text, txtPassword.Text);

                if (existUser != null)
                {
                    menuForm menu = new menuForm(existUser, findUserDetails(existUser), findUserInfo(existUser));
                    menu.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("Username or password is incorrect. Please check and try again.");
                }
            }
            catch (Exception ex)
            {
                CatchExLinqToApi.myCatchException(ex, "btnLogin_Click");
            }
        }