AlexRaynor

Untitled

Oct 16th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Task
  5. {
  6.     class Program
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             int obj1x = 5;
  11.             int obj1y = 5;
  12.             bool isalive1 = true;
  13.             int obj2x = 10;
  14.             int obj2y = 10;
  15.             bool isalive2 = true;
  16.             int obj3x = 15;
  17.             int obj3y = 15;
  18.             bool isalive3 = true;
  19.  
  20.             Random random = new Random();
  21.  
  22.             while (true)
  23.             {
  24.                 if (obj1x == obj2x && obj1y == obj2y)
  25.                 {
  26.                     isalive1 = false;
  27.                     isalive2 = false;
  28.                 }
  29.  
  30.                 if (obj1x == obj3x && obj1y == obj3y)
  31.                 {
  32.                     isalive1 = false;
  33.                     isalive3 = false;
  34.                 }
  35.  
  36.                 if (obj2x == obj3x && obj2y == obj3y)
  37.                 {
  38.                     isalive2 = false;
  39.                     isalive3 = false;
  40.                 }
  41.  
  42.                 obj1x += random.Next(-1, 1);
  43.                 obj1y += random.Next(-1, 1);
  44.  
  45.                 obj2x += random.Next(-1, 1);
  46.                 obj2y += random.Next(-1, 1);
  47.  
  48.                 obj3x += random.Next(-1, 1);
  49.                 obj3y += random.Next(-1, 1);
  50.  
  51.                 if (obj1x < 0)
  52.                     obj1x = 0;
  53.  
  54.                 if (obj1y < 0)
  55.                     obj1y = 0;
  56.  
  57.                 if (obj2x < 0)
  58.                     obj2x = 0;
  59.  
  60.                 if (obj2y < 0)
  61.                     obj2y = 0;
  62.  
  63.                 if (obj3x < 0)
  64.                     obj3x = 0;
  65.  
  66.                 if (obj3y < 0)
  67.                     obj3y = 0;
  68.  
  69.                 if (isalive1)
  70.                 {
  71.                     Console.SetCursorPosition(obj1x, obj1y);
  72.                     Console.Write("1");
  73.                 }
  74.  
  75.                 if (isalive2)
  76.                 {
  77.                     Console.SetCursorPosition(obj2x, obj2y);
  78.                     Console.Write("2");
  79.                 }
  80.  
  81.                 if (isalive3)
  82.                 {
  83.                     Console.SetCursorPosition(obj3x, obj3y);
  84.                     Console.Write("3");
  85.                 }
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment