Files
snake/Snake/Worm.cs
2026-02-04 20:29:49 +01:00

36 lines
728 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Snake
{
public class Worm
{
public List<Cell> Body = new List<Cell>();
public Worm(Cell startCell)
{
Body.Add(startCell);
}
public void Move(int x, int y, Map map)
{
Cell swapCell = map.Cells[x, y];
for (int i = 1; i < Body.Count; i++)
{
map.SwapCells(swapCell, Body[i]);
swapCell = Body[i];
}
}
public void Eat(ref Cell cell)
{
cell.Type = CellTypes.Snake;
Body.Insert(1, cell);
}
}
}