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 SnakeWinForms1b
- {
- public enum Direction { Left, Right, Up, Down }
- public partial class Form1 : Form
- {
- private int positionX;
- private int positionY;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- timer1.Interval = 100;
- timer1.Tick += UpdateScreen;
- timer1.Start();
- }
- private void UpdateScreen(object sender, EventArgs e)
- {
- pbGame.Invalidate();
- }
- private void pbGame_Paint(object sender, PaintEventArgs e)
- {
- Graphics canvas = e.Graphics;
- canvas.FillEllipse(Brushes.Red, new Rectangle(positionX, positionY, 20, 20));
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- switch (e.KeyCode) {
- case Keys.Right :
- positionX++;
- break;
- case Keys.Left :
- positionX--;
- break;
- case Keys.Up :
- positionY--;
- break;
- case Keys.Down :
- positionY++;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement