Files
snake/Snake/Worm.cs
maxwes08 df6832419f eating
2026-01-30 12:14:01 +01:00

37 lines
723 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.Add(cell);
}
}
}