PictureBox pictures;
int Y = 0;
Timer timer1;
int[] P = new int[10];
Random RanInt;
PictureBox PictureRed;
public Form1()
{
InitializeComponent();
RanInt = new Random();
for (int i = 0; i < 10; i++)
{
Y += 22;
pictures = new PictureBox();
pictures.Parent = this;
pictures.BackColor = Color.Black;
pictures.Location = new Point(RanInt.Next(0, Width - 51), Y);
pictures.Width = 50;
pictures.Height = 7;
P[i] = 5;
}
PictureRed = new PictureBox();
PictureRed.Parent = this;
PictureRed.BackColor = Color.Red;
PictureRed.Width = 7;
PictureRed.Height = 7;
PictureRed.Location = new Point(Width / 2 - PictureRed.Width / 2, 22 * 11);
timer1 = new Timer();
timer1.Enabled = true;
timer1.Interval = 1;
timer1.Tick += Game;
timer1.Tick += End;
}
private void Game(object sedner, EventArgs e)
{
var Pictures = Controls.OfType<PictureBox>().ToList();
for (int i = 0; i < 10; i++)
if (Pictures[i].Name != "PictureRed")
{
Pictures[i].Left += P[i];
if (Pictures[i].Left + Pictures[i].Width >= Width) P[i] *= -1;
if (Pictures[i].Left <= 0) P[i] *= -1;
}
}
bool Up = true;
bool Down = true;
bool LeftBool = true;
bool RightBool = true;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Up:
{
if (Up)
{
timer1.Tick += Up2;
Up = false;
}
break;
}
case Keys.Down:
{
if (Down)
{
timer1.Tick += Down2;
Down = false;
}
break;
}
case Keys.Left:
{
if (LeftBool)
{
timer1.Tick += Left2;
LeftBool = false;
}
break;
}
case Keys.Right:
{
if (RightBool)
{
timer1.Tick += Right2;
RightBool = false;
}
break;
}
}
if (e.KeyData == Keys.F5)
if (PictureRed.Top >= 22 * 10)
PictureRed.Location = new Point(Width / 2 - PictureRed.Width / 2, 22 * 11);
if (e.KeyData == Keys.Escape) Close();
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Up:
{
timer1.Tick -= Up2;
Up = true;
break;
}
case Keys.Down:
{
timer1.Tick -= Down2;
Down = true;
break;
}
case Keys.Left:
{
timer1.Tick -= Left2;
LeftBool = true;
break;
}
case Keys.Right:
{
timer1.Tick -= Right2;
RightBool = true;
break;
}
}
}
private void Up2(object sender, EventArgs e)
{
if (PictureRed.Top >= 0) PictureRed.Top -= 1;
}
private void Down2(object sender, EventArgs e)
{
if (PictureRed.Top + PictureRed.Height <= Height) PictureRed.Top += 1;
}
private void Left2(object sender, EventArgs e)
{
if (PictureRed.Left >= 0) PictureRed.Left -= 1;
}
private void Right2(object sender, EventArgs e)
{
if (PictureRed.Left + PictureRed.Width <= Width) PictureRed.Left += 1;
}
bool once = true;
private void End(object sender, EventArgs e)
{
var Pictures = Controls.OfType<PictureBox>().ToList();
for (int i = 0; i < Pictures.Count; i++)
for (int i2 = 0; i2 < Pictures.Count; i2++)
if (i != i2)
if ((Pictures[i].Location.X >= Pictures[i2].Location.X - Pictures[i].Width) &
(Pictures[i].Location.X <= Pictures[i2].Location.X + Pictures[i2].Width) &
(Pictures[i].Location.Y >= Pictures[i2].Location.Y - Pictures[i].Height) &
(Pictures[i].Location.Y <= Pictures[i2].Location.Y + Pictures[i2].Height))
{
PictureRed.Location = new Point(Width / 2 - PictureRed.Width / 2, 22 * 11);
timer1.Tick -= Up2;
timer1.Tick -= Down2;
timer1.Tick -= Left2;
timer1.Tick -= Right2;
}
if (PictureRed.Location.Y <= 0)
if (once == true)
{
once = false;
timer1.Tick -= Up2;
timer1.Tick -= Down2;
timer1.Tick -= Left2;
timer1.Tick -= Right2;
PictureRed.Top = 5;
once = true;
MessageBox.Show("You Win");
}
}
Виртуальный выделенный сервер (VDS) становится отличным выбором
Добрый деньСтолкнулся с проблемой разрабатывая простое сервер - клиент приложение
Всем привет, нужно вернуть все индексы массива через return
В файле html внутри <head> внёс :
Есть форма и кнопка выше нееПри нажатии на кнопку выводятся значения для первого и второго (нулевого и первого) полей - email и username