Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace first_projekt
- {
- class Message
- {
- private String UserName, Text;
- public Message(String username, String text)
- {
- UserName = username;
- Text = text;
- }
- public void Print()
- {
- Console.WriteLine("{0}:\t{1}", UserName, Text);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Message> history = new List<Message>();
- history.Add(new Message("Jakob", "Hey"));
- history.Add(new Message("Ivy", "Hey, what you want?"));
- history.Add(new Message("Jakob", "Nothing, sister ;p"));
- var Instruction = new Dictionary<String, String>();
- Instruction.Add(@"\exit", "Exit");
- Instruction.Add(@"\clear", "Clear consol");
- Instruction.Add(@"\histori", "Show message histori");
- var Users = new Dictionary<String, String>();
- Users.Add(@"Jakob", "Assassin");
- Users.Add(@"Ivy", "Assassin");
- String username = "";
- bool fl = false;
- while (fl == false)
- {
- Console.WriteLine("Enter '\\login' or '\\registrate'");
- String Text1 = Console.ReadLine().Trim();
- if (Text1 == "\\login")
- {
- Console.Write("Enter your nickname: ");
- string nickname = Console.ReadLine().Trim();
- if (Users.ContainsKey(nickname))
- {
- Console.Write("Enter your password: ");
- string password = Console.ReadLine();
- if (Users.ContainsValue(password))
- {
- username = nickname;
- Console.WriteLine("Hello, {0}", username);
- fl = true;
- continue;
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Wrong password!!\n");
- continue;
- }
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Wrong nickname!!\n");
- continue;
- }
- }
- else
- if (Text1 == "\\registrate")
- {
- Console.Write("Enter your nickname: ");
- string nickname = Console.ReadLine().Trim();
- Console.Write("Enter your password: ");
- string password = Console.ReadLine();
- Users.Add(nickname, password);
- username = nickname;
- Console.WriteLine("Hello, {0}", username);
- fl = true;
- continue;
- }
- else {
- Console.Clear();
- Console.WriteLine("Error!!\n");
- }
- }
- ShowInstructions(Instruction);
- foreach (Message message in history)
- {
- message.Print();
- }
- while (true)
- {
- Console.Write("> ");
- String text = Console.ReadLine().Trim();
- if (text.Length == 0)
- {
- ClearConsoleLines(1);
- continue;
- }
- if (text == "\\exit")
- {
- break;
- }
- if (text == "\\clear")
- {
- Console.Clear();
- continue;
- }
- if (text == "\\histori")
- {
- foreach (Message message in history)
- {
- message.Print();
- }
- continue;
- }
- Message usermessage = new Message(username, text);
- history.Add(usermessage);
- int line = (int)((text.Length + 2) / Console.WindowHeight) + 1;
- ClearConsoleLines(line);
- Console.WriteLine("Sending message. ");
- Thread.Sleep(700);
- ClearConsoleLines(1);
- Console.WriteLine("Sending message.. ");
- Thread.Sleep(700);
- ClearConsoleLines(1);
- Console.WriteLine("Sending message... ");
- Thread.Sleep(700);
- ClearConsoleLines(1);
- usermessage.Print();
- }
- }
- public static void ClearConsoleLines(int Line)
- {
- Console.SetCursorPosition(0, Console.CursorTop - Line);
- Console.Write(new String(' ', Console.WindowWidth*Line));
- Console.SetCursorPosition(0, Console.CursorTop - Line);
- }
- public static void ShowInstructions(Dictionary<String, String> Instructions)
- {
- Console.WriteLine("\nType:\n");
- foreach (KeyValuePair<String, String> instruction in Instructions)
- {
- Console.WriteLine("\t{0} - {1}\n", instruction.Key, instruction.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement