private void AccountSystem() { Console.BackgroundColor = ConsoleColor.Black; while (loggedIn == false) { //Console.Clear(); //Console.SetCursorPosition(Console.WindowWidth / 2, //Console.WindowHeight / 3); //string[] intro = { "Welcome to Blackjack!", "Do you want to:", " 1. Login", " 2. Create Account", " 3. Delete Account" }; //Testing_stuff.PrintTextNice(intro); Menu.LoginText(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" Username: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.White; string loginUsername = Console.ReadLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" Password: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Black; string loginPassword = Console.ReadLine(); Console.ResetColor(); switch (SaveSystem.Login(loginUsername, loginPassword)) { case true: _player.Name = SaveSystem.loggedInUser.Username; _player.MoneyPot = SaveSystem.loggedInUser.Money; _player.Points = SaveSystem.loggedInUser.PlayerPoints; _dealer.Points = SaveSystem.loggedInUser.DealerPoints; Menu.LoginText(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Logged in successfully!"); Console.ResetColor(); Thread.Sleep(750); loggedIn = true; break; case false: Thread.Sleep(750); break; } } }
public static bool DeleteUser(string username, string password) { LoadSave(); var blackjackDB = dbClient.GetDatabase(dbName); var usersCol = blackjackDB.GetCollection <BsonDocument>("users"); var filter = Builders <BsonDocument> .Filter.Eq("Username", username); foreach (var existingUser in users) { if (existingUser.Username.ToLower() == username.ToLower() && existingUser.Password == GetHashCode(username.ToLower(), password)) { users.Remove(existingUser); usersCol.DeleteOne(filter); return(true); } else if (existingUser.Username.ToLower() == username.ToLower() && existingUser.Password != GetHashCode(username.ToLower(), password)) { Menu.DeleteAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Wrong password!"); Console.ResetColor(); return(false); } } Menu.DeleteAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Account not found!"); Console.ResetColor(); return(false); }
public static bool Login(string username, string password) { LoadSave(); foreach (var user in users) { if (user.Username.ToLower() == username.ToLower() && user.Password == GetHashCode(username.ToLower(), password)) { loggedInUser = user; return(true); } else if (user.Username.ToLower() == username.ToLower() && user.Password != GetHashCode(username.ToLower(), password)) { Menu.LoginText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Wrong password!"); Console.ResetColor(); return(false); } } Menu.LoginText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Account not found!"); Console.ResetColor(); return(false); }
public static void DeleteAccountText() { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.Clear(); Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(@" ___ ___ _ ___ _____ ___ _ ___ ___ ___ _ _ _ _ _____ "); ConsoleText.CenterText(@" | \| __| | | __|_ _| __| /_\ / __/ __/ _ \| | | | \| |_ _|"); ConsoleText.CenterText(@" | |) | _|| |__| _| | | | _| / _ \ (_| (_| (_) | |_| | .` | | | "); ConsoleText.CenterText(@" |___/|___|____|___| |_| |___| /_/ \_\___\___\___/ \___/|_|\_| |_| "); Console.WriteLine(); Console.WriteLine(); }
public static void LoginText() { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.Clear(); Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(@" _ ___ ___ ___ _ _ "); ConsoleText.CenterText(@" | | / _ \ / __|_ _| \| |"); ConsoleText.CenterText(@" | |_| (_) | (_ || || .` |"); ConsoleText.CenterText(@" |____\___/ \___|___|_|\_|"); Console.WriteLine(); Console.WriteLine(); }
public static void BlackjackText() { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.Clear(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(@" ____ _ _____ _ __ _ _____ _ __ "); ConsoleText.CenterText(@" | _ \| | /\ / ____| |/ / | | /\ / ____| |/ / "); ConsoleText.CenterText(@" | |_) | | / \ | | | ' / | | / \ | | | ' / "); ConsoleText.CenterText(@" | _ <| | / /\ \| | | < _ | |/ /\ \| | | < "); ConsoleText.CenterText(@" | |_) | |____ / ____ \ |____| . \ |__| / ____ \ |____| . \ "); ConsoleText.CenterText(@" |____/|______/_/ \_\_____|_|\_\____/_/ \_\_____|_|\_\ "); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); }
public Menu() { BlackjackText(); Console.ForegroundColor = ConsoleColor.Cyan; ConsoleText.CenterText("Starting game..."); try { SaveSystem.LoadSave(); } catch (Exception e) { BlackjackText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Can't connect to database!"); ConsoleText.CenterText("Check your internet connection and try again."); Console.ReadLine(); Environment.Exit(0); } BlackjackText(); while (selectedOption == false) { switch (menuPos) { case 0: BlackjackText(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" RULES "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" LOGIN "); ConsoleText.CenterText(" "); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" CREATE ACCOUNT "); ConsoleText.CenterText(" "); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" DELETE ACCOUNT "); ConsoleText.CenterText(" "); break; case 1: BlackjackText(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" RULES "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" LOGIN "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" CREATE ACCOUNT "); ConsoleText.CenterText(" "); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" DELETE ACCOUNT "); ConsoleText.CenterText(" "); break; case 2: BlackjackText(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" RULES "); ConsoleText.CenterText(" "); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" LOGIN "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" CREATE ACCOUNT "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" DELETE ACCOUNT "); ConsoleText.CenterText(" "); break; case 3: BlackjackText(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" RULES "); ConsoleText.CenterText(" "); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" LOGIN "); ConsoleText.CenterText(" "); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" CREATE ACCOUNT "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" DELETE ACCOUNT "); ConsoleText.CenterText(" "); break; } switch (Console.ReadKey().Key) { case ConsoleKey.Enter: switch (menuPos) { case 0: #region Rules Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.Clear(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(@" _____ _ _ _ ______ _____ "); ConsoleText.CenterText(@" | __ \| | | | | | ____|/ ____|"); ConsoleText.CenterText(@" | |__) | | | | | | |__ | (___ "); ConsoleText.CenterText(@" | _ /| | | | | | __| \___ \ "); ConsoleText.CenterText(@" | | \ \| |__| | |____| |____ ____) |"); ConsoleText.CenterText(@" |_| \_\\____/|______|______|_____/ "); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText("Black Jack is a cardgame where you are playing against a dealer. The"); ConsoleText.CenterText("goal is to get as near 21 as possible (or over the dealer). The value"); ConsoleText.CenterText("of each numbered card is the value of the number. An ace can for the"); ConsoleText.CenterText("player both have the value 1 and 11. A king, queen and jack does all"); ConsoleText.CenterText("have the value 10. For the dealer every card except ace is worth the"); ConsoleText.CenterText("same. For the dealer, the ace is worth 11."); Console.WriteLine(); ConsoleText.CenterText("When you create an account you start with $300. You start every round"); ConsoleText.CenterText("with betting. If you lose against the dealer, you lose what you have bet."); ConsoleText.CenterText("If you get BlackJack (value 21) you get back three times of what you bet"); ConsoleText.CenterText("in the beginning. If you win over the dealer (have a higher value than"); ConsoleText.CenterText("the dealer) you get back dubble the amount you bet."); Console.WriteLine(); ConsoleText.CenterText("Press any key to return."); Console.ReadKey(); #endregion break; case 1: selectedOption = true; break; case 2: #region CreateAccount CreateAccountText(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" Username: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.White; string createAccountUsername = Console.ReadLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" Password: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Black; string createAccountPasswordFirst = Console.ReadLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" Confirm Password: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Black; string createAccountPassword = Console.ReadLine(); Console.ResetColor(); if (createAccountPasswordFirst != createAccountPassword) { CreateAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Passwords doesn't match. Try again!"); Console.ResetColor(); Thread.Sleep(750); break; } if (Regex.IsMatch(createAccountUsername, @"^[a-zA-Z][a-zA-Z0-9]{2,14}$") == false) { CreateAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("ERROR:"); ConsoleText.CenterText("Username must be 3-15 char long."); ConsoleText.CenterText("Username must start with a letter."); ConsoleText.CenterText("Username can't contain special chars."); Console.WriteLine(); Console.ResetColor(); ConsoleText.CenterText("Press any key to continue."); Console.ReadLine(); break; } if (Regex.IsMatch(createAccountPassword, @"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{5,}$") == false) { CreateAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("ERROR:"); ConsoleText.CenterText("Password must be atleast 6 chars long."); ConsoleText.CenterText("Password should contain atleast one upper case and one lower case."); ConsoleText.CenterText("Password should contain atleast one digit."); ConsoleText.CenterText("Password should contain atleast one special char (#?!@$%^&*-)"); Console.WriteLine(); Console.ResetColor(); ConsoleText.CenterText("Press any key to continue."); Console.ReadLine(); break; } switch (SaveSystem.CreateUser(createAccountUsername, createAccountPassword)) { case true: CreateAccountText(); Console.ForegroundColor = ConsoleColor.Green; ConsoleText.CenterText("Account created!"); Console.ResetColor(); Thread.Sleep(750); break; case false: CreateAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Username is already taken!"); Console.ResetColor(); Thread.Sleep(750); break; } #endregion break; case 3: #region DeleteAccount DeleteAccountText(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" Username: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.White; string deleteAccountUsername = Console.ReadLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" Password: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Black; string deleteAccountPassword = Console.ReadLine(); Console.ResetColor(); switch (SaveSystem.DeleteUser(deleteAccountUsername, deleteAccountPassword)) { case true: DeleteAccountText(); Console.ForegroundColor = ConsoleColor.Green; ConsoleText.CenterText("Account deleted successfully!"); Console.ResetColor(); Thread.Sleep(750); break; case false: Thread.Sleep(750); break; } #endregion break; } break; case ConsoleKey.DownArrow: if (menuPos < 3) { menuPos++; } break; case ConsoleKey.UpArrow: if (menuPos > 0) { menuPos--; } break; } } if (menuPos == 1) { new Game(); } }
public Menu() { BlackjackText(); Console.ForegroundColor = ConsoleColor.Cyan; ConsoleText.CenterText("Starting game..."); try { SaveSystem.LoadSave(); } catch (Exception e) { BlackjackText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Can't connect to database!"); ConsoleText.CenterText("Check your internet connection and try again."); Console.ReadLine(); Environment.Exit(0); } BlackjackText(); while (selectedOption == false) { switch (menuPos) { case 0: BlackjackText(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" LOGIN "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" CREATE ACCOUNT "); ConsoleText.CenterText(" "); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" DELETE ACCOUNT "); ConsoleText.CenterText(" "); break; case 1: BlackjackText(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" LOGIN "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" CREATE ACCOUNT "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" DELETE ACCOUNT "); ConsoleText.CenterText(" "); break; case 2: BlackjackText(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" LOGIN "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" CREATE ACCOUNT "); ConsoleText.CenterText(" "); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" DELETE ACCOUNT "); ConsoleText.CenterText(" "); break; } switch (Console.ReadKey().Key) { case ConsoleKey.Enter: switch (menuPos) { case 0: selectedOption = true; break; case 1: #region CreateAccount CreateAccountText(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" Username: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.White; string createAccountUsername = Console.ReadLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" Password: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Black; string createAccountPasswordFirst = Console.ReadLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" Confirm Password: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Black; string createAccountPassword = Console.ReadLine(); Console.ResetColor(); if (createAccountPasswordFirst != createAccountPassword) { CreateAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Passwords doesn't match. Try again!"); Console.ResetColor(); Console.ReadLine(); break; } switch (SaveSystem.CreateUser(createAccountUsername, createAccountPassword)) { case true: CreateAccountText(); Console.ForegroundColor = ConsoleColor.Green; ConsoleText.CenterText("Account created!"); Console.ResetColor(); Thread.Sleep(750); break; case false: CreateAccountText(); Console.ForegroundColor = ConsoleColor.Red; ConsoleText.CenterText("Username is already taken!"); Console.ResetColor(); Thread.Sleep(750); break; } #endregion break; case 2: #region DeleteAccount DeleteAccountText(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleText.CenterText(" "); ConsoleText.CenterText(" Username: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.White; string deleteAccountUsername = Console.ReadLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine(); ConsoleText.CenterText(" "); ConsoleText.CenterText(" Password: "******" "); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition((Console.WindowWidth - 9) / 2, Console.CursorTop); Console.ForegroundColor = ConsoleColor.Black; string deleteAccountPassword = Console.ReadLine(); Console.ResetColor(); switch (SaveSystem.DeleteUser(deleteAccountUsername, deleteAccountPassword)) { case true: DeleteAccountText(); Console.ForegroundColor = ConsoleColor.Green; ConsoleText.CenterText("Account deleted successfully!"); Console.ResetColor(); Thread.Sleep(750); break; case false: Thread.Sleep(750); break; } #endregion break; } break; case ConsoleKey.DownArrow: if (menuPos < 2) { menuPos++; } break; case ConsoleKey.UpArrow: if (menuPos > 0) { menuPos--; } break; } } if (menuPos == 0) { new Game(); } }