Exemple #1
0
        public SnakeModel(Arena arena)
        {
            Body.AddLast(new Point(1, 1));

            this.arena = arena;
            ChangeDirection(Direction.Right);
        }
Exemple #2
0
        public static void Render(Graphics graphics, Arena arena)
        {
            graphics.FillRectangle(Brushes.AliceBlue, 0, 0, arena.Width * 10, arena.Height * 10);
            for (int x = 0; x < arena.Width; x++)
            {
                for (int y = 0; y < arena.Height; y++)
                {
                    if (arena.Cells[x, y] == Food.Apple)
                    {
                        graphics.FillRectangle(Brushes.GreenYellow, x * 10, y * 10, 10, 10);
                    }
                    else if (arena.Cells[x, y] == Food.Orange)
                    {
                        graphics.FillRectangle(Brushes.Orange, x * 10, y * 10, 10, 10);
                    }
                }
            }

            bool up, down, left, right;

            LinkedListNode<Point> lastSegment = null;
            LinkedListNode<Point> currentSegment = arena.Snake.Body.First;
            LinkedListNode<Point> nextSegment;
            while (null != currentSegment)
            {
                up = down = left = right = false;
                nextSegment = currentSegment.Next;

                CompareSegment(currentSegment, lastSegment, ref up, ref down, ref left, ref right);
                CompareSegment(currentSegment, nextSegment, ref up, ref down, ref left, ref right);

                DrawSegment(graphics, currentSegment.Value.X, currentSegment.Value.Y, up, down, left, right);

                lastSegment = currentSegment;
                currentSegment = nextSegment;
            }

        }
Exemple #3
0
 private void CreateArena()
 {
     arena = new Arena(PanelArena.Width / ArenaView.SIZE, PanelArena.Height / ArenaView.SIZE);
 }
Exemple #4
0
 private void CreateArena()
 {
     arena = new Arena(PanelArena.Width / 10, PanelArena.Height / 10);
 }