Witam,
mam kawałek kodu snake.. muszę rozdzielić go dodatkowo na klasę Plansza i Snake.. kto mi powie które części kodu w jakiej klasy muszą być, aby działało? męczę się.. i nie wiem w sumie co źle robię.. która część w której klasie powinna być, bo mi nie działa...
pomoże ktoś????
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
enum Sterowanie { L, P, G, D };
Sterowanie S;
const Int32 rozmiar=20;
const Int32 szerokosc=200;
const Int32 wysokosc=300;
List<Point> snake = new List<Point>();
Graphics g;
Pen pioro;
public Form1()
{
InitializeComponent();
snake.Add(new Point(5,5));
snake.Add(new Point(5, 6));
snake.Add(new Point(5, 7));
snake.Add(new Point(5, 8));
Plansza.Image = new Bitmap(szerokosc * rozmiar, wysokosc * rozmiar);
g = Graphics.FromImage(Plansza.Image);
pioro = new Pen(Color.Blue,2);
// tajmer.Start();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode== Keys.Left)
{
S=Sterowanie.L;
}
else if (e.KeyCode==Keys.Right)
{
S=Sterowanie.P;
}
else if (e.KeyCode == Keys.Up)
{
S = Sterowanie.G;
}
else if (e.KeyCode == Keys.Down)
{
S = Sterowanie.D;
}
}
private void rysuj()
{
g.Clear(Color.Red);
foreach (Point p in snake)
{
g.DrawRectangle(pioro, p.X * rozmiar, p.Y * rozmiar, rozmiar, rozmiar);
}
Plansza.Refresh();
}
private void tajmer_Tick(object sender, EventArgs e)
{
if (S == Sterowanie.G)
{
snake.Add(new Point(snake.Last().X, snake.Last().Y - 1));
snake.Remove(snake.First());
}
else if (S == Sterowanie.D)
{
snake.Add(new Point(snake.Last().X, snake.Last().Y + 1));
snake.Remove(snake.First());
}
else if (S == Sterowanie.L)
{
snake.Add(new Point(snake.Last().X -1, snake.Last().Y ));
snake.Remove(snake.First());
}
else if (S == Sterowanie.P)
{
snake.Add(new Point(snake.Last().X +1, snake.Last().Y ));
snake.Remove(snake.First());
}
rysuj();
}
}
}