Advertisement
Guest User

Untitled

a guest
Jan 28th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace first_projekt
  9. {
  10. class Message
  11. {
  12. private String UserName, Text;
  13.  
  14. public Message(String username, String text)
  15. {
  16. UserName = username;
  17. Text = text;
  18. }
  19.  
  20. public void Print()
  21. {
  22. Console.WriteLine("{0}:\t{1}", UserName, Text);
  23. }
  24. }
  25.  
  26. class Program
  27. {
  28. static void Main(string[] args)
  29. {
  30. List<Message> history = new List<Message>();
  31. history.Add(new Message("Jakob", "Hey"));
  32. history.Add(new Message("Ivy", "Hey, what you want?"));
  33. history.Add(new Message("Jakob", "Nothing, sister ;p"));
  34.  
  35. var Instruction = new Dictionary<String, String>();
  36. Instruction.Add(@"\exit", "Exit");
  37. Instruction.Add(@"\clear", "Clear consol");
  38. Instruction.Add(@"\histori", "Show message histori");
  39.  
  40. var Users = new Dictionary<String, String>();
  41. Users.Add(@"Jakob", "Assassin");
  42. Users.Add(@"Ivy", "Assassin");
  43.  
  44. String username = "";
  45.  
  46. bool fl = false;
  47. while (fl == false)
  48. {
  49. Console.WriteLine("Enter '\\login' or '\\registrate'");
  50. String Text1 = Console.ReadLine().Trim();
  51.  
  52. if (Text1 == "\\login")
  53. {
  54. Console.Write("Enter your nickname: ");
  55. string nickname = Console.ReadLine().Trim();
  56. if (Users.ContainsKey(nickname))
  57. {
  58. Console.Write("Enter your password: ");
  59. string password = Console.ReadLine();
  60. if (Users.ContainsValue(password))
  61. {
  62. username = nickname;
  63. Console.WriteLine("Hello, {0}", username);
  64. fl = true;
  65. continue;
  66. }
  67. else
  68. {
  69. Console.Clear();
  70. Console.WriteLine("Wrong password!!\n");
  71. continue;
  72. }
  73. }
  74. else
  75. {
  76. Console.Clear();
  77. Console.WriteLine("Wrong nickname!!\n");
  78. continue;
  79. }
  80. }
  81. else
  82. if (Text1 == "\\registrate")
  83. {
  84. Console.Write("Enter your nickname: ");
  85. string nickname = Console.ReadLine().Trim();
  86. Console.Write("Enter your password: ");
  87. string password = Console.ReadLine();
  88. Users.Add(nickname, password);
  89. username = nickname;
  90. Console.WriteLine("Hello, {0}", username);
  91. fl = true;
  92. continue;
  93. }
  94. else {
  95. Console.Clear();
  96. Console.WriteLine("Error!!\n");
  97. }
  98. }
  99.  
  100. ShowInstructions(Instruction);
  101.  
  102. foreach (Message message in history)
  103. {
  104. message.Print();
  105. }
  106. while (true)
  107. {
  108. Console.Write("> ");
  109. String text = Console.ReadLine().Trim();
  110.  
  111. if (text.Length == 0)
  112. {
  113. ClearConsoleLines(1);
  114. continue;
  115. }
  116.  
  117. if (text == "\\exit")
  118. {
  119. break;
  120. }
  121.  
  122. if (text == "\\clear")
  123. {
  124. Console.Clear();
  125. continue;
  126. }
  127.  
  128. if (text == "\\histori")
  129. {
  130. foreach (Message message in history)
  131. {
  132. message.Print();
  133. }
  134. continue;
  135. }
  136.  
  137. Message usermessage = new Message(username, text);
  138. history.Add(usermessage);
  139.  
  140. int line = (int)((text.Length + 2) / Console.WindowHeight) + 1;
  141. ClearConsoleLines(line);
  142. Console.WriteLine("Sending message. ");
  143. Thread.Sleep(700);
  144. ClearConsoleLines(1);
  145. Console.WriteLine("Sending message.. ");
  146. Thread.Sleep(700);
  147. ClearConsoleLines(1);
  148. Console.WriteLine("Sending message... ");
  149. Thread.Sleep(700);
  150. ClearConsoleLines(1);
  151. usermessage.Print();
  152. }
  153. }
  154.  
  155. public static void ClearConsoleLines(int Line)
  156. {
  157. Console.SetCursorPosition(0, Console.CursorTop - Line);
  158. Console.Write(new String(' ', Console.WindowWidth*Line));
  159. Console.SetCursorPosition(0, Console.CursorTop - Line);
  160. }
  161.  
  162. public static void ShowInstructions(Dictionary<String, String> Instructions)
  163. {
  164. Console.WriteLine("\nType:\n");
  165. foreach (KeyValuePair<String, String> instruction in Instructions)
  166. {
  167. Console.WriteLine("\t{0} - {1}\n", instruction.Key, instruction.Value);
  168. }
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement