Exemple #1
0
		/// <summary>
		///  Метод удаляющий каждого второго чловека в кругу.
		/// </summary>
		public void Count()
		{
			while (n > 0)
			{
				current = current.next.next;

				current = current.previous;
				current.next.next.previous = current;
				current.next = current.next.next;
				n--;
			}
		}
Exemple #2
0
 /// <summary>
 ///  Метод удаляющй каждого второго чловека в кругу.
 /// </summary>
 public void Count(int n)
 {
     current = first;
     Print(n);
     int k = n;
     
     for (int i = 1; i < n; i++)
     {
             current.next = current.next.next;
             current = current.next;
             k--;
             Print(k);
     }
 }
        static void Main(string[] args)
        {
            var timer =new Timer(2);
            var personArtem = new Person(15, "Artem", "Pupkin");
            var personDima = new Person(16, "Dima", "Vasin");
            var animal = new Animal(timer, "Sharik");

            personDima.Register(timer);
            personArtem.Register(timer);
            timer.SimulateTimeRing("Wake up");
            personArtem.UnRegister(timer);

            timer.SimulateTimeRing("Wake up");
            Console.ReadKey();
        }
Exemple #4
0
		/// <summary>
		///  который создаёт список людей в кругу 
		/// и делает его циклическим.
		/// </summary>
		public People(int n)
		{
			this.n = n;
			current = new Person(1);
			Person p = current;
			for (int i = 1; i < n; i++)
			{
				p.next = new Person(i + 1);
				p.next.previous = p;
				p = p.next;
			}
			p.next = current;
			current.previous = p;
			current = current.previous;
		}
Exemple #5
0
 /// <summary>
 ///  который создаёт список людей в кругу 
 /// и делает его циклическим.
 /// </summary>
 public void PeopleAdd(int n)
 {
     if (first == null)
     {
         first = new Person(n);
         last = first;
     }
     else
     {
         last.next = new Person(n);
         last.next.previous = last;
         last = last.next;
         last.next = first;
         first.previous = last;
     }
     Print(n);
 }
        private static void Main(string[] args)
        {
            var p1 = new Person()
            {
                FirstName = "Alex",
                LastName = "Ivanov"
            };

            var p2 = new Person()
            {
                FirstName = "Alex",
                LastName = "Ivanov"
            };

            Console.WriteLine(p1.Equals(p2)); // true
            Console.WriteLine(p1 == p2); // true

            Console.ReadLine();
        }
Exemple #7
0
 public People()
 {
     first = null;
     last = null;
 }
        static void Main(string[] args)
        {
            bool flag = true;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Let's play rock, paper, scissors");
            Console.WriteLine("Enter player name: ");
            string playerNickName;

            while (true)
            {
                playerNickName = Console.ReadLine();
                if (String.IsNullOrEmpty(playerNickName))
                {
                    Console.WriteLine("Try again, there must be a player nickname to play !\nEnter a nickname:");
                    flag = false;
                }
                else
                {
                    flag = true;
                    break;
                }
            }
            Person   player   = new Person(playerNickName);
            Computer computer = new Computer();

            while (flag)
            {
                try
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Enter one of the numbers in the menu:");
                    Console.WriteLine("1) Play   2) Stats   3) Exit");
                    bool success = int.TryParse(Console.ReadLine(), out int choice);

                    if (!success)
                    {
                        throw new Exception("Invalid input !");
                    }
                    else
                    {
                        if (choice <= 3 && choice >= 1)
                        {
                            if (choice == 1)
                            {
                                Play(player, computer);
                            }
                            else if (choice == 2)
                            {
                                Stats(player, computer);
                            }
                            else
                            {
                                flag = false;
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine("Thank you for playing :)");
                            }
                        }
                        else
                        {
                            throw new Exception("Invalid option chosen !");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("An error has occured.");
                    Console.WriteLine("Try again if you want :)");
                    Console.WriteLine(e.Message);
                }
            }
            Console.ReadLine();
        }
Exemple #9
0
		public Person(int n)
		{
			number = n;
			next = null;
		}