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 tank
- {
- public partial class Form1 : Form
- {
- int x = 100, y = 100;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.FillRectangle((Brushes.Red), x, y, 100, 100);
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Right)
- {
- x += 10;
- if (x >= 650 - 100)
- {
- x = 650 - 100;
- }
- }
- if (e.KeyData == Keys.Left)
- {
- x -= 10;
- if (x <= 0)
- {
- x = 0;
- }
- }
- if (e.KeyData == Keys.Up)
- {
- y -= 10;
- if (y <= 0)
- {
- y = 0;
- }
- }
- if (e.KeyData == Keys.Down)
- {
- y += 10;
- if (y>= 317 - 115)
- {
- y = 317 - 115;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement