Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace BlackJack
  8. {
  9. class GameData
  10. {
  11. private const string dPath = "c:\\CP2BlackJack";
  12.  
  13. public string userName { get; set; }
  14.  
  15. //Determine if game directory exist - create if needed
  16. public void CheckGameDirectory()
  17. {
  18. //This will happen the first time the program runs
  19. if (!Directory.Exists(dPath))
  20. Directory.CreateDirectory(dPath);
  21.  
  22. }//end of CheckGameDirectory()
  23.  
  24. //Determine if User's directory exists - create if needed
  25. //Directories should be userName's
  26. public string CheckPlayerDirectory()
  27. {
  28. this.CheckGameDirectory();
  29. Console.WriteLine("Enter Username Here");
  30. userName = Console.ReadLine();
  31.  
  32. //This will happen everytime the player logs into play
  33. if (!Directory.Exists(dPath + "\\" + userName))
  34. {
  35. Console.WriteLine("This aappears to be your first login");
  36. Console.WriteLine("If this is true type yes");
  37. string responce = Console.ReadLine().ToLower();
  38. if (responce.Equals("yes"))
  39. Setup(dPath, userName);
  40. else
  41. {
  42. Console.WriteLine("There was an error - please restart program.");
  43. Console.ReadLine();
  44. Environment.Exit(0);
  45. }
  46. }
  47. else
  48. Login("c:\\CP2BlackJack\\" + userName + "\\Login.txt", userName);
  49.  
  50. return userName;
  51. }//End of Directory()
  52.  
  53. //Determine if file exists - create if needed
  54. public void CheckFile(string fPath, string fName)
  55. {
  56. if (!File.Exists(fPath + fName))
  57. {
  58. File.Create(fPath + fName).Close();
  59. }
  60. }//End of CheckFile()
  61. //Setup Directories and files
  62.  
  63. public void Setup(string dPath, string userName)
  64. {
  65. Directory.CreateDirectory(dPath + "\\" + userName);
  66. String fileName = dPath + "\\" + userName + "\\" + "Login.txt";
  67. File.Create(fileName).Close();
  68.  
  69. FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None);
  70. StreamWriter sw = new StreamWriter();
  71. sw.WriteLine("userName:" + strPassword);
  72. sw.Close();
  73. fs.Close();
  74.  
  75. fileName = dPath + "\\" + userName + "\\" + "Data.txt";
  76. File.Create(fileName).Close();
  77. }
  78.  
  79. public void Login(string fPath, string userName)
  80. {
  81. string temp = null;
  82. string storedPassword = null;
  83.  
  84. FileStream fs = new FileStream(fPath, FileMode.Open, FileAccess.Read, FileShare.None);
  85. StreamReader sr = new StreamReader();
  86.  
  87. temp = sr.ReadToEnd();
  88. sr.Close();
  89. fs.Close();
  90.  
  91. int startHere = temp.IndexOf("password:") + 9;
  92. storedPassword = (temp.Substring(startHere).Trim());
  93.  
  94. Console.WriteLine("Enter your password");
  95. string inputPassword = Console.ReadLine().Trim();
  96.  
  97. if (storedPassword.Equals(inputPassword))
  98. Console.WriteLine("Password matches \nPress Enter to Continue");
  99. else
  100. Console.WriteLine("No match - stored Password is " + storedPassword + " input Password is " + inputPassword);
  101.  
  102. Console.ReadLine();
  103.  
  104. }
  105.  
  106. public void UpdateData(string fileName, string userName, string data)
  107. {
  108. FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None);
  109. StreamWriter sw = new StreamWriter(fs);
  110. sw.WriteLine(data);
  111. sw.Close();
  112. fs.Close();
  113. }
  114.  
  115. public void ReadData()
  116. {
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement