Advertisement
stic_t

tanks

Feb 17th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7.  
  8. namespace Tanks
  9. {
  10.     class Tank : IRan, ITurn
  11.     {
  12.         TankImg tankImg = new TankImg();
  13.         private Image img;
  14.  
  15.         static Random random ;
  16.  
  17.         public Tank()
  18.         {
  19.             img = tankImg.Img;
  20.             random = new Random();
  21.             Direct_x = 0;
  22.             Direct_y = 1;
  23.         }
  24.  
  25.         private int y, direct_y;
  26.         private int x, direct_x;
  27.  
  28.         public Image Img
  29.         { get => img; set => img = value; }
  30.         public int X { get => x; set => x = value; }
  31.         public int Y { get => y; set => y = value; }
  32.         public int Direct_x
  33.         { get => direct_x;
  34.  
  35.           set
  36.           {
  37.                 if (direct_x == 0 || direct_x == -1 || direct_x == 1)
  38.                     direct_x = value;
  39.                 else direct_x = 0;
  40.             }
  41.         }
  42.  
  43.         public int Direct_y
  44.         {
  45.             get => direct_y;
  46.  
  47.             set
  48.             {
  49.                 if (direct_y == 0 || direct_y == -1 || direct_y == 1)
  50.                     direct_y = value;
  51.                 else direct_y = 0;
  52.             }
  53.         }
  54.  
  55.         public void Ran()
  56.         {
  57.             x += Direct_x;
  58.             y += Direct_y;
  59.         }
  60.  
  61.         public void Turn()
  62.         {
  63.             if (Math.IEEERemainder(x,40) == 0 && Math.IEEERemainder(y, 40) == 0)
  64.             {
  65.                 if (random.Next(5000) < 2500)
  66.                 {
  67.                     if (Direct_y == 0)
  68.                     {  
  69.                         Direct_x = 0;
  70.                         while (Direct_y == 0)
  71.                         {
  72.                             Direct_y = random.Next(-1, 2);
  73.                         }
  74.                     }
  75.  
  76.                 }
  77.                 else
  78.                 {
  79.                     if (Direct_x == 0)
  80.                     {
  81.                         Direct_y = 0;
  82.                         while (Direct_x == 0)
  83.                         {
  84.                             Direct_x = random.Next(-1, 2);
  85.                         }
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement