Advertisement
Guest User

simulation class

a guest
Apr 30th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. public class Tournament
  2. {
  3. public static void Simulation()
  4. {
  5. string path = @"..\\TournamentSimulation\Tournament.txt";
  6. if (!File.Exists(path))
  7. {
  8. //Create a file to write to
  9. using (StreamWriter sw = File.CreateText(path))
  10. {
  11.  
  12. }
  13. }
  14.  
  15. Console.WriteLine("What is the name of the tournament?");
  16. string TournamentName = Console.ReadLine();
  17. Console.WriteLine("When does the tournament start? (mm-dd-yyyy)");
  18. DateTime TournamentStart = Convert.ToDateTime(Console.ReadLine());
  19. Console.WriteLine("When does the tournament end? (mm-dd-yyyy)");
  20. DateTime TournamentEnd = Convert.ToDateTime(Console.ReadLine());
  21. Console.WriteLine("How many players are in the tournament? " +
  22. "Please choose 8, 16, 32 or 64");
  23. int TournamentPlayers = Convert.ToInt32(Console.ReadLine());
  24.  
  25. if (TournamentPlayers == 8 || TournamentPlayers == 16 || TournamentPlayers == 32
  26. || TournamentPlayers == 64)
  27. {
  28. Console.WriteLine("There are {0} players in the tournament and {1} referees"
  29. , TournamentPlayers, TournamentPlayers / 2);
  30. using (StreamWriter sw = File.AppendText(path))
  31. {
  32. sw.WriteLine("Tournament name: " + TournamentName);
  33. sw.WriteLine("Tournament start date: " + TournamentStart);
  34. sw.WriteLine("Tournament end date: " + TournamentEnd);
  35. sw.WriteLine("There are {0} players in the tournament called {1}."
  36. , TournamentPlayers, TournamentName);
  37. sw.WriteLine("There are {0} matches in the first round."
  38. , TournamentPlayers / 2);
  39. sw.WriteLine("There are {0} matches in the second round, " +
  40. "between {1} winners from round 1.", TournamentPlayers / 4, TournamentPlayers / 2);
  41.  
  42. if (TournamentPlayers == 8)
  43. {
  44. sw.WriteLine("There is {0} match in the third round (the final), " +
  45. "between {1} winners from round 2.", TournamentPlayers / 8, TournamentPlayers / 4);
  46. }
  47. else if (TournamentPlayers == 16)
  48. {
  49. sw.WriteLine("There are {0} matches in the third round, " +
  50. "between {1} winners from round 2.", TournamentPlayers / 8, TournamentPlayers / 4);
  51. sw.WriteLine("There is {0} match in the fourth round (the final), " +
  52. "between {1} winners from round 2.", TournamentPlayers / 16, TournamentPlayers / 8);
  53. }
  54. else if (TournamentPlayers == 32)
  55. {
  56. sw.WriteLine("There are {0} matches in the third round, " +
  57. "between {1} winners from round 2.", TournamentPlayers / 8, TournamentPlayers / 4);
  58. sw.WriteLine("There are {0} matches in the fourth round, " +
  59. "between {1} winners from round 2.", TournamentPlayers / 16, TournamentPlayers / 8);
  60. sw.WriteLine("There is {0} match in the fifth round (the final), " +
  61. "between {1} winners from round 2.", TournamentPlayers / 32, TournamentPlayers / 16);
  62. }
  63. else if (TournamentPlayers == 64)
  64. {
  65. sw.WriteLine("There are {0} matches in the third round, " +
  66. "between {1} winners from round 2.", TournamentPlayers / 8, TournamentPlayers / 4);
  67. sw.WriteLine("There are {0} matches in the fourth round, " +
  68. "between {1} winners from round 2.", TournamentPlayers / 16, TournamentPlayers / 8);
  69. sw.WriteLine("There are {0} matches in the fifth round, " +
  70. "between {1} winners from round 2.", TournamentPlayers / 32, TournamentPlayers / 16);
  71. sw.WriteLine("There is {0} match in the sixth round (the final), " +
  72. "between {1} winners from round 2.", TournamentPlayers / 64, TournamentPlayers / 32);
  73. }
  74. sw.WriteLine(" ");
  75. }
  76.  
  77. }
  78.  
  79. else
  80. {
  81. Console.WriteLine("You have to choose 8, 16, 32 or 64 players");
  82. }
  83.  
  84. using (StreamReader sr = File.OpenText(path))
  85. {
  86. string s = "";
  87. while ((s = sr.ReadLine()) != null)
  88. {
  89. Console.WriteLine(s);
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement