Gabriel Barg

Gabriel Barg

  • NA
  • 14
  • 939

Slowing down a picturebox movement

Jun 1 2019 1:24 AM
This is the code: 
 
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Timers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Collections;
using System.Globalization;
using System.Resources;
namespace Move_the_Block_Project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
A_Down.BringToFront();
A_Up.BringToFront();
A_Right.BringToFront();
A_Left.BringToFront();
}
public int SelectRandom (string type)
{
Random random = new Random();
int a = 0;
if (type == "A")
{
a = random.Next(0, 4);
}
if (type == "L")
{
a = random.Next(68, 358);
}
if (type == "M")
{
a = random.Next(1,2);
}
return a;
}
private void Start_B_Click(object sender, EventArgs e)
{
Moving.Interval = 500;
Moving.Start();
}
public PictureBox A_List(string type)
{
List<PictureBox> Arrows = new List<PictureBox>(3);
Arrows.Add(A_Up);
Arrows.Add(A_Right);
Arrows.Add(A_Left);
Arrows.Add(A_Down);
int save, n = SelectRandom(type);
save = n;
if (type == "save")
{
return Arrows[save];
}
else
{
return Arrows[n];
}
}
private void Moving_Tick(object sender, EventArgs e)
{
string type = "A";
PictureBox Arrow_S = A_List(type);
bool Flag = true;
Point End_P = new Point(Arrow_S.Location.X, 420);
while (Flag)
{
type = "M";
Arrow_S.Location = new Point(Arrow_S.Location.X, Arrow_S.Location.Y + SelectRandom(type));
Flag = go(Arrow_S.Location);
if (End_P == Arrow_S.Location)
{
Arrow_S.Location = new Point(Arrow_S.Location.X, 68);
break;
}
}
}
public bool go (Point L)
{
string type = "Y";
bool Flag;
Point a = new Point (L.X, SelectRandom(type));
if (L.Y == a.Y)
{
Flag = false;
}
else
{
Flag = true;
}
return Flag ;
}
private void Stop_Click(object sender, EventArgs e)
{
Moving.Stop();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
string type = "save";
PictureBox Arrow_S = A_List(type);
if (e.KeyChar == 119)
{
if (B_A_Up.Location.Y -112 <= A_Up.Location.Y && B_A_Up.Location.Y >= A_Up.Location.Y)
{
Display.BackColor = Color.LightGreen;
}
else
{
Display.BackColor = Color.Red;
}
}
if (e.KeyChar == 115)
{
if (B_A_Down.Location.Y -112 <= A_Down.Location.Y && B_A_Down.Location.Y >= A_Down.Location.Y)
{
Display.BackColor = Color.LightGreen;
}
else
{
Display.BackColor = Color.Red;
}
}
if (e.KeyChar == 097)
{
if (B_A_Left.Location.Y-112 <= A_Left.Location.Y && B_A_Left.Location.Y >= A_Left.Location.Y)
{
Display.BackColor = Color.LightGreen;
}
else
{
Display.BackColor = Color.Red;
}
}
if (e.KeyChar == 100)
{
if (B_A_Right.Location.Y -112 <= A_Right.Location.Y && B_A_Right.Location.Y >= A_Right.Location.Y)
{
Display.BackColor = Color.LightGreen;
}
else
{
Display.BackColor = Color.Red;
}
}
}
private void Restart_B_Click(object sender, EventArgs e)
{
Moving.Stop();
Display.BackColor = Color.Transparent;
}
}
}
 

Answers (4)