diff --git a/Snake.slnx b/Snake.slnx
new file mode 100644
index 0000000..b8cefea
--- /dev/null
+++ b/Snake.slnx
@@ -0,0 +1,3 @@
+
+
+
diff --git a/Snake/Cell.cs b/Snake/Cell.cs
new file mode 100644
index 0000000..e28d8d4
--- /dev/null
+++ b/Snake/Cell.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Snake
+{
+ public class Cell
+ {
+ public int X;
+ public int Y;
+ public CellTypes Type;
+
+ public Cell(int x, int y, CellTypes type)
+ {
+ X = x;
+ Y = y;
+ Type = type;
+ }
+ }
+}
diff --git a/Snake/CellTypes.cs b/Snake/CellTypes.cs
new file mode 100644
index 0000000..c8473a3
--- /dev/null
+++ b/Snake/CellTypes.cs
@@ -0,0 +1,9 @@
+namespace Snake
+{
+ public enum CellTypes
+ {
+ None,
+ Food,
+ Snake,
+ }
+}
diff --git a/Snake/Directions.cs b/Snake/Directions.cs
new file mode 100644
index 0000000..37ffe7a
--- /dev/null
+++ b/Snake/Directions.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Snake
+{
+ public enum Directions
+ {
+ Up,
+ Down,
+ Left,
+ Right,
+ }
+}
diff --git a/Snake/Form1.Designer.cs b/Snake/Form1.Designer.cs
new file mode 100644
index 0000000..520c5d9
--- /dev/null
+++ b/Snake/Form1.Designer.cs
@@ -0,0 +1,68 @@
+namespace Snake
+{
+ partial class Form1
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ components = new System.ComponentModel.Container();
+ gamearea = new PictureBox();
+ timer = new System.Windows.Forms.Timer(components);
+ ((System.ComponentModel.ISupportInitialize)gamearea).BeginInit();
+ SuspendLayout();
+ //
+ // gamearea
+ //
+ gamearea.Location = new Point(200, 25);
+ gamearea.Name = "gamearea";
+ gamearea.Size = new Size(400, 400);
+ gamearea.TabIndex = 0;
+ gamearea.TabStop = false;
+ //
+ // timer
+ //
+ timer.Enabled = true;
+ timer.Interval = 500;
+ timer.Tick += timer_Tick;
+ //
+ // Form1
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(gamearea);
+ Name = "Form1";
+ Text = "Form1";
+ Load += Form1_Load;
+ ((System.ComponentModel.ISupportInitialize)gamearea).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+ private System.Windows.Forms.Timer timer;
+ public PictureBox gamearea;
+ }
+}
diff --git a/Snake/Form1.cs b/Snake/Form1.cs
new file mode 100644
index 0000000..f820597
--- /dev/null
+++ b/Snake/Form1.cs
@@ -0,0 +1,24 @@
+namespace Snake
+{
+ public partial class Form1 : Form
+ {
+ private Game _game;
+
+ public Form1()
+ {
+ InitializeComponent();
+ }
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+ _game = new Game(this);
+ _game.Start();
+ }
+
+ private void timer_Tick(object sender, EventArgs e)
+ {
+ _game.Update();
+ Invalidate();
+ }
+ }
+}
diff --git a/Snake/Form1.resx b/Snake/Form1.resx
new file mode 100644
index 0000000..7a549a0
--- /dev/null
+++ b/Snake/Form1.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/Snake/Game.cs b/Snake/Game.cs
new file mode 100644
index 0000000..513dfc0
--- /dev/null
+++ b/Snake/Game.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Snake
+{
+ public class Game
+ {
+ //new Cell(10, 10, CellTypes.Snake)
+ Worm worm;
+ Directions direction = Directions.Down;
+ Map map;
+ Form1 form;
+
+ public Game(Form1 form)
+ {
+ this.form = form;
+ }
+
+ public void Start()
+ {
+ Cell startCell = new Cell(10, 10, CellTypes.Snake);
+ map = new Map(20, 20);
+ map.SetCell(startCell);
+ worm = new Worm(startCell);
+ }
+
+ public void Update()
+ {
+ map.Render(form.gamearea.CreateGraphics());
+ form.Invalidate();
+
+ int x = worm.Body[0].X;
+ int y = worm.Body[0].Y;
+
+ Cell snakeCell = map.Cells[x, y];
+ Cell cellBelow = map.Cells[x, y-1];
+
+ map.SwapCells(snakeCell, cellBelow);
+ }
+ }
+}
diff --git a/Snake/Map.cs b/Snake/Map.cs
new file mode 100644
index 0000000..d214505
--- /dev/null
+++ b/Snake/Map.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography.Xml;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Snake
+{
+ public class Map
+ {
+ public Cell[,] Cells;
+ private int _h;
+ private int _w;
+ private const int CELL_SIZE = 20;
+
+ public Map(int h, int w)
+ {
+ Cells = new Cell[h, w];
+ _h = h;
+ _w = w;
+
+ for (int x = 0; x < _w; x++)
+ {
+ for (int y = 0; y < _h; y++)
+ {
+ Cells[x, y] = new Cell(x, y, CellTypes.None);
+ }
+ }
+ }
+
+ public void SetCell(Cell cell)
+ {
+ Cells[cell.X,cell.Y] = cell;
+ }
+
+ public void SwapCells(Cell cell1, Cell cell2)
+ {
+ int tmpX = cell1.X;
+ int tmpY = cell1.Y;
+
+ cell1.X = cell2.X; cell1.Y = cell2.Y;
+
+ cell2.X = tmpX; cell2.Y = tmpY;
+
+ Cells[cell1.X, cell1.Y] = cell1;
+ Cells[cell2.X, cell2.Y] = cell2;
+ }
+
+ public void Render(Graphics graphics)
+ {
+ SolidBrush brush = new SolidBrush(Color.RebeccaPurple);
+
+ for (int x = 0; x < _w; x++)
+ {
+ for (int y = 0; y < _h; y++)
+ {
+ Cell cell = Cells[x,y];
+
+ if (cell.Type == CellTypes.None)
+ {
+ brush.Color = Color.LightGray;
+ }
+ else if (cell.Type == CellTypes.Snake)
+ {
+ brush.Color = Color.Green;
+ }
+ else if (cell.Type == CellTypes.Food)
+ {
+ brush.Color = Color.Red;
+ }
+
+ int totalHeight = CELL_SIZE * _h;
+
+ graphics.FillRectangle(brush,
+ x * 20,
+ totalHeight - y * 20,
+ CELL_SIZE,
+ CELL_SIZE
+ );
+ }
+ }
+ }
+ }
+}
diff --git a/Snake/Program.cs b/Snake/Program.cs
new file mode 100644
index 0000000..d4071d2
--- /dev/null
+++ b/Snake/Program.cs
@@ -0,0 +1,12 @@
+namespace Snake
+{
+ internal static class Program
+ {
+ [STAThread]
+ static void Main()
+ {
+ ApplicationConfiguration.Initialize();
+ Application.Run(new Form1());
+ }
+ }
+}
\ No newline at end of file
diff --git a/Snake/Snake.csproj b/Snake/Snake.csproj
new file mode 100644
index 0000000..663fdb8
--- /dev/null
+++ b/Snake/Snake.csproj
@@ -0,0 +1,11 @@
+
+
+
+ WinExe
+ net8.0-windows
+ enable
+ true
+ enable
+
+
+
\ No newline at end of file
diff --git a/Snake/Worm.cs b/Snake/Worm.cs
new file mode 100644
index 0000000..e8ce675
--- /dev/null
+++ b/Snake/Worm.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Snake
+{
+ public class Worm
+ {
+ public List Body = new List| ();
+
+ public Worm(Cell startCell)
+ {
+ Body.Add(startCell);
+ }
+
+ }
+}
| |