Exemplo n.º 1
0
        private void buttonPLayNewGame_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
            PlayingWindow playingWindow = new PlayingWindow();

            playingWindow.Show();
        }
        private void buttonLogin_Click(object sender, RoutedEventArgs e)
        {
            string line = "";

            if (!(textBoxUsername.Text.Equals("Username") && textBoxPassword.Password.Equals("Password")))
            {
                try
                {
                    StreamReader read  = new StreamReader(@"C:\Users\HP\Documents\Visual Studio 2015\Projects\TicTacToe\TicTacToe\users.txt");    //object to read text file with the name auntheticateUsers.text
                    String       line2 = "";
                    while (!login && (line = read.ReadLine()) != null)
                    {
                        if (line == textBoxUsername.Text)              //check if username exists in text file
                        {
                            line2 = read.ReadLine();
                            if (line2 == textBoxPassword.Password)                                                    //shows login panel
                            {
                                login = true;
                                if (Globals.singlePlay)
                                {
                                    this.Hide();
                                    PlayingWindow playingWindow = new PlayingWindow();
                                    playingWindow.Show();
                                }
                                else
                                {
                                    this.Hide();
                                    if (Globals2.firstTime)
                                    {
                                        if ((Globals2.username1 == line) && (Globals2.password == line2))
                                        {
                                            MessageBox.Show("Trying to login with same user name Twice", "Log In Again!!");
                                            MainWindow mainWindow = new MainWindow();
                                            mainWindow.Show();
                                        }
                                        else
                                        {
                                            PlayingWindow playingWindow = new PlayingWindow();
                                            playingWindow.Show();
                                        }
                                    }
                                    else
                                    {
                                        Globals2.username1 = line;
                                        Globals2.password  = line2;
                                        MainWindow mainWindow = new MainWindow();
                                        mainWindow.Show();
                                        Globals2.firstTime = true;
                                    }
                                }
                            }
                        }
                    }
                    if (line != textBoxUsername.Text || line2 != textBoxPassword.Password)
                    {
                        MessageBox.Show("Aunthetication Error");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error,Can't find file", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else if (textBoxUsername.Text.Equals("Username") || textBoxPassword.Password.Equals("Password"))
            {
                MessageBox.Show("Aunthetication Error");
            }
        }