Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 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 Tetris_Atanasov
  12. {
  13. public partial class Form1 : Form
  14. {
  15. enum Position
  16. {
  17. left, Right, Up, Down
  18. }
  19.  
  20. private int x;
  21. private int y;
  22. private Position objPosition;
  23.  
  24. public Form1()
  25. {
  26. InitializeComponent();
  27. x = 50;
  28. y = 50;
  29. objPosition = Position.Down;
  30. }
  31.  
  32. private void Form1_Paint(object sender, PaintEventArgs e)
  33. {
  34. e.Graphics.FillRectangle(Brushes.Red, x, y, 100, 100);
  35. }
  36.  
  37. private void timerMoving_Tick(object sender, EventArgs e)
  38. {
  39. if (objPosition == Position.Right)
  40. {
  41. x += 10;
  42. }
  43. else if (objPosition == Position.left)
  44. {
  45. x -= 10;
  46. }
  47. else if (objPosition == Position.Up)
  48. {
  49. y -= 10;
  50. }
  51. else if (objPosition == Position.Down)
  52. {
  53. y += 10;
  54. }
  55. Invalidate();
  56. }
  57.  
  58. private void Form1_KeyDown(object sender, KeyEventArgs e)
  59. {
  60. if (e.KeyCode == Keys.Left)
  61. {
  62. objPosition = Position.left;
  63. }
  64. else if (e.KeyCode == Keys.Right)
  65. {
  66. objPosition = Position.Right;
  67. }
  68. else if (e.KeyCode ==Keys.Up)
  69. {
  70. objPosition = Position.Up;
  71. }
  72. else if (e.KeyCode == Keys.Down)
  73. {
  74. objPosition = Position.Down;
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement