Finished up game

This commit is contained in:
maxwes08
2026-02-03 13:44:30 +01:00
parent df6832419f
commit 46816d3dbf
5 changed files with 105 additions and 24 deletions

View File

@@ -13,6 +13,7 @@ namespace Snake
public Worm(Cell startCell)
{
Body.Add(startCell);
startCell.Color = ColorFromHue((float)(Body.Count * 8));
}
public void Move(int x, int y, Map map)
@@ -29,8 +30,31 @@ namespace Snake
public void Eat(ref Cell cell)
{
cell.Type = CellTypes.Snake;
Body.Add(cell);
cell.Color = ColorFromHue((float)(Body.Count * 8));
Body.Insert(1, cell);
}
public Color ColorFromHue(float hue)
{
hue = hue % 360f;
float c = 1f;
float x = c * (1 - Math.Abs((hue / 60f) % 2 - 1));
float m = 0f;
float r = 0, g = 0, b = 0;
if (hue < 60) { r = c; g = x; }
else if (hue < 120) { r = x; g = c; }
else if (hue < 180) { g = c; b = x; }
else if (hue < 240) { g = x; b = c; }
else if (hue < 300) { r = x; b = c; }
else { r = c; b = x; }
return Color.FromArgb(
(int)((r + m) * 255),
(int)((g + m) * 255),
(int)((b + m) * 255)
);
}
}
}