Advertisement
Guest User

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

a guest
Mar 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Windows.Forms;
  8. using System.Text.RegularExpressions;
  9.  
  10. namespace Dice_Game {
  11. class Program {
  12. public static INIT S; //intialises the INIT class and allows the use of variables within it
  13. static void Main(string[] args) {
  14. GameStart(); //starts the program
  15. }
  16. public static void GameStart() {
  17. S = new INIT();
  18. Functions L = new Functions(); //initialises the Functions class in the form of L which stores all the functions of the game which can be used in the future
  19. L.ImportUsers();
  20. Console.WriteLine("Welcome to the Dice Game! \n The rules are: \n -You write Roll to roll the dice \n -You enter your username \n -If you're playing with 2 players you take it turns rolling. \n \n Write 'Start' to Start the game \n Write 'Register' to register \n Write Leaderboard to view the leaderboard");
  21. //Checks for errors
  22. try {
  23. S.Choice = Console.ReadLine();
  24. }
  25. catch(ArgumentOutOfRangeException) {
  26. MessageBox.Show("Sorry, something broke. Let's try again!", "Error", //outputs error message if the program breaks
  27. MessageBoxButtons.OK, MessageBoxIcon.Error);
  28. GameStart();
  29. }
  30. catch(ArgumentNullException) {
  31. MessageBox.Show("Sorry, something broke. Let's try again!", "Error", //outputs error message if the program breaks
  32. MessageBoxButtons.OK, MessageBoxIcon.Error);
  33. GameStart();
  34. }
  35. if (S.Choice == "Start" || S.Choice == "start") {
  36. L.LoginPrompt();
  37. }
  38. else if (S.Choice == "Register" || S.Choice == "register") {
  39. L.RegisterPrompt();
  40. }
  41. else if (S.Choice == "Leaderboard" || S.Choice == "leaderboard") {
  42. Leadboard G = new Leadboard();
  43. G.ViewLeadBoard();
  44. GameStart();
  45. }
  46. }
  47. }
  48. class Leadboard {
  49. int maxValue = 0;
  50. int Sum;
  51. public void ViewLeadBoard() {
  52. var myFile = File.Create(Program.S.CurrentDirectory + "Temp.txt");
  53. StreamReader sr = new StreamReader(Program.S.CurrentDirectory + "Leaderboard.txt");
  54. string contents = sr.ReadToEnd();
  55. myFile.Close();
  56. sr.Close();
  57.  
  58. TextWriter Tw = new StreamWriter(Program.S.CurrentDirectory + "Temp.txt");
  59. string[] lines = contents.Split( //splits leaderboard per each line
  60. new[] { Environment.NewLine },
  61. StringSplitOptions.None
  62. );
  63. string[] temp = new string[2];
  64. string[,] Strings = new string[lines.Length, 2];
  65. for (int i = 0; i < lines.Length; i++) {
  66. temp = Regex.Split(lines[i], @"\d+"); //split at number
  67. temp[1] = Regex.Match(lines[i], @"\d+").Value;
  68. Strings[i, 0] = temp[0];
  69. Strings[i, 1] = temp[1];
  70. }
  71.  
  72. Console.WriteLine("sick");
  73. while (Sum != -1) {
  74. Sum = 0;
  75. for (int i = 0; i < lines.Length; i++) {
  76. Sum += Convert.ToInt32(Strings[i, 1]);
  77. }
  78. if (Sum == 0) {
  79. Sum = -1;
  80. break;
  81. }
  82. for (int i = 0; i < lines.Length; i++) {
  83. if (Convert.ToInt32(Strings[i, 1]) > Convert.ToInt32(Strings[maxValue, 1])) {
  84. maxValue = i; //Find highest number in array, then proceed to delete the 2 records from array and append them to a string on new line
  85. }
  86. //else if (Convert.ToInt32(Strings[i + 1, 1]) > Convert.ToInt32(Strings[i, 1])) {
  87. // maxValue = i - 1;
  88. //}
  89. }
  90. Tw.Write(System.Environment.NewLine + "{0,-20} {1,20}", Strings[maxValue, 0], Strings[maxValue, 1]);
  91. Strings[maxValue, 1] = "0";
  92. Console.WriteLine(Strings[0, 1]);
  93. Console.WriteLine(Strings[1, 1]);
  94. Console.WriteLine(Strings[2, 1]);
  95. }
  96. Tw.Close();
  97. StreamReader sr2 = new StreamReader(Program.S.CurrentDirectory + "Temp.txt");
  98. contents = sr2.ReadToEnd();
  99. sr2.Close();
  100. File.Delete(Program.S.CurrentDirectory + "Temp.txt");
  101. Console.Clear();
  102. Console.WriteLine("-------------------------------------");
  103. Console.WriteLine("{0,-20} {1,20}", "Username", "Wins");
  104. Console.WriteLine(contents);
  105. Console.WriteLine("-------------------------------------");
  106. Console.WriteLine("");
  107. Console.WriteLine("Press any key to continue");
  108. Console.ReadKey();
  109. Console.Clear();
  110. }
  111. }
  112.  
  113. class INIT { //creates a class which stores all the variables that might change
  114. public string Choice;
  115. public string Choice2;
  116. public string Username;
  117. public string Username2;
  118. public string Password;
  119. public string Password2;
  120. public string NUsername;
  121. public string NPassword;
  122. public string CurrentDirectory;
  123. public string[] Users;
  124. public StreamReader sr;
  125. public TextWriter tw;
  126. public string UserFile;
  127. public string[,] UserPass; //I used a 2 dimensional array because it allows to reference the correct username and password really easily and efficiently
  128. public bool[] LoginAccepted = new bool[2];
  129. public bool AI;
  130. public bool P2;
  131. }
  132. class Functions {
  133. int lineCount;
  134. public void LoginPrompt() { //Prompt for logging the user in
  135. bool Pt2 = false;
  136. void Login2() {
  137. Console.WriteLine("Please enter the login details for the second player \n ----------------------------");
  138. Console.WriteLine("Please Input your username");
  139. try {
  140. Program.S.Username = Console.ReadLine(); //Reads user response and stores it as a password
  141. }
  142. catch (ArgumentOutOfRangeException) {
  143. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  144. MessageBoxButtons.OK, MessageBoxIcon.Error);
  145. }
  146. catch (ArgumentNullException) {
  147. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  148. MessageBoxButtons.OK, MessageBoxIcon.Error);
  149. }
  150. //Password Section
  151. //Asks user for input and catches errors if they exist
  152. Console.WriteLine("Please input your password");
  153. try {
  154. Program.S.Password = Console.ReadLine(); //Reads user response and stores it as a password
  155. }
  156. catch (ArgumentOutOfRangeException) {
  157. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  158. MessageBoxButtons.OK, MessageBoxIcon.Error);
  159. }
  160. catch (ArgumentNullException) {
  161. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  162. MessageBoxButtons.OK, MessageBoxIcon.Error);
  163. }
  164. //
  165. //Code here for checking with the file which I will add in later on
  166. Pt2 = LoginChecker(Program.S.Username, Program.S.Password);
  167. }
  168.  
  169. Console.WriteLine("AI or 2P (2 Player?)");
  170. Game B = new Game();
  171.  
  172. try {
  173. Program.S.Choice2 = Console.ReadLine(); // checks if whatever the user inputs doesn't break it
  174. }
  175. catch (ArgumentOutOfRangeException) {
  176. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  177. MessageBoxButtons.OK, MessageBoxIcon.Error);
  178. }
  179. catch (ArgumentNullException) {
  180. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  181. MessageBoxButtons.OK, MessageBoxIcon.Error);
  182. }
  183. if (Program.S.Choice2 == "AI" || Program.S.Choice2 == "ai") {
  184. //Just continues the program
  185. Program.S.AI = true;
  186. }
  187. else if (Program.S.Choice2 == "2P" || Program.S.Choice2 == "2p") {
  188. Program.S.P2 = true;
  189. Login2();
  190. }
  191. //Username Section
  192. //Asks user for input and catches errors if they exist
  193. Console.WriteLine("Please Input your username");
  194. try {
  195. Program.S.Username2 = Console.ReadLine(); //Reads user response and stores it as a password
  196. }
  197. catch (ArgumentOutOfRangeException) {
  198. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  199. MessageBoxButtons.OK, MessageBoxIcon.Error);
  200. }
  201. catch (ArgumentNullException) {
  202. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  203. MessageBoxButtons.OK, MessageBoxIcon.Error);
  204. }
  205. //Password Section
  206. //Asks user for input and catches errors if they exist within the program
  207. Console.WriteLine("Please input your password");
  208. try {
  209. Program.S.Password2 = Console.ReadLine(); //Reads user response and stores it as a password
  210. }
  211. catch (ArgumentOutOfRangeException) {
  212. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  213. MessageBoxButtons.OK, MessageBoxIcon.Error);
  214. }
  215. catch (ArgumentNullException) {
  216. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  217. MessageBoxButtons.OK, MessageBoxIcon.Error);
  218. }
  219. //
  220. //Code here for checking with the file which I will add in later on
  221. if (Program.S.Username2 == Program.S.Username) {
  222. Console.WriteLine("Players can't both use the same account");
  223. Console.ReadKey();
  224. //Restart program function
  225. }
  226. bool Pt1 = LoginChecker(Program.S.Username2, Program.S.Password2);
  227.  
  228. if (Pt1 == true) {
  229. if (Program.S.AI == true) {
  230. Console.WriteLine("Login succesful");
  231. Console.ReadKey();
  232. B.AIGAME();
  233. Environment.Exit(1);
  234. }
  235. }
  236.  
  237. if (Pt2 == true && Pt1 == true) {
  238. Console.WriteLine("both work");
  239. B.P2GAME();
  240. }
  241.  
  242.  
  243.  
  244. else if (Pt1 == false || Pt2 == false) {
  245. Console.WriteLine("Login Failed");
  246. Console.ReadKey();
  247. }
  248.  
  249.  
  250. //ADD LIMITED LOGIN ALLOWANCES
  251. }
  252.  
  253. public void RegisterPrompt() { //Prompt for Registering the user
  254. //Username Section
  255.  
  256. Console.WriteLine("Please enter your new Username");
  257. try {
  258. Program.S.NUsername = Console.ReadLine(); //Reads user response and stores it as a password
  259. if (Program.S.NUsername.Any(char.IsDigit) == true) {
  260. Console.WriteLine("Sorry, the username cannot contain numbers \n Press any key to try again \n");
  261. Console.ReadKey();
  262. RegisterPrompt();
  263. }
  264. }
  265. catch (ArgumentOutOfRangeException) {
  266. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  267. MessageBoxButtons.OK, MessageBoxIcon.Error);
  268. }
  269. catch (ArgumentNullException) {
  270. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  271. MessageBoxButtons.OK, MessageBoxIcon.Error);
  272. }
  273. if (Program.S.NUsername.Length > 16) { //if the Username the user is trying to register exceeds 16 characters in length this forces the user to restart the registering process
  274. Console.WriteLine("Your username exceeded the 16 character limit, please try again \n");
  275. RegisterPrompt();
  276. }
  277. else if (Program.S.NUsername.Length < 3) { //checks if the username is smaller than 3 characters in length
  278. Console.WriteLine("Your username is too short, the login process will restart \n");
  279. RegisterPrompt();
  280. }
  281.  
  282. //This will check if the username already exists
  283. DoesUserExist();
  284.  
  285. // Password Section
  286.  
  287. Console.WriteLine("Please enter your new password to associate with that username");
  288. try {
  289. Program.S.NPassword = Console.ReadLine(); //Reads user response and stores it as a password
  290. }
  291. catch (ArgumentOutOfRangeException) {
  292. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  293. MessageBoxButtons.OK, MessageBoxIcon.Error);
  294. }
  295. catch (ArgumentNullException) {
  296. MessageBox.Show("Sorry something broke", "Error", //outputs error message if the program breaks
  297. MessageBoxButtons.OK, MessageBoxIcon.Error);
  298. }
  299. if (Program.S.NPassword.Length > 16) { //if the Password the user is trying to register exceeds 16 characters in length this forces the user to restart the registering process
  300. Console.WriteLine("Your Password exceeded the 16 character limit, please try again \n");
  301. RegisterPrompt();
  302. }
  303. else if (Program.S.NPassword.Length < 3) { //checks if the username is smaller than 3 characters in length
  304. Console.WriteLine("Your password is too short, the login process will restart \n");
  305. RegisterPrompt();
  306. }
  307.  
  308.  
  309. //This will add the new details to the list
  310. AddtoList();
  311. Program.GameStart();
  312. }
  313. void AddtoList() { //This method adds the details to the list of existing users
  314. Program.S.tw = new StreamWriter(Program.S.UserFile, true);
  315. Program.S.tw.Write(Environment.NewLine + Program.S.NUsername + "|" + Program.S.NPassword);
  316. Program.S.tw.Close();
  317. }
  318. bool LoginChecker(string Username, string Password) {
  319. for (int y = 0; y < lineCount ; y++) {
  320. if (Username == Program.S.UserPass[y, 0] && Password == Program.S.UserPass[y, 1]) {
  321. return true;
  322. }
  323. }
  324. return false;
  325. }
  326. void DoesUserExist() { //Checks whether the user exists
  327. try {
  328. var regexItem = new Regex("^[a-zA-Z0-9 ]*$");
  329. Program.S.sr = new StreamReader(Program.S.UserFile);
  330. string contents = Program.S.sr.ReadToEnd();
  331. if (contents.Contains(Program.S.NUsername)) {
  332. Console.WriteLine("Sorry this user already exists, please pick another username, \n \n Press any key to continue");
  333. Console.ReadKey();
  334. Console.Clear();
  335. Program.S.sr.Close();
  336. RegisterPrompt();
  337. }
  338.  
  339. else if (Program.S.NUsername.Any(char.IsDigit) || regexItem.IsMatch(Program.S.NUsername)) {
  340. Console.WriteLine("Sorry, the username cannot contain digits or special characters, \n \n Press any key to continue");
  341. Console.ReadKey();
  342. Console.Clear();
  343. RegisterPrompt();
  344. }
  345. Program.S.sr.Close();
  346. }
  347. catch(ArgumentNullException) {
  348. //If no users exist stops the program from crashing
  349. }
  350. Console.WriteLine("Check passed... The user does not exist, press any key to continue");
  351. Console.ReadLine();
  352. }
  353. void SplitPass() { //splits the username and passwords into program friendly and readable format for validation
  354. string[] temp = new string[2];
  355. Program.S.UserPass = new string[lineCount, 2];
  356. for (int i = 0; i < lineCount; i++) {
  357. temp = Program.S.Users[i].Split('|');
  358. Program.S.UserPass[i, 0] = temp[0];
  359. Program.S.UserPass[i, 1] = temp[1];
  360. }
  361. }
  362. public void ImportUsers() { //imports the Username/Password file
  363. Program.S.CurrentDirectory = Directory.GetCurrentDirectory() +"\\"; //Saves the current working directory
  364. Program.S.UserFile = Program.S.CurrentDirectory + "Users.txt";
  365. //when the users files exists
  366. if (File.Exists(Program.S.UserFile) == true) {
  367. //Counts the lines (Each Line is a user)
  368. try {
  369. lineCount = File.ReadLines(Program.S.UserFile).Count();
  370. Program.S.Users = File.ReadAllLines(Program.S.UserFile); //Adds all of the users to the array
  371. Program.S.sr.Close();
  372. }
  373. catch(NullReferenceException) {
  374. //ignores it and doesn't create an array
  375. }
  376. }
  377. //when the users file doesn't exist
  378. else if (File.Exists(Program.S.UserFile) == false) {
  379. File.Create(Program.S.UserFile);
  380. }
  381. try {
  382. SplitPass();
  383. }
  384. catch (ArgumentNullException) {
  385. //If no users exists
  386. }
  387. catch (NullReferenceException) {
  388. //If no users exists
  389. }
  390. }
  391. }
  392. class Game {
  393. Player p1; //initialises the players
  394. Player p2;
  395. int Counter = 0; //resets and initialises the counter
  396. public void AIGAME() {
  397. p1 = new Player() {
  398. Name = Program.S.Username2, //sets player 1's name to player 1 input
  399. Score = 0,
  400. OldScore = 0
  401. };
  402. p2 = new Player() {
  403. Name = "AI", //sets player 2's name to be that of the ai
  404. Score = 0,
  405. OldScore = 0
  406. };
  407. do {
  408. Progresz(false);
  409. } while (Counter < 4);
  410. while (p1.Score == p2.Score) {
  411. Progresz(true);
  412. }
  413. switch (p1.Score > p2.Score) {
  414. case true:
  415. Console.WriteLine(p1.Name + " Has Won!");
  416. Console.ReadKey();
  417. WriteWins(p1.Name);
  418. break;
  419. case false:
  420. Console.WriteLine(p2.Name + " Has Won!");
  421. Console.ReadKey();
  422. break;
  423. }
  424. }
  425. void Progresz(bool Option) {
  426. if (Option == false) {
  427. p1.Score += Roll(false);
  428. if (p1.Score > p1.OldScore) { //Checks if the player rolled an even or odd then displays it as output
  429. Console.WriteLine(p1.Name + " rolled an even, +10 points to " + p1.Name + ", \n " + p1.Name + "'s current score is: " + p1.Score, "\n \n Press any key to continue");
  430. Console.ReadKey();
  431. Console.Clear();
  432. }
  433. else if (p1.Score < p1.OldScore) { //checks if the player score is less than 0
  434. if (p1.Score < 0) {
  435. p1.Score = 0;
  436. }
  437. Console.WriteLine(p1.Name + " rolled an odd, -5 points to " + p1.Name + ", \n " + p1.Name + "'s current score is: " + p1.Score, "\n \n Press any key to continue");
  438. Console.ReadKey();
  439. Console.Clear();
  440. }
  441. p1.OldScore = p1.Score;
  442.  
  443. p2.Score += Roll(false);
  444. if (p2.Score > p2.OldScore) {
  445. Console.WriteLine(p2.Name + " rolled an even, +10 points to " + p2.Name + ", \n" + p2.Name + "'s current score is: " + p2.Score, "\n \n Press any key to continue");
  446. Console.ReadKey();
  447. Console.Clear();
  448. }
  449. else if (p2.Score < p2.OldScore) {
  450. if (p2.Score < 0) {
  451. p2.Score = 0;
  452. }
  453. Console.WriteLine(p2.Name + " rolled an odd, -5 points to " + p2.Name + ", \n" + p2.Name + "'s current score is: " + p2.Score, "\n \n Press any key to continue");
  454. Console.ReadKey();
  455. Console.Clear();
  456. }
  457. p2.OldScore = p2.Score;
  458. Counter++;
  459. }
  460. else if (Option == true) {
  461. p1.Score += Roll(true);
  462. if (p1.Score > p1.OldScore) {
  463. Console.WriteLine(p1.Name + " rolled an even, +10 points to " + p1.Name + ", \n " + p1.Name + "'s current score is: " + p1.Score, "\n \n Press any key to continue");
  464. Console.ReadKey();
  465. Console.Clear();
  466. }
  467. else if (p1.Score < p1.OldScore) {
  468. if (p1.Score < 0) {
  469. p1.Score = 0;
  470. }
  471. Console.WriteLine(p1.Name + " rolled an odd, -5 points to " + p1.Name + ", \n " + p1.Name + "'s current score is: " + p1.Score, "\n \n Press any key to continue");
  472. Console.ReadKey();
  473. Console.Clear();
  474. }
  475. p1.OldScore = p1.Score;
  476.  
  477. p2.Score += Roll(true);
  478. if (p2.Score > p2.OldScore) {
  479. Console.WriteLine(p2.Name + " rolled an even, +10 points to " + p2.Name + ", \n" + p2.Name + "'s current score is: " + p2.Score, "\n \n Press any key to continue");
  480. Console.ReadKey();
  481. Console.Clear();
  482. }
  483. else if (p2.Score < p2.OldScore) {
  484. if (p2.Score < 0) {
  485. p2.Score = 0;
  486. }
  487. Console.WriteLine(p2.Name + " rolled an odd, -5 points to " + p2.Name + ", \n" + p2.Name + "'s current score is: " + p2.Score, "\n \n Press any key to continue");
  488. Console.ReadKey();
  489. Console.Clear();
  490. }
  491. p2.OldScore = p2.Score;
  492. }
  493. }
  494.  
  495. int Roll(bool Option) {
  496.  
  497. Random Big = new Random(); //instantiates the random class
  498. if (Option == false) { //runs only if the loop has been run less than 4 times. i.e does this for the main part of the program
  499. int d = 0;
  500. int a = Big.Next(1, 6); int b = Big.Next(1, 6); //randomises the values of a and b
  501. if (a == b) { //if dice scores are equal, roll once more again
  502. int c = Big.Next(1, 6);
  503. d = a + b + c;
  504. }
  505. else if (a != b) { //If Die scores are not equal, add the scores together
  506. d = a + b;
  507. }
  508. switch (d % 2) { //checks whether the result of the die scores is even
  509. case 0: //if it is, return 10
  510. return 10;
  511. case 1: //if it is not even, return -5
  512. return -5;
  513. }
  514. }
  515. else if (Option == true) { //if the code has been run more than 4 times and the scores of both players are equal, only one die will roll
  516. int a = Big.Next(1, 6);
  517. switch (a % 2) {
  518. case 0:
  519. return 10;
  520. case 1:
  521. return -5;
  522. }
  523. }
  524. return -5;
  525. }
  526. public void P2GAME() { //When the 2 player mode is selected
  527. p1 = new Player() { //defines a player
  528. Name = Program.S.Username2, //stores the player's name as the players username
  529. Score = 0, //sets player's score to 0
  530. OldScore = 0 //sets the old score to 0
  531. };
  532. p2 = new Player() {
  533. Name = Program.S.Username,
  534. Score = 0,
  535. OldScore = 0
  536. };
  537. do { //do while loop, whilst the counter is smaller than 4, continue the dice game
  538. Progresz(false);
  539. } while (Counter < 4);
  540. while (p1.Score == p2.Score) {
  541. Progresz(true);
  542. }
  543. switch (p1.Score > p2.Score) {
  544. case true:
  545. Console.WriteLine(p1.Name + " Has Won!");
  546. Console.ReadKey();
  547. WriteWins(p1.Name);
  548. break;
  549. case false:
  550. Console.WriteLine(p2.Name + " Has Won!");
  551. Console.ReadKey();
  552. WriteWins(p2.Name);
  553. break;
  554. }
  555. }
  556. void WriteWins(string Winner) {
  557. //Reads the contents of leaderboard.txt and if it doesn't exists it creates a new file called leaderboard.txt and writes the winner into it
  558. if (File.Exists(Program.S.CurrentDirectory + "Leaderboard.txt") == true) {
  559. StreamReader sr = new StreamReader(Program.S.CurrentDirectory + "Leaderboard.txt");
  560. string contents = sr.ReadToEnd();
  561. sr.Close();
  562. File.WriteAllText(Program.S.CurrentDirectory + "Leaderboard.txt", string.Empty);
  563. TextWriter Tw = new StreamWriter(Program.S.CurrentDirectory + "Leaderboard.txt", true);
  564. if (contents.Contains(Winner)) {
  565. string[] temp = new string[2];
  566. string[] lines = contents.Split( //splits leaderboard per each line
  567. new[] { Environment.NewLine },
  568. StringSplitOptions.None
  569. );
  570. int resultString = 0;
  571. for (int i = 0; i < lines.Length; i++) {
  572. temp = Regex.Split(lines[i], @"\d+"); //@"(?<=\p{L})(?=\p{N})"
  573. bool match = Regex.IsMatch(temp[0], string.Format(@"\b{0}\b", Regex.Escape(Winner)));
  574. if (match == true) {
  575. resultString = Convert.ToInt32(Regex.Match(lines[i], @"\d+").Value);
  576. resultString++;
  577. lines[i] = Regex.Replace(lines[i], @"\d+", Convert.ToString(resultString));
  578. Tw.Write(lines[0]);
  579. for (int y = 1; y < lines.Length; y++) {
  580.  
  581. Tw.Write(System.Environment.NewLine + lines[y]);
  582. }
  583. Tw.Close();
  584. break;
  585. }
  586.  
  587. }
  588.  
  589. }
  590. else if (File.Exists(Program.S.CurrentDirectory + "Leaderboard.txt") == false) {
  591. File.Create(Program.S.CurrentDirectory + "Leaderboard.txt");
  592. Tw.WriteLine(Winner + "1");
  593. Tw.Close();
  594. }
  595.  
  596. else if (contents.Contains(Winner) == false) {
  597. Tw.WriteLine(Winner + "1");
  598. Tw.Close();
  599. }
  600. }
  601.  
  602. }
  603. }
  604. public class Player {
  605. public string Name;
  606. public int Score;
  607. public int OldScore;
  608. }
  609. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement