Beispiel #1
0
        public ResetPassword(MySqlConnection con)
        {
            while (true)
            {
                Connection = con;

                Console.WriteLine("lets reset your password\nFirst enter your trainer name: ");
                TrainerName = Console.ReadLine();

                string lookupEmailByName = "SELECT email FROM sql3346222.userCredentials WHERE(TrainerName = '" + TrainerName + "');";
                string returnedEmail     = "0";

                Console.WriteLine("Enter the email attached to your account: ");
                EnteredEmail = Console.ReadLine();

                con.Open();
                MySqlCommand    query = new MySqlCommand(lookupEmailByName, con);
                MySqlDataReader rdr   = query.ExecuteReader();

                //reading returned query
                while (rdr.Read())
                {
                    returnedEmail = rdr[0].ToString();
                }
                rdr.Close();
                con.Close();

                //if an email is returned from DB this is skipped
                if (returnedEmail.Length <= 1)
                {
                    string newUser;
                    Console.WriteLine("No email found or user name incorrect!\nPlease try again or create new user");
                    Console.WriteLine("Would you like to make a new account?(y/n)");
                    newUser = Console.ReadLine();
                    while (true)
                    {
                        //Choice if user is new, takes them to create user
                        if (newUser.ToLower().Equals("y"))
                        {
                            var backToMakeNewAccount = new UserAuthAndLogin();
                            break;
                        }

                        //Choice if user enters, N not a new user, prompts login
                        if (newUser.ToLower().Equals("n"))
                        {
                            break;
                        }

                        //if something other than y or n is entered user is prompted with choice again
                        Console.WriteLine("Invalid choice! Please type y or n");
                        Console.WriteLine("Make new account? (y/n)");
                        newUser = Console.ReadLine();
                    }
                }

                while (true)
                {
                    if (returnedEmail == EnteredEmail)
                    {
                        var emailVerificationForReset = new EmailValidation(returnedEmail);
                        if (emailVerificationForReset.EmailIsValid == true)
                        {
                            Console.WriteLine("Lets reset your password...");
                            MakeNewPassword();
                            var backToLogin = new UserAuthAndLogin();
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Emails do not match! Let's try this again");
                        break;
                    }
                }
                break;
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
#if WINDOWS
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            ShowWindow(ThisConsole, MAXIMIZE);
#endif
            var loginStart = new UserAuthAndLogin();
            //Commented this about because the application just started, there won't be much to clean up, and this brings a lot of overhead on call regardless of heap size.
            //One might describe the impact of this function as t(s) = 0.1s^2 + 100; where s is the size of the heap, and t(s) returns the time it takes to GC.
            //Since it's the start of the application, "s" would be very small in this case, but the GC takes 0.1*s^2 + 100 time to clear anyways. That + 100 at the end makes GC's take a long time regardless of heap size.
            //System.GC.Collect(); //Doing this a lot isn't a good idea, I get doing it in loading breaks, but the CLR takes care of this. Regardless, it's also not a huge deal in the console app.
            Trainer CurrentTrainer = new Trainer();
            CurrentTrainer.UserId      = loginStart.UserID;
            CurrentTrainer.TrainerName = loginStart.TrainerName;

            Boolean Win;
            Boolean Exit = false;
            while (Exit == false)
            {
                int WinCounter = 0;
                var Lineup     = new TrainerLineUp(CurrentTrainer.UserId, CurrentTrainer.TrainerName, loginStart.Connection.myConnection);
                if (Lineup.HasLineup == false)
                {
                    Lineup.LoadLineup();
                }

                while (Lineup.LoopStuck == true)
                {
                    Console.WriteLine("Would you like to leave? type 'exit'\nOr press enter to continue");
                    string exitChoice = Console.ReadLine().Trim();

                    if (exitChoice.ToLower().Equals("exit"))
                    {
                        System.Environment.Exit(0);
                    }
                    else
                    {
                        loginStart = new UserAuthAndLogin();
                        System.GC.Collect();
                        CurrentTrainer             = new Trainer();
                        CurrentTrainer.UserId      = loginStart.UserID;
                        CurrentTrainer.TrainerName = loginStart.TrainerName;

                        Lineup = new TrainerLineUp(CurrentTrainer.UserId, CurrentTrainer.TrainerName, loginStart.Connection.myConnection);
                        if (Lineup.HasLineup == false)
                        {
                            Lineup.LoadLineup();
                        }
                    }
                }

                CurrentTrainer = Lineup.GhostTrainer;
                System.GC.Collect();

                //Console.WriteLine("Let's Battle! "); //Derek, my code already includes this.

                for (int j = 5; j > 0; j--)
                {
                    Trainer      EliteTrainer = new Trainer();
                    LoadOpponent EliteLoader  = new LoadOpponent(j, loginStart.Connection.myConnection);

                    EliteTrainer.Pokemon     = EliteLoader.OpponentLineUp;
                    EliteTrainer.TrainerName = EliteLoader.OpponentName;

                    //Game 1 will have dumbest AI at intelligence = 45%, Game 5 at 85% (increments of 10%).
                    Win = GameMockup.GameEngine(CurrentTrainer, EliteTrainer, ((((double)j + 1d) / 10d) + 0.35d));

                    if (Win == false)
                    {
                        ScoreBoard ScoreAndRanking = new ScoreBoard(WinCounter, CurrentTrainer, loginStart.Connection.myConnection);
                        PlayAgain  Again           = new PlayAgain();
                        Exit = !Again.Decsision(); //Again.Decision() returns true if they want to play again, which is notted for whether or not they want to quit.
                        if (Exit)
                        {
                            //The person quit, so it should break the fighting loop. Right? if it starts over on the match they lost on, their pokemon's HP should be restored to the values they were before this match.
                            Console.WriteLine("\n\n\nThanks for playing!");
                            Thread.Sleep(3000);
                            break;
                        }
                        else
                        {
                            //Sets all the pokemanz health back to full and restarts the game from the first of the elite four.
                            CurrentTrainer.Pokemon.ForEach(x => x.ActingHP = x.BaseHP);
                            WinCounter = 0;
                            j          = 6; //It'll be decremented to 5 at the beginning of the loop.
                        }
                    }
                    else
                    {
                        WinCounter++;
                    }
                    System.GC.Collect(); //I think this is appropriate here, as this is when loading happens, and all those json and pokemon objects get cleaned up, freeing lots of memory.
                }
            }
            System.Environment.Exit(0);
        }
        public ResetPassword(MySqlConnection con)
        {
            while (true)
            {
                Connection = con;

                Console.WriteLine("Lets reset your password.\nFirst enter your trainer name: ");
                while (true)
                {
                    TrainerName = Console.ReadLine().Trim();
                    if (!Grand.alphaNumeric.IsMatch(TrainerName))
                    {
                        Console.WriteLine("Trainer names can contain only letters, numbers, and underscores!");
                    }
                    else
                    {
                        break;
                    }
                }
                string lookupEmailByName = "SELECT email FROM sql3346222.userCredentials WHERE(TrainerName = @Username);";
                string returnedEmail     = "0";

                Console.WriteLine("Enter the email attached to your account: ");
                EnteredEmail = Console.ReadLine().Trim();

                con.Open();
                MySqlCommand query = new MySqlCommand(lookupEmailByName, con);
                query.Parameters.Add(@"@Username", MySqlDbType.VarChar);
                query.Parameters[@"@Username"].Value = TrainerName;
                MySqlDataReader rdr = query.ExecuteReader();

                //reading returned query
                while (rdr.Read())
                {
                    returnedEmail = rdr[0].ToString();
                }
                rdr.Close();
                con.Close();

                //if an email is returned from DB this is skipped
                if (returnedEmail.Length <= 1)
                {
                    string newUser;
                    Console.WriteLine("No email found or user name incorrect!\nPlease try again or create new user");
                    Console.WriteLine("Would you like to make a new account? (Y/N)");
                    while (true)
                    {
                        newUser = Console.ReadLine().Trim();
                        //Choice if user is new, takes them to create user
                        if (Grand.yes.IsMatch(newUser))
                        {
                            var backToMakeNewAccount = new UserAuthAndLogin();
                            break;
                        }
                        //Choice if user enters, N not a new user, prompts login
                        else if (Grand.no.IsMatch(newUser))
                        {
                            break;
                        }

                        //if something other than y or n is entered user is prompted with choice again
                        Console.WriteLine("Invalid choice! Please type y or n");
                        Console.WriteLine("Make new account? (Y/N)");
                    }
                }

                while (true)
                {
                    if (returnedEmail == EnteredEmail)
                    {
                        var emailVerificationForReset = new EmailValidation(returnedEmail);
                        if (emailVerificationForReset.EmailIsValid == true)
                        {
                            Console.WriteLine("Lets reset your password...");
                            MakeNewPassword();
                            var backToLogin = new UserAuthAndLogin();
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Emails do not match! Let's try this again");
                        break;
                    }
                }
                break;
            }
        }