Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Tetris_Atanasov
- {
- public partial class Form1 : Form
- {
- enum Position
- {
- left, Right, Up, Down
- }
- private int x;
- private int y;
- private Position objPosition;
- public Form1()
- {
- InitializeComponent();
- x = 50;
- y = 50;
- objPosition = Position.Down;
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.FillRectangle(Brushes.Red, x, y, 100, 100);
- }
- private void timerMoving_Tick(object sender, EventArgs e)
- {
- if (objPosition == Position.Right)
- {
- x += 10;
- }
- else if (objPosition == Position.left)
- {
- x -= 10;
- }
- else if (objPosition == Position.Up)
- {
- y -= 10;
- }
- else if (objPosition == Position.Down)
- {
- y += 10;
- }
- Invalidate();
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Left)
- {
- objPosition = Position.left;
- }
- else if (e.KeyCode == Keys.Right)
- {
- objPosition = Position.Right;
- }
- else if (e.KeyCode ==Keys.Up)
- {
- objPosition = Position.Up;
- }
- else if (e.KeyCode == Keys.Down)
- {
- objPosition = Position.Down;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement