Advertisement
Nikolcho

tanks

Jun 11th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace tank
  12. {
  13. public partial class Form1 : Form
  14. {
  15. int x = 100, y = 100;
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void Form1_Paint(object sender, PaintEventArgs e)
  22. {
  23. e.Graphics.FillRectangle((Brushes.Red), x, y, 100, 100);
  24. }
  25.  
  26. private void Form1_KeyDown(object sender, KeyEventArgs e)
  27. {
  28. if (e.KeyData == Keys.Right)
  29. {
  30. x += 10;
  31. if (x >= 650 - 100)
  32. {
  33. x = 650 - 100;
  34. }
  35. }
  36. if (e.KeyData == Keys.Left)
  37. {
  38. x -= 10;
  39. if (x <= 0)
  40. {
  41. x = 0;
  42. }
  43. }
  44. if (e.KeyData == Keys.Up)
  45. {
  46. y -= 10;
  47. if (y <= 0)
  48. {
  49. y = 0;
  50. }
  51. }
  52. if (e.KeyData == Keys.Down)
  53. {
  54. y += 10;
  55. if (y>= 317 - 115)
  56. {
  57. y = 317 - 115;
  58. }
  59. }
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement