fixed window
This commit is contained in:
@@ -15,6 +15,7 @@ namespace Snake
|
||||
Form1 form;
|
||||
|
||||
int mapSize = 20;
|
||||
float colorMultiplier = 8f;
|
||||
|
||||
public Game(Form1 form)
|
||||
{
|
||||
@@ -27,6 +28,7 @@ namespace Snake
|
||||
map = new Map(mapSize, mapSize);
|
||||
map.SetCell(startCell);
|
||||
worm = new Worm(startCell);
|
||||
startCell.Color = ColorFromHue(0f);
|
||||
SpawnApple();
|
||||
}
|
||||
|
||||
@@ -94,6 +96,7 @@ namespace Snake
|
||||
if (cell.Type == CellTypes.None)
|
||||
{
|
||||
cell.Type = CellTypes.Food;
|
||||
cell.Color = ColorFromHue(worm.Body.Count*colorMultiplier);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -137,5 +140,28 @@ namespace Snake
|
||||
{
|
||||
form.timer.Enabled = false;
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user