namespace moraba{public partial class Form1 : Form
{
enum Direction { Up, Down, Right, Left, UpRight,UpLeft, DownLeft, DownRight};
Direction Dir;
Graphics G;
Point Po;
Size Si;
Rectangle Re;
Pen Pen_Draw;
Pen Pen_Clear;
public Form1()
{InitializeComponent();}
private void Form1_Load(object sender, EventArgs e)
{
Dir = Direction.Right;
G = CreateGraphics();
Po = new Point(300, 300);
Si = new Size(10, 10);
Re = new Rectangle(Po, Si);
Pen_Draw = new Pen(Color.Red,10);
Pen_Clear = new Pen(BackColor,10);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (Dir == Direction.Right)
{
G.DrawRectangle(Pen_Clear, Re);
Po.X += 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);
}
if (Dir == Direction.Left)
{
G.DrawRectangle(Pen_Clear, Re);
Po.X -= 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);
}
if (Dir == Direction.Up)
{
G.DrawRectangle(Pen_Clear, Re);
Po.Y -= 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);
}
if (Dir == Direction.Down)
{
G.DrawRectangle(Pen_Clear, Re);
Po.Y += 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);
}
if (Dir == Direction.UpRight)
{
G.DrawRectangle(Pen_Clear, Re);
Po.Y -= 2;
Po.X += 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);
}
if (Dir == Direction.UpLeft)
{
G.DrawRectangle(Pen_Clear, Re);
Po.Y -= 2;
Po.X -= 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);
}
if (Dir == Direction.DownLeft)
{
G.DrawRectangle(Pen_Clear, Re);
Po.Y += 2;
Po.X -= 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);
}
if (Dir == Direction.DownRight)
{
G.DrawRectangle(Pen_Clear, Re);
Po.Y += 2;
Po.X += 2;
Re.Location = Po;
G.DrawRectangle(Pen_Draw, Re);}}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
if (e.Shift)
Dir = Direction.UpRight;
else
Dir = Direction.Right;
}
if (e.KeyCode == Keys.Left)
{
if (e.Shift)
Dir = Direction.DownLeft;
else
Dir = Direction.Left;
}
if (e.KeyCode == Keys.Up)
{
if (e.Shift)
Dir = Direction.UpLeft;
else
Dir = Direction.Up;
}
if (e.KeyCode == Keys.Down)
{
if (e.Shift)
Dir = Direction.DownRight;
else
Dir = Direction.Down;}}}}