Advertisement
RMarK0

Задание Илюхи пинбол

Mar 11th, 2021
1,277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. public partial class DefaultForm : Form
  2.     {
  3.         private int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
  4.         private int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
  5.  
  6.         private bool LeftMove, UpMove;
  7.  
  8.         public DefaultForm()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.  
  13.         private void timer1_Tick(object sender, EventArgs e)
  14.         {
  15.             int speed = 10; // скорость движения окна
  16.  
  17.             if (!LeftMove)
  18.             {
  19.                 Location = new Point(Location.X + speed, Location.Y);
  20.             }
  21.             if (LeftMove)
  22.             {
  23.                 Location = new Point(Location.X - speed, Location.Y);
  24.             }
  25.             if (!UpMove)
  26.             {
  27.                 Location = new Point(Location.X, Location.Y + speed);
  28.             }
  29.             if (UpMove)
  30.             {
  31.                 Location = new Point(Location.X, Location.Y - speed);
  32.             }
  33.  
  34.             if (Location.X <= 0) // если по X уходит за рамки экрана слева
  35.                 LeftMove = false;
  36.             if (Location.X >= screenWidth - Size.Width) // если по X уходит за рамки экрана справа
  37.                 LeftMove = true;
  38.             if (Location.Y <= 0) // если по Y уходит за рамки экрана сверху
  39.                 UpMove = false;
  40.             if (Location.Y >= screenHeight - Size.Height) // если по Y уходит за рамки экрана снизу
  41.                 UpMove = true;
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement