Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace BlackJack
- {
- class GameData
- {
- private const string dPath = "c:\\CP2BlackJack";
- public string userName { get; set; }
- //Determine if game directory exist - create if needed
- public void CheckGameDirectory()
- {
- //This will happen the first time the program runs
- if (!Directory.Exists(dPath))
- Directory.CreateDirectory(dPath);
- }//end of CheckGameDirectory()
- //Determine if User's directory exists - create if needed
- //Directories should be userName's
- public string CheckPlayerDirectory()
- {
- this.CheckGameDirectory();
- Console.WriteLine("Enter Username Here");
- userName = Console.ReadLine();
- //This will happen everytime the player logs into play
- if (!Directory.Exists(dPath + "\\" + userName))
- {
- Console.WriteLine("This aappears to be your first login");
- Console.WriteLine("If this is true type yes");
- string responce = Console.ReadLine().ToLower();
- if (responce.Equals("yes"))
- Setup(dPath, userName);
- else
- {
- Console.WriteLine("There was an error - please restart program.");
- Console.ReadLine();
- Environment.Exit(0);
- }
- }
- else
- Login("c:\\CP2BlackJack\\" + userName + "\\Login.txt", userName);
- return userName;
- }//End of Directory()
- //Determine if file exists - create if needed
- public void CheckFile(string fPath, string fName)
- {
- if (!File.Exists(fPath + fName))
- {
- File.Create(fPath + fName).Close();
- }
- }//End of CheckFile()
- //Setup Directories and files
- public void Setup(string dPath, string userName)
- {
- Directory.CreateDirectory(dPath + "\\" + userName);
- String fileName = dPath + "\\" + userName + "\\" + "Login.txt";
- File.Create(fileName).Close();
- FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None);
- StreamWriter sw = new StreamWriter();
- sw.WriteLine("userName:" + strPassword);
- sw.Close();
- fs.Close();
- fileName = dPath + "\\" + userName + "\\" + "Data.txt";
- File.Create(fileName).Close();
- }
- public void Login(string fPath, string userName)
- {
- string temp = null;
- string storedPassword = null;
- FileStream fs = new FileStream(fPath, FileMode.Open, FileAccess.Read, FileShare.None);
- StreamReader sr = new StreamReader();
- temp = sr.ReadToEnd();
- sr.Close();
- fs.Close();
- int startHere = temp.IndexOf("password:") + 9;
- storedPassword = (temp.Substring(startHere).Trim());
- Console.WriteLine("Enter your password");
- string inputPassword = Console.ReadLine().Trim();
- if (storedPassword.Equals(inputPassword))
- Console.WriteLine("Password matches \nPress Enter to Continue");
- else
- Console.WriteLine("No match - stored Password is " + storedPassword + " input Password is " + inputPassword);
- Console.ReadLine();
- }
- public void UpdateData(string fileName, string userName, string data)
- {
- FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None);
- StreamWriter sw = new StreamWriter(fs);
- sw.WriteLine(data);
- sw.Close();
- fs.Close();
- }
- public void ReadData()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement