diff --git a/Snake/Form1.Designer.cs b/Snake/Form1.Designer.cs index 13ce13f..dae433f 100644 --- a/Snake/Form1.Designer.cs +++ b/Snake/Form1.Designer.cs @@ -36,7 +36,9 @@ // // gamearea // - gamearea.Location = new Point(200, 25); + gamearea.Anchor = AnchorStyles.None; + gamearea.Location = new Point(43, 50); + gamearea.Margin = new Padding(2); gamearea.Name = "gamearea"; gamearea.Size = new Size(400, 400); gamearea.TabIndex = 0; @@ -50,10 +52,11 @@ // // Form1 // - AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 688); + ClientSize = new Size(484, 461); Controls.Add(gamearea); + Margin = new Padding(2); Name = "Form1"; Text = "Form1"; Load += Form1_Load; diff --git a/Snake/Game.cs b/Snake/Game.cs index 285b6fd..1e9788e 100644 --- a/Snake/Game.cs +++ b/Snake/Game.cs @@ -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) + ); + } } } diff --git a/Snake/Map.cs b/Snake/Map.cs index 22d1078..d823b8d 100644 --- a/Snake/Map.cs +++ b/Snake/Map.cs @@ -57,17 +57,11 @@ namespace Snake { Cell cell = Cells[x,y]; + brush.Color = cell.Color; + if (cell.Type == CellTypes.None) { - brush.Color = Color.LightGray; - } - else if (cell.Type == CellTypes.Snake) - { - brush.Color = cell.Color; - } - else if (cell.Type == CellTypes.Food) - { - brush.Color = Color.Red; + brush.Color = Color.Black; } int totalHeight = CELL_SIZE * _h; diff --git a/Snake/Worm.cs b/Snake/Worm.cs index dbbffb5..60dc358 100644 --- a/Snake/Worm.cs +++ b/Snake/Worm.cs @@ -13,7 +13,6 @@ 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) @@ -30,31 +29,7 @@ namespace Snake public void Eat(ref Cell cell) { cell.Type = CellTypes.Snake; - 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) - ); - } } }